From c49d21f6938322da2cd89b9f39bb285161d35272 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sun, 21 Feb 2021 22:31:37 -0800 Subject: [PATCH] Add hidden_tags config option --- redstring/library.py | 13 ++++++++++--- redstring/server.py | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/redstring/library.py b/redstring/library.py index a3eecbb..6cc23b6 100644 --- a/redstring/library.py +++ b/redstring/library.py @@ -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. """ + directory = config['root'] categories: dict = {} # categories = { @@ -35,11 +36,17 @@ def generate_index_document(directory: str) -> Document: with open(os.path.join(directory, filename)) as 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'): category_name = category_tag.value else: 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: 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)) - # Build an index document + # Build an index document. def document_link(info): doc_id, doc_title = info return ( diff --git a/redstring/server.py b/redstring/server.py index f6dad93..bd7e4f8 100644 --- a/redstring/server.py +++ b/redstring/server.py @@ -60,7 +60,7 @@ def root(): @app.route('/index/', methods=['GET']) 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) @@ -179,6 +179,7 @@ def read_config(app, path): config = json.load(f) app.config['root'] = config['root'] app.config['edit'] = config['edit'] + app.config['hidden_tabs'] = config.get('hidden_tabs', []) return config