You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

render.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. import os
  3. import subprocess
  4. import sys
  5. import shutil
  6. import pathlib
  7. output = sys.argv[1]
  8. print('exporting to \'' + output + '\'')
  9. # Make sure the directory doesn't already exist.
  10. if not os.path.exists(output):
  11. os.mkdir(output)
  12. else:
  13. print('directory already exists!')
  14. sys.exit(1)
  15. # Copy the static files
  16. for dp, dns, fns in os.walk('static'):
  17. for fn in fns:
  18. if fn.endswith('~'):
  19. continue
  20. shutil.copy2(os.path.join(dp, fn), os.path.join(output, fn))
  21. # Convert and export the markdown files.
  22. def export_markdown(f):
  23. outfile = os.path.splitext(os.path.join(output, f))[0] + '.html'
  24. try:
  25. os.makedirs(os.path.dirname(outfile))
  26. except:
  27. pass
  28. cmd = 'pandoc --from markdown+yaml_metadata_block --to html --standalone --template=pandoc.template --include-in-header=mdheader.htm -o ' + outfile + ' markdown/' + f
  29. subprocess.run(cmd.split(), shell=False)
  30. for dp, dns, fns in os.walk('markdown'):
  31. for fn in fns:
  32. if fn.endswith('~'):
  33. continue
  34. export_markdown(os.path.relpath(os.path.join(dp, fn), 'markdown'))