diff options
Diffstat (limited to 'megapixels/app/site/parser.py')
| -rw-r--r-- | megapixels/app/site/parser.py | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/megapixels/app/site/parser.py b/megapixels/app/site/parser.py index ad4256ad..87539ade 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 = [] @@ -125,8 +133,9 @@ def intro_section(metadata, s3_path): parts = [] if 'desc' in metadata: desc = metadata['desc'] + # colorize the first instance of the database name in the header if 'color' in metadata and metadata['title'] in desc: - desc = desc.replace(metadata['title'], "<span style='color: {}'>{}</span>".format(metadata['color'], metadata['title'])) + desc = desc.replace(metadata['title'], "<span style='color: {}'>{}</span>".format(metadata['color'], metadata['title']), 1) section += "<div class='hero_desc'><span>{}</span></div>".format(desc, desc) if 'subdesc' in metadata: @@ -137,7 +146,7 @@ def intro_section(metadata, s3_path): section += "</section>" if 'caption' in metadata: - section += "<section><div class='image'><div class='caption'>{}</div></div></section>".format(metadata['caption']) + section += "<section><div class='image'><div class='intro-caption caption'>{}</div></div></section>".format(metadata['caption']) return section @@ -223,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 = cfg.DIR_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 |
