Skip to content
Permalink
Browse files

metadata support for template output

  • Loading branch information...
shawnmjones committed May 13, 2019
1 parent 4e0e104 commit 92226e7e49fb80de14820a03aa0141134b44a5fd
@@ -92,12 +92,18 @@ def generate_story(self, story_data, mementoembed_api, story_template):
pprint.pformat(elements)
))

if 'metadata' in story_data:
metadata = story_data['metadata']
else:
metadata = None

env = Environment()
template = env.from_string(story_template)
rendered_story = template.render(
title=story_data['title'],
generated_by=story_data['generated_by'],
collection_url=story_data['collection_url'],
metadata=metadata,
elements=elements
)

@@ -8,6 +8,16 @@
<p><strong>Collection URL:</strong> <a href="{{ collection_url }}">{{ collection_url }}</a></p>
{% endif %}

{% if metadata is defined %}

{% for key, value in metadata.items() %}

<p><strong>{{ key|title }}</strong>: {{ value }}</p>

{% endfor %}

{% endif %}

{% for element in elements %}
<hr>

@@ -206,7 +216,7 @@

{% else %}

{{ element.text }}
<p>{{ element.text }}</p>

{% endif %}

@@ -13,6 +13,16 @@ title: {{ title }}
<p><strong>Collection URL:</strong> <a href="{{ collection_url }}">{{ collection_url }}</a></p>
{% endif %}

{% if metadata is defined %}

{% for key, value in metadata.items() %}

<p><strong>{{ key|title }}</strong>: {{ value }}</p>

{% endfor %}

{% endif %}

{% for element in elements %}
<hr>

@@ -14,6 +14,16 @@ title: {{ title }}
**Collection URL:** [{{ collection_url }}]({{ collection_url }})
{% endif %}

{% if metadata is defined %}

{% for key, value in metadata.items() %}

**{{ key|title }}**: {{ value }}

{% endfor %}

{% endif %}

{% for element in elements %}

---
@@ -9,6 +9,16 @@
**Collection URL:** [{{ collection_url }}]({{ collection_url }})
{% endif %}

{% if metadata is defined %}

{% for key, value in metadata.items() %}

**{{ key|title }}**: {{ value }}

{% endfor %}

{% endif %}

{% for element in elements %}

---
@@ -1,18 +1,14 @@

'''{{ title }}'''
= {{ title }} =
{% if generated_by is defined %}'''Story By:''' {{ generated_by }}{% endif %}

{% if generated_by is defined %}
'''Story By:''' {{ generated_by }}
{% endif %}
{% if collection_url is defined %}'''Collection URL:''' [{{ collection_url }} {{ collection_url }}]{% endif %}

{% if collection_url is defined %}
'''Collection URL:''' [{{ collection_url }} {{ collection_url }}]
{% endif %}
{% if metadata is defined %}{% for key, value in metadata.items() %}'''{{ key|title }}''': {{ value }}

{% endfor %}{% endif %}
{% for element in elements %}

----

{% if element.type == 'link' %}

'''[{{ element.surrogate.urim }} {{ element.surrogate.title }}]'''
@@ -28,11 +24,9 @@ Member of the Collection [{{ element.surrogate.archive_collection_uri }} {{ elem
[{{ element.surrogate.urim }} {{ element.surrogate.original_domain }} @ {{ element.surrogate.memento_datetime }}]

[http://timetravel.mementoweb.org/list/{{ element.surrogate.memento_datetime_14num }}Z/{{ element.surrogate.original_uri }} Other Versions] || [{{ element.surrogate.original_uri }} Current Version]

{% else %}

{{ element.text }}

{% endif %}

{% endfor %}
@@ -2,6 +2,11 @@
"title": "My Story Title",
"collection_url": "https://archive.example.com/mycollection",
"generated_by": "Generated By",
"metadata": {
"myKey1": "value1",
"my-Key2": "value2",
"my key 3": "value 3"
},
"elements": [
{
"type": "text",

0 comments on commit 92226e7

Please sign in to comment.
You can’t perform that action at this time.