選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

render.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. import os
  3. import subprocess
  4. import sys
  5. import shutil
  6. import pathlib
  7. import json
  8. output = sys.argv[1]
  9. print('exporting to \'' + output + '\'')
  10. # Make sure the directory doesn't already exist.
  11. if not os.path.exists(output):
  12. os.mkdir(output)
  13. else:
  14. print('directory already exists!')
  15. sys.exit(1)
  16. # Copy the static files
  17. for dp, dns, fns in os.walk('static'):
  18. for fn in fns:
  19. if fn.endswith('~'):
  20. continue
  21. shutil.copy2(os.path.join(dp, fn), os.path.join(output, fn))
  22. TITLE_PREFIX = 'title: '
  23. # Convert and export the markdown files.
  24. def export_markdown(path):
  25. title = None
  26. with open('markdown/' + path, 'r') as f:
  27. for l in f.readlines():
  28. # Shittily parse out the thing.
  29. if l.startswith(TITLE_PREFIX):
  30. tstr = l[len(TITLE_PREFIX):]
  31. if tstr.startswith('\''):
  32. tstr = tstr[1:]
  33. if tstr.endswith('\''):
  34. tstr = tstr[:-1]
  35. title = tstr.strip()
  36. title = str(title)
  37. outfile = os.path.splitext(os.path.join(output, path))[0] + '.page'
  38. try:
  39. os.makedirs(os.path.dirname(outfile))
  40. except:
  41. pass
  42. cmd = 'pandoc --from markdown+yaml_metadata_block --to html --standalone --template=squarespace.template --include-in-header=mdheader.htm -o ' + outfile + ' markdown/' + path
  43. subprocess.run(cmd.split(), shell=False)
  44. # Generate info file
  45. with open(outfile + '.conf', 'w') as f:
  46. conf = {
  47. 'title': '%s :: ProvDSA PoliEd' % title,
  48. 'description': '%s - ProvDSA PoliEd Foundational Series' % title
  49. }
  50. json.dump(conf, f, indent=' ')
  51. for dp, dns, fns in os.walk('markdown'):
  52. for fn in fns:
  53. if fn.endswith('~'):
  54. continue
  55. export_markdown(os.path.relpath(os.path.join(dp, fn), 'markdown'))