1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #!/usr/bin/env python3
-
- import os
- import subprocess
- import sys
- import shutil
- import pathlib
- import json
-
- output = sys.argv[1]
-
- print('exporting to \'' + output + '\'')
-
- # Make sure the directory doesn't already exist.
- if not os.path.exists(output):
- os.mkdir(output)
- else:
- print('directory already exists!')
- sys.exit(1)
-
- # Copy the static files
- for dp, dns, fns in os.walk('static'):
- for fn in fns:
- if fn.endswith('~'):
- continue
- shutil.copy2(os.path.join(dp, fn), os.path.join(output, fn))
-
- TITLE_PREFIX = 'title: '
-
- # Convert and export the markdown files.
- def export_markdown(path):
- title = None
-
- with open('markdown/' + path, 'r') as f:
- for l in f.readlines():
- # Shittily parse out the thing.
- if l.startswith(TITLE_PREFIX):
- tstr = l[len(TITLE_PREFIX):]
- if tstr.startswith('\''):
- tstr = tstr[1:]
- if tstr.endswith('\''):
- tstr = tstr[:-1]
- title = tstr.strip()
-
- title = str(title)
-
- outfile = os.path.splitext(os.path.join(output, path))[0] + '.page'
- try:
- os.makedirs(os.path.dirname(outfile))
- except:
- pass
- cmd = 'pandoc --from markdown+yaml_metadata_block --to html --standalone --template=squarespace.template --include-in-header=mdheader.htm -o ' + outfile + ' markdown/' + path
- subprocess.run(cmd.split(), shell=False)
-
- # Generate info file
- with open(outfile + '.conf', 'w') as f:
- conf = {
- 'title': '%s :: ProvDSA PoliEd' % title,
- 'description': '%s - ProvDSA PoliEd Foundational Series' % title
- }
-
- json.dump(conf, f, indent=' ')
-
- for dp, dns, fns in os.walk('markdown'):
- for fn in fns:
- if fn.endswith('~'):
- continue
- export_markdown(os.path.relpath(os.path.join(dp, fn), 'markdown'))
|