From 1f897ecbb0704800531025795c2a1420741bb81b Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sat, 7 Jul 2018 13:31:17 -0700 Subject: [PATCH] Refactor citeblock code to take full article object --- src/article.py | 18 ++++++++++-------- src/build.py | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/article.py b/src/article.py index 8132f6e..0af2b06 100644 --- a/src/article.py +++ b/src/article.py @@ -162,18 +162,20 @@ class LexiconArticle: } return self.content.format(**format_map) - def build_default_citeblock(self, prev_target, next_target): + def build_default_citeblock(self, prev_article, next_article): """ Builds the citeblock content HTML for use in regular article pages. For each defined target, links the target page as Previous or Next. """ citeblock = "
\n" # Prev/next links - if next_target is not None: - citeblock += "

Next →

\n".format(utils.titleescape(next_target)) - if prev_target is not None: - citeblock += "

← Previous

\n".format(utils.titleescape(prev_target)) - elif next_target is not None: + if next_article is not None: + citeblock += "

Next →

\n".format( + next_article.title_filesafe) + if prev_article is not None: + citeblock += "

← Previous

\n".format( + prev_article.title_filesafe) + if next_article is None and prev_article is None: citeblock += "

 

\n" # Citations cites_links = [ @@ -182,7 +184,7 @@ class LexiconArticle: "" if title in self.wcites else " class=\"phantom\"") for title in sorted(self.wcites | self.pcites)] cites_str = " | ".join(cites_links) - if len(cites_str) < 1: cites_str = "--" + if len(cites_str) < 1: cites_str = "—" citeblock += "

Citations: {}

\n".format(cites_str) # Citedby citedby_links = [ @@ -190,6 +192,6 @@ class LexiconArticle: title, utils.titleescape(title)) for title in self.citedby] citedby_str = " | ".join(citedby_links) - if len(citedby_str) < 1: citedby_str = "--" + if len(citedby_str) < 1: citedby_str = "—" citeblock += "

Cited by: {}

\n
\n".format(citedby_str) return citeblock diff --git a/src/build.py b/src/build.py index 8e37e38..314a470 100644 --- a/src/build.py +++ b/src/build.py @@ -288,8 +288,8 @@ def build_all(path_prefix, lexicon_name): with open(pathto("article", article.title_filesafe + ".html"), "w", encoding="utf8") as f: content = article.build_default_content() citeblock = article.build_default_citeblock( - None if idx == 0 else articles[idx - 1].title, - None if idx == l-1 else articles[idx + 1].title) + None if idx == 0 else articles[idx - 1], + None if idx == l-1 else articles[idx + 1]) article_html = entry_skeleton.format( title = article.title, lexicon = config["LEXICON_TITLE"],