diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-02 14:38:27 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-02 14:38:27 +0200 |
| commit | b8f5c87e823d0b68d5e30f8de453ba90dcadc241 (patch) | |
| tree | e5e16680ab69a64dd41fd7c7e30acaae8fd62747 /megapixels | |
| parent | af41073892c9391d679b8872f498767ef87150d4 (diff) | |
sidebar from spreadsheet
Diffstat (limited to 'megapixels')
| -rw-r--r-- | megapixels/app/site/loader.py | 38 | ||||
| -rw-r--r-- | megapixels/app/site/parser.py | 11 |
2 files changed, 39 insertions, 10 deletions
diff --git a/megapixels/app/site/loader.py b/megapixels/app/site/loader.py index 779f68ba..701c78b2 100644 --- a/megapixels/app/site/loader.py +++ b/megapixels/app/site/loader.py @@ -5,6 +5,9 @@ import glob import app.settings.app_cfg as cfg from app.utils.file_utils import load_json +import app.utils.sheet_utils as sheet + +sidebar = sheet.fetch_google_lookup("sidebar", item_key="key") def read_metadata(fn): """ @@ -20,6 +23,12 @@ def read_metadata(fn): sections = data.split("\n\n") return parse_metadata(fn, sections) +def domainFromUrl(url): + domain = url.split('/')[2].split('.') + if len(domain) > 2 and len(domain[-2]) == 2: + return ".".join(domain[-3:]) + return ".".join(domain[-2:]) + default_metadata = { 'status': 'published', @@ -33,6 +42,18 @@ default_metadata = { 'tagline': '', } +sidebar_order = [ + { 'key': 'published', 'title': 'Published' }, + { 'key': 'images', 'title': 'Images' }, + { 'key': 'videos', 'title': 'Videos' }, + { 'key': 'identities', 'title': 'Identities' }, + { 'key': 'purpose', 'title': 'Purpose' }, + { 'key': 'created_by', 'title': 'Created by' }, + { 'key': 'funded_by_short', 'title': 'Funded by' }, + { 'key': 'size_gb', 'title': 'Download Size' }, + { 'key': 'website', 'title': 'Website' }, +] + def parse_metadata(fn, sections): """ parse the metadata headers in a markdown file @@ -87,8 +108,25 @@ def parse_metadata(fn, sections): print("Bad metadata? {}".format(dataset_path)) elif 'datasets' in fn: print("/!\\ {} does not exist!".format(dataset_path)) + + if metadata['slug'] in sidebar: + sidebar_row = sidebar[metadata['slug']] + if sidebar_row: + metadata['sidebar'] = [] + for item in sidebar_order: + key = item['key'] + value = sidebar_row[key] + if value: + value = value.replace(' - ', ' – ') + if key == 'size_gb': + value += ' GB' + if key == 'website': + value = "<a href='" + value + "' target='_blank' rel='nofollow noopener'>" + domainFromUrl(value) + "</a>" + metadata['sidebar'].append({ 'value': value, 'title': item['title'], }) + if 'meta' not in metadata or not metadata['meta']: # dude metadata['meta'] = {} + metadata['sidebar'] = [] return metadata, valid_sections diff --git a/megapixels/app/site/parser.py b/megapixels/app/site/parser.py index 06c45f41..dc2a09f2 100644 --- a/megapixels/app/site/parser.py +++ b/megapixels/app/site/parser.py @@ -55,7 +55,7 @@ def parse_markdown(metadata, sections, s3_path, skip_h1=False): elif '### statistics' in section.lower() or '### sidebar' in section.lower(): if len(current_group): groups.append(format_section(current_group, s3_path)) - current_group = [] + current_group = [format_include("{% include 'sidebar.html' %}", metadata)] if 'sidebar' not in section.lower(): current_group.append(section) in_stats = True @@ -267,15 +267,6 @@ def format_include(section, metadata): include_fn = section.strip().strip('\n').strip().strip('{%').strip().strip('%}').strip() include_fn = include_fn.strip('include').strip().strip('"').strip().strip("'").strip() return includes_env.get_template(include_fn).render(metadata=metadata) - # include_dir = cfg.DIR_SITE_INCLUDES - # try: - # includes_env.get_template(fp_html) - # 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): """ |
