Add citations to compiled page

This commit is contained in:
Tim Van Baak 2018-07-07 16:17:55 -07:00
parent 2c59fbefc8
commit 4762365a07
1 changed files with 16 additions and 3 deletions

View File

@ -251,7 +251,8 @@ def build_compiled_page(articles, config):
# Build the content of each article # Build the content of each article
css = utils.load_resource("lexicon.css") css = utils.load_resource("lexicon.css")
css += "\n"\ css += "\n"\
"body { background: #ffffff; }\n" "body { background: #ffffff; }\n"\
"sup { vertical-align: top; font-size: 0.6em; }\n"
content = "<html>\n"\ content = "<html>\n"\
"<head>\n"\ "<head>\n"\
"<title>{lexicon}</title>\n"\ "<title>{lexicon}</title>\n"\
@ -263,17 +264,29 @@ def build_compiled_page(articles, config):
lexicon=config["LEXICON_TITLE"], lexicon=config["LEXICON_TITLE"],
css=css) css=css)
for article in turn_order: for article in turn_order:
# Stitch in superscripts for citations
format_map = { format_map = {
format_id: cite_tuple[0] # TODO format_id: "{}<sup>{}</sup>".format(cite_tuple[0], format_id[1:])
for format_id, cite_tuple in article.citations.items() for format_id, cite_tuple in article.citations.items()
} }
article_body = article.content.format(**format_map) article_body = article.content.format(**format_map)
# Stitch a page-break-avoid div around the header and first paragraph # Stitch a page-break-avoid div around the header and first paragraph
article_body = article_body.replace("</p>", "</p></div>", 1) article_body = article_body.replace("</p>", "</p></div>", 1)
# Append the citation block
cite_list = "<br>\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 ""\
"<p><i>Citations:</i><br>\n"\
"{}\n</p>".format(cite_list)
article_block = "<div style=\"page-break-inside:avoid;\">\n"\ article_block = "<div style=\"page-break-inside:avoid;\">\n"\
"<h2>{}</h2>\n"\ "<h2>{}</h2>\n"\
"{}\n".format(article.title, article_body) "{}\n"\
"{}\n".format(article.title, article_body, cite_block)
content += article_block content += article_block
content += "</body></html>" content += "</body></html>"
return content return content