summaryrefslogtreecommitdiff
path: root/cli/build.py
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2024-05-09 13:52:23 +0200
committerYuval Adam <_@yuv.al>2024-05-10 12:55:22 +0200
commita2409a50c65a140319bfc99531dcc4d2354e4514 (patch)
treec1b613b1bd4ffcd81fb1f6ab8a64e8d8253d3d19 /cli/build.py
parent2b18b6abbdc20e94292e4eb4e86b52856a1461b5 (diff)
Migrate build script to use ymlstash
Diffstat (limited to 'cli/build.py')
-rw-r--r--cli/build.py47
1 files changed, 15 insertions, 32 deletions
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'<a href="{url}" class="{classes}">{value["domain"]}</a>')
+ url = value.url or "https://" + value.domain
+ res.append(f'<a href="{url}" class="{classes}">{value.domain}</a>')
else:
res.append(part)
return " ".join(res)