diff --git a/src/build.py b/src/build.py index 1ea357a..c2f1e22 100644 --- a/src/build.py +++ b/src/build.py @@ -298,49 +298,54 @@ def build_compiled_page(articles, config): """ Builds a page compiling all articles in the Lexicon. """ - # Sort by turn and title - turn_order = sorted( + articles = sorted( articles, - key=lambda a: (a.turn, utils.titlesort(a.title))) + key=lambda a: (utils.titlesort(a.title))) - # Build the content of each article - css = utils.load_resource("lexicon.css") - css += "\n"\ - "body { background: #ffffff; }\n"\ - "sup { vertical-align: top; font-size: 0.6em; }\n" - content = "\n"\ - "\n"\ - "{lexicon}\n"\ - "\n"\ - "\n"\ - "

{lexicon}

".format( - lexicon=config["LEXICON_TITLE"], - css=css) - for article in turn_order: - # Stitch in superscripts for citations + # Write the header + content = "{}"\ + ""\ + "\n".format(config["LEXICON_TITLE"]) + + # Write each article + for article in articles: + # Article title + content += "

{0.title}

".format(article) + + # Article content format_map = { - format_id: "{}{}".format(cite_tuple[0], format_id[1:]) - for format_id, cite_tuple in article.citations.items() + "c"+str(c.id) : c.format("{text}{id}") + for c in article.citations } - 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"\ - "{}\n".format(article.title, article_body, cite_block) - content += article_block + article_content = article.content.format(**format_map) + article_content = article_content.replace("

", "

", 1) + content += article_content + + # Article citations + cite_list = "
".join( + c.format("{id}. {target}") + for c in article.citations) + cite_block = "

{}

".format(cite_list) + content += cite_block + + # Addendums + for addendum in article.addendums: + # Addendum content + format_map = { + "c"+str(c.id) : c.format("{text}{id}") + for c in addendum.citations + } + article_content = addendum.content.format(**format_map) + content += article_content + + # Addendum citations + cite_list = "
".join( + c.format("{id}. {target}") + for c in addendum.citations) + cite_block = "

{}

".format(cite_list) + content += cite_block content += "" return content