From a2409a50c65a140319bfc99531dcc4d2354e4514 Mon Sep 17 00:00:00 2001
From: Yuval Adam <_@yuv.al>
Date: Thu, 9 May 2024 13:52:23 +0200
Subject: Migrate build script to use ymlstash
---
cli/build.py | 47 +++++++++++++++--------------------------------
1 file changed, 15 insertions(+), 32 deletions(-)
(limited to 'cli/build.py')
diff --git a/cli/build.py b/cli/build.py
index 38b6724..526e086 100644
--- a/cli/build.py
+++ b/cli/build.py
@@ -1,12 +1,10 @@
-import yaml
-
from jinja2 import Environment, PackageLoader, select_autoescape
from os import listdir, mkdir
from pathlib import Path
from shutil import copyfile
from unidecode import unidecode
-from .base import cli
+from .base import cli, STASH
ROOT_PATH = Path(__file__).parents[1]
@@ -14,9 +12,6 @@ NAMES_DIR = ROOT_PATH / "names"
BUILD_DIR = ROOT_PATH / "build"
STATIC_DIR = ROOT_PATH / "static"
-REQUIRED_FIELDS = set(["domain", "name"])
-OPTIONAL_FIELDS = set(["url", "title", "email", "github", "candidate", "invalid"])
-
TEMPLATES = ["index.html"]
@@ -32,38 +27,26 @@ def build():
names = []
candidates = []
- for name in listdir(NAMES_DIR):
- with open(NAMES_DIR / name, "r") as f:
- fields = yaml.load(f.read(), Loader=yaml.Loader)
- field_set = set(fields.keys())
-
- missing_fields = REQUIRED_FIELDS - field_set
- if missing_fields:
- raise Exception(f"Missing required fields {missing_fields} in {name}")
-
- invalid_fields = field_set - OPTIONAL_FIELDS - REQUIRED_FIELDS
- if invalid_fields:
- raise Exception(f"Invalid fields {invalid_fields} in {name}")
-
- if fields.get("invalid"):
- continue
-
- if fields.get("candidate"):
- candidates.append(fields)
- else:
- names.append(fields)
+ for key in STASH.list_keys():
+ name = STASH.load(key)
+ if name.invalid is True:
+ continue
+ if name.candidate is True:
+ candidates.append(name)
+ else:
+ names.append(name)
- names = list(sorted(names, key=lambda x: x["domain"]))
- candidates = list(sorted(candidates, key=lambda x: x["domain"]))
+ names = list(sorted(names, key=lambda x: x.domain))
+ candidates = list(sorted(candidates, key=lambda x: x.domain))
def render_link(value, classes):
- name = unidecode(value["name"]).lower().split(" ")
- domain = unidecode(value["domain"]).replace(".", "")
+ name = unidecode(value.name).lower().split(" ")
+ domain = unidecode(value.domain).replace(".", "")
res = []
for part in name:
if part == domain:
- url = value.get("url") or "https://" + value.get("domain")
- res.append(f'{value["domain"]}')
+ url = value.url or "https://" + value.domain
+ res.append(f'{value.domain}')
else:
res.append(part)
return " ".join(res)
--
cgit v1.3.1