| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/usr/bin/env python3
- import chevron
- import datetime
- import os
- import markdown
- import shutil
- import sys
- import tempfile
- import yaml
- 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)
- project_data['header'] = markdown.markdown(project_data['header'])
- for p in project_data['projects']:
- p['text'] = markdown.markdown(p['text'])
- for s in p.get('stuff', ()):
- s['text'] = markdown.markdown(s['text'])
- with open(find_asset('main.css', assets)) as f:
- css = f.read()
- with open(find_asset('main.js', assets)) as f:
- javascript = f.read()
- with open(find_asset('main.mustache', assets)) as f:
- template = f.read()
- year = datetime.datetime.now().year
- index_html = chevron.render(
- template=template,
- data={
- 'css': css,
- 'javascript': javascript,
- 'project_data': project_data,
- 'copyright': f'© {year} Getty Ritter'
- },
- )
- if not output_file or output_file == '-':
- print(index_html)
- return
- with tempfile.TemporaryDirectory() as tmpdir:
- with open(os.path.join(tmpdir, 'index.html'), 'w') as f:
- print(index_html, file=f)
- shutil.copyfile(
- 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__':
- main(*sys.argv[1:])
|