From 4762365a07daca4b91dbafacb7f943d4dda3dae1 Mon Sep 17 00:00:00 2001
From: Tim Van Baak
Date: Sat, 7 Jul 2018 16:17:55 -0700
Subject: [PATCH] Add citations to compiled page
---
src/build.py | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/build.py b/src/build.py
index c5ec9b3..131016b 100644
--- a/src/build.py
+++ b/src/build.py
@@ -251,7 +251,8 @@ def build_compiled_page(articles, config):
# Build the content of each article
css = utils.load_resource("lexicon.css")
css += "\n"\
- "body { background: #ffffff; }\n"
+ "body { background: #ffffff; }\n"\
+ "sup { vertical-align: top; font-size: 0.6em; }\n"
content = "\n"\
"\n"\
"{lexicon}\n"\
@@ -263,17 +264,29 @@ def build_compiled_page(articles, config):
lexicon=config["LEXICON_TITLE"],
css=css)
for article in turn_order:
+ # Stitch in superscripts for citations
format_map = {
- format_id: cite_tuple[0] # TODO
+ format_id: "{}{}".format(cite_tuple[0], format_id[1:])
for format_id, cite_tuple in article.citations.items()
}
article_body = article.content.format(**format_map)
# Stitch a page-break-avoid div around the header and first paragraph
article_body = article_body.replace("
", "", 1)
+ # Append the citation block
+ cite_list = "
\n".join(
+ "{}. {}\n".format(format_id[1:], cite_tuple[1])
+ for format_id, cite_tuple in sorted(
+ article.citations.items(),
+ key=lambda t:int(t[0][1:])))
+ cite_block = "" if article.player is None else ""\
+ "Citations:
\n"\
+ "{}\n
".format(cite_list)
article_block = "\n"\
"
{}
\n"\
- "{}\n".format(article.title, article_body)
+ "{}\n"\
+ "{}\n".format(article.title, article_body, cite_block)
content += article_block
+
content += ""
return content