|
|
@@ -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:])
|