summaryrefslogtreecommitdiff
path: root/generator
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2018-01-01 04:46:37 -0800
committeriximeow <me@iximeow.net>2018-01-01 04:46:37 -0800
commit1a864e96c115cefa6aa4965210ebf44d60cf0690 (patch)
treef52daf4e7e1faf8cc5812ebcfedd6357d9cc0f70 /generator
parent22cdc1d261925125948000ea8382161121daf561 (diff)
adjust #eval to execute a shell command rather than execute one program
also set up pandoc to include a bit of style information, currently located at headers.html TODO plans include configurable headers for a page, but not right now
Diffstat (limited to 'generator')
-rw-r--r--generator/generate.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/generator/generate.py b/generator/generate.py
index d94d085..60ac8f6 100644
--- a/generator/generate.py
+++ b/generator/generate.py
@@ -21,7 +21,11 @@ def replace_references(lines, file_dir):
elif line.startswith("#eval "):
# include results of system'ing that line
try:
- evald_text = subprocess.check_output(line[6:], shell=True).decode('utf-8')
+ command = line[6:].strip()
+ eval_p = subprocess.Popen(['bash', '-c', command], stdout=subprocess.PIPE, stdin=subprocess.PIPE, cwd=file_dir)
+ evald_text = eval_p.communicate()[0].decode('utf-8')
+ if evald_text is None or len(evald_text.strip()) == 0:
+ raise Exception("Evaluating `{}` produced no output".format(command))
result = result + '<pre>' + evald_text + '</pre>\n'
except Exception as e:
print("Error processing line {}:\n {}\nError: {}".format(i, line, e))
@@ -47,6 +51,8 @@ if __name__ == "__main__":
page_cwd = page_path[:(md_source.rfind('/') + 1)]
page_path = page_path[(md_source.rfind('/') + 1):]
+ headers_file = './headers.html'
+
compiled_dest = './generated/{}{}'.format(page_cwd, page_path)
print("Source: {}\nPage path: {}\nDest file: {}".format(md_source, page_path, compiled_dest))
try:
@@ -59,9 +65,8 @@ if __name__ == "__main__":
if markdown_blob == None:
print("Error compiling {}".format(md_source))
sys.exit(3)
- print(markdown_blob)
# now shove it all through pandoc
- pandoc_proc = subprocess.Popen(['pandoc'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+ pandoc_proc = subprocess.Popen(['pandoc', '-H', headers_file], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
html = pandoc_proc.communicate(markdown_blob.encode('utf-8'))[0]
try:
if not os.path.isdir('./generated/' + page_cwd):