diff --git a/src/build.py b/src/build.py
index 314a470..6b5ff43 100644
--- a/src/build.py
+++ b/src/build.py
@@ -13,7 +13,7 @@ def build_contents_page(articles, config):
Builds the full HTML of the contents page.
"""
content = ""
- # Article counts
+ # Head the contents page with counts of written and phantom articles
phantom_count = len([article for article in articles if article.player is None])
if phantom_count == 0:
content = "
There are {0} entries in this lexicon.
\n".format(len(articles))
@@ -23,48 +23,44 @@ def build_contents_page(articles, config):
# Prepare article links
link_by_title = {article.title : "{0}".format(
article.title, article.title_filesafe,
- "" if article.player is not None else " class=\"phantom\"")
+ " class=\"phantom\"" if article.player is None else "")
for article in articles}
# Write the articles in alphabetical order
content += utils.load_resource("contents.html")
content += "\n
\n"
indices = config["INDEX_LIST"].split("\n")
- alphabetical_order = sorted(articles, key=lambda a: utils.titlecase(a.title))
+ alphabetical_order = sorted(
+ articles,
+ key=lambda a: utils.titlesort(a.title))
check_off = list(alphabetical_order)
for index_str in indices:
content += "{0}
\n".format(index_str)
for article in alphabetical_order:
- if (utils.titlestrip(article.title)[0].upper() in index_str):
+ if (utils.titlesort(article.title)[0].upper() in index_str):
check_off.remove(article)
- content += "- "
- content += link_by_title[article.title]
- content += "
\n"
+ content += "- {}
\n".format(link_by_title[article.title])
if len(check_off) > 0:
content += "&c.
\n"
for article in check_off:
- content += "- "
- content += link_by_title[article.title]
- content += "
\n"
+ content += "- {}
\n".format(link_by_title[article.title])
content += "
\n
\n"
# Write the articles in turn order
content += "\n
\n"
latest_turn = max([article.turn for article in articles if article.player is not None])
- turn_order = sorted(articles, key=lambda a: (a.turn, utils.titlecase(a.title)))
+ turn_order = sorted(
+ articles,
+ key=lambda a: (a.turn, utils.titlesort(a.title)))
check_off = list(turn_order)
for turn_num in range(1, latest_turn + 1):
content += "Turn {0}
\n".format(turn_num)
for article in turn_order:
if article.turn == turn_num:
check_off.remove(article)
- content += "- "
- content += link_by_title[article.title]
- content += "
\n"
+ content += "- {}
\n".format(link_by_title[article.title])
if len(check_off) > 0:
content += "Unwritten
\n"
for article in check_off:
- content += "- "
- content += link_by_title[article.title]
- content += "
\n"
+ content += "- {}
\n".format(link_by_title[article.title])
content += "
\n
\n"
# Fill in the page skeleton
entry_skeleton = utils.load_resource("entry-page.html")
@@ -264,9 +260,10 @@ def build_all(path_prefix, lexicon_name):
# so we can derive the written titles from this list
#written_titles = [article.title for article in articles]
# Once they've been populated, the articles list has the titles of all articles
+ # Sort this by turn before title so prev/next links run in turn order
articles = sorted(
LexiconArticle.populate(articles),
- key=lambda a: utils.titlestrip(a.title))
+ key=lambda a: (a.turn, utils.titlesort(a.title)))
#phantom_titles = [article.title for article in articles if article.title not in written_titles]
def pathto(*els):
return os.path.join(lex_path, *els)
diff --git a/src/utils.py b/src/utils.py
index d97111d..af15187 100644
--- a/src/utils.py
+++ b/src/utils.py
@@ -23,13 +23,14 @@ def titleescape(s):
s = hex(abs(hash(s)))[2:] # Replace it with a hex hash
return s
-def titlestrip(s):
+def titlesort(s):
"""
- Strips articles for title sorting.
+ Reduces titles down for sorting.
"""
- if s.startswith("The "): return s[4:]
- if s.startswith("An "): return s[3:]
- if s.startswith("A "): return s[2:]
+ s = s.lower()
+ if s.startswith("the "): return s[4:]
+ if s.startswith("an "): return s[3:]
+ if s.startswith("a "): return s[2:]
return s
# Load functions