summaryrefslogtreecommitdiff
path: root/megapixels/app/site
diff options
context:
space:
mode:
Diffstat (limited to 'megapixels/app/site')
-rw-r--r--megapixels/app/site/parser.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/megapixels/app/site/parser.py b/megapixels/app/site/parser.py
index f7d0128e..6c5aa8af 100644
--- a/megapixels/app/site/parser.py
+++ b/megapixels/app/site/parser.py
@@ -1,4 +1,5 @@
import os
+from os.path import join
import re
import glob
import simplejson as json
@@ -53,10 +54,17 @@ def parse_markdown(metadata, sections, s3_path, skip_h1=False):
elif in_stats and not section.strip().startswith('## ') and 'end sidebar' not in section.lower():
current_group.append(section)
elif in_stats and section.strip().startswith('## ') or 'end sidebar' in section.lower():
- current_group = [format_section(current_group, s3_path, 'right-sidebar', tag='div')]
+ current_group = [format_section(current_group, s3_path, 'left-sidebar', tag='div')]
if 'end sidebar' not in section.lower():
current_group.append(section)
in_stats = False
+ elif section.strip().startswith('{% include'):
+ groups.append(format_section(current_group, s3_path))
+ current_group = []
+ current_group.append(section)
+ if section.strip().endswith(' %}'):
+ groups.append(format_include("\n\n".join(current_group)))
+ current_group = []
elif section.strip().startswith('```'):
groups.append(format_section(current_group, s3_path))
current_group = []
@@ -224,6 +232,21 @@ def format_footnotes(footnotes, s3_path):
footnote_txt = '<section><ul class="footnotes"><li>' + '</li><li>'.join(footnote_list) + '</li></ul></section>'
return footnote_txt, footnote_index_lookup
+def format_include(section):
+ """
+ Include html template
+ """
+ include_dir = '/work/megapixels_dev/site/includes/'
+ fp_html = section.strip().strip('\n').strip().strip('{%').strip().strip('%}').strip()
+ fp_html = fp_html.strip('include').strip().strip('"').strip().strip("'").strip()
+ try:
+ with open(join(include_dir, fp_html), 'r') as fp:
+ html = fp.read().replace('\n', '')
+ return html
+ except Exception as e:
+ print(f'Error parsing include: {e}')
+ return ''
+
def format_applet(section, s3_path):
"""
Format the applets, which load javascript modules like the map and CSVs