Fix category and topic building

This commit is contained in:
Tim Van Baak 2021-02-12 10:13:34 -08:00
parent 276a77b67e
commit 606537d959
1 changed files with 6 additions and 4 deletions

View File

@ -17,16 +17,18 @@ def generate_index_document(directory: str) -> Document:
document: Document = load(f) document: Document = load(f)
# Check if this document specifies a tab, and create it if necessary. # Check if this document specifies a tab, and create it if necessary.
category = document.get_tag('category') if category_tag := document.get_tag('category'):
if not category: category = category_tag.value
else:
category = 'index' category = 'index'
if category not in categories: if category not in categories:
categories[category] = {} categories[category] = {}
category_tab = categories[category] category_tab = categories[category]
# Check if this document specifies a topic, and create it if necessary. # Check if this document specifies a topic, and create it if necessary.
topic = document.get_tag('topic') if topic_tag := document.get_tag('topic'):
if not topic: topic = topic_tag.value
else:
topic = 'uncategorized' topic = 'uncategorized'
if '.' in topic: if '.' in topic:
topic, subtopic = topic.split('.', maxsplit=1) topic, subtopic = topic.split('.', maxsplit=1)