Add hidden_tags config option

This commit is contained in:
Tim Van Baak 2021-02-21 22:31:37 -08:00
parent be9f4fefc2
commit c49d21f693
2 changed files with 12 additions and 4 deletions

View File

@ -14,10 +14,11 @@ from redstring.parser import (
) )
def generate_index_document(directory: str) -> Document: def generate_index_document(config) -> Document:
""" """
Generate a document describing a document collection. Generate a document describing a document collection.
""" """
directory = config['root']
categories: dict = {} categories: dict = {}
# categories = { # categories = {
@ -35,11 +36,17 @@ def generate_index_document(directory: str) -> Document:
with open(os.path.join(directory, filename)) as f: with open(os.path.join(directory, filename)) as f:
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.
if category_tag := document.get_tag('category'): if category_tag := document.get_tag('category'):
category_name = category_tag.value category_name = category_tag.value
else: else:
category_name = 'index' category_name = 'index'
# Skip hidden tabs in guest mode.
if (not config['edit']) and (category_name in config.get('hidden_tabs', [])):
continue
# Create it if necessary.
if category_name not in categories: if category_name not in categories:
categories[category_name] = {} categories[category_name] = {}
destination_category = categories[category_name] destination_category = categories[category_name]
@ -72,7 +79,7 @@ def generate_index_document(directory: str) -> Document:
destination_topic.append((doc_id, doc_title)) destination_topic.append((doc_id, doc_title))
# Build an index document # Build an index document.
def document_link(info): def document_link(info):
doc_id, doc_title = info doc_id, doc_title = info
return ( return (

View File

@ -60,7 +60,7 @@ def root():
@app.route('/index/', methods=['GET']) @app.route('/index/', methods=['GET'])
def index(): def index():
document = generate_index_document(current_app.config['root']) document = generate_index_document(current_app.config)
return render_template('doc.jinja', document=document, index=True) return render_template('doc.jinja', document=document, index=True)
@ -179,6 +179,7 @@ def read_config(app, path):
config = json.load(f) config = json.load(f)
app.config['root'] = config['root'] app.config['root'] = config['root']
app.config['edit'] = config['edit'] app.config['edit'] = config['edit']
app.config['hidden_tabs'] = config.get('hidden_tabs', [])
return config return config