Getty Ritter 3 лет назад
Родитель
Сommit
56ce33fcc5
3 измененных файлов с 31 добавлено и 13 удалено
  1. 11 1
      BUILD.bazel
  2. 12 11
      generate.py
  3. 8 1
      projects.yaml

+ 11 - 1
BUILD.bazel

@@ -11,6 +11,16 @@ py_binary(
     ]
 )
 
+filegroup(
+    name="static",
+    srcs=glob(["static/*"]),
+)
+
+filegroup(
+    name="templates",
+    srcs=glob(["templates/*"]),
+)
+
 genrule(
     name = "out",
     srcs = [
@@ -20,5 +30,5 @@ genrule(
     ],
     tools = [":generate"],
     outs = ["output"],
-    cmd = "$(location :generate) $(location :projects.yaml) $(location :static) $(location :templates) $(location output)",
+    cmd = "$(location :generate) $(location output) $(location :projects.yaml) $(locations :static) $(locations :templates)",
 )

+ 12 - 11
generate.py

@@ -9,7 +9,14 @@ import sys
 import tempfile
 import yaml
 
-def main(projects_yaml, static_dir, template_dir, output_file=None):
+def find_asset(name, assets):
+    for a in assets:
+        if os.path.basename(a) == name:
+            return a
+    raise Exception(f"Unable to find {name} in assets")
+
+def main(output_file, projects_yaml, *assets):
+
     with open(projects_yaml) as f:
         project_data = yaml.safe_load(f)
 
@@ -19,12 +26,12 @@ def main(projects_yaml, static_dir, template_dir, output_file=None):
         for s in p.get('stuff', ()):
             s['text'] = markdown.markdown(s['text'])
 
-    with open(os.path.join(static_dir, 'main.css')) as f:
+    with open(find_asset('main.css', assets)) as f:
         css = f.read()
-    with open(os.path.join(static_dir, 'main.js')) as f:
+    with open(find_asset('main.js', assets)) as f:
         javascript = f.read()
 
-    with open(os.path.join(template_dir, 'main.mustache')) as f:
+    with open(find_asset('main.mustache', assets)) as f:
         template = f.read()
 
     year = datetime.datetime.now().year
@@ -47,17 +54,11 @@ def main(projects_yaml, static_dir, template_dir, output_file=None):
         with open(os.path.join(tmpdir, 'index.html'), 'w') as f:
             print(index_html, file=f)
         shutil.copyfile(
-            os.path.join(static_dir, 'raleway.ttf'),
+            find_asset('raleway.ttf', assets),
             os.path.join(tmpdir, 'raleway.ttf'),
         )
         shutil.make_archive('output', 'zip', tmpdir)
         shutil.move('output.zip', output_file)
 
 if __name__ == '__main__':
-    if len(sys.argv) not in (4, 5):
-        print(
-            f"{sys.argv[0]}: [project.yaml] [static/] [templates/] [output-zip]",
-            file=sys.stderr,
-        )
-        sys.exit(1)
     main(*sys.argv[1:])

+ 8 - 1
projects.yaml

@@ -50,6 +50,12 @@ projects:
       related, and others that are about designing physical objects
       for my own use. As of right now, much of my physical design work
       is done with the help of a laser-cutter.
+    stuff:
+      - name: cocktail.graphics
+        text: >
+          [cocktail.graphics](https://cocktail.graphics/) is an
+          information design project aimed at doing visual graph-style
+          recipes for cocktails.
   - name: writing
     text: >
       I write a lot of non-fiction blog posts, and I also write some
@@ -63,4 +69,5 @@ projects:
       forward.
     stuff:
       - name: Logomancy
-        text: blah
+        text: >
+          A tiny party game inspired by [The Adventure Zone]().