summaryrefslogtreecommitdiff
path: root/megapixels
diff options
context:
space:
mode:
Diffstat (limited to 'megapixels')
-rw-r--r--megapixels/app/settings/app_cfg.py1
-rw-r--r--megapixels/app/site/parser.py30
2 files changed, 28 insertions, 3 deletions
diff --git a/megapixels/app/settings/app_cfg.py b/megapixels/app/settings/app_cfg.py
index 40625958..d213f584 100644
--- a/megapixels/app/settings/app_cfg.py
+++ b/megapixels/app/settings/app_cfg.py
@@ -165,6 +165,7 @@ S3_DATASETS_PATH = "v1" # datasets is already in the filename
DIR_SITE_PUBLIC = "../site/public"
DIR_SITE_CONTENT = "../site/content/pages"
DIR_SITE_TEMPLATES = "../site/templates"
+DIR_SITE_INCLUDES = "../site/includes"
DIR_SITE_USER_CONTENT = "../site/public/user_content"
# -----------------------------------------------------------------------------
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