From ac91fdbcb319b7aca5c2b8cc406997e331efbec8 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 7 Sep 2017 14:23:19 +0200 Subject: Pre-generated menus for static pages (and group tool pages) --- Makefile | 5 ++++- bin/generate-statics.sh | 1 + scripts/static-menu.py | 16 +++------------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 99f0d04..edf9cb0 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ players: bin/build-players.sh http statics: + python scripts/generate-static-menu.py config/static.json http http > http/.menu.html bin/generate-statics.sh config/static.json static http menus: @@ -31,7 +32,8 @@ menus: group-tools: python scripts/static.py static/group-intro.html static/group-form-loading.html static/group-form.html > http/ranking-grupowy.html - python scripts/static-menu.py config/static.json http/ranking-grupowy.html http + python scripts/generate-static-menu.py config/static.json http http > http/.menu.html + python scripts/static-menu.py http/ranking-grupowy.html http/.menu.html minimize: $(tmpfiles) @@ -40,6 +42,7 @@ $(tmpfiles): mv $@ $(patsubst %.tmp,%,$@) deploy: + find http -type f -name .menu.html -delete bin/deploy.sh clean: diff --git a/bin/generate-statics.sh b/bin/generate-statics.sh index bb49671..4369aa7 100755 --- a/bin/generate-statics.sh +++ b/bin/generate-statics.sh @@ -11,5 +11,6 @@ cat $1 | if [ -n "$CONTENT_FILE" ] then python scripts/static.py $CONTENT_DIR/$CONTENT_FILE "$HEADER" > $OUTPUT_DIR/$OUTPUT_FILE + python scripts/static-menu.py $OUTPUT_DIR/$OUTPUT_FILE $OUTPUT_DIR/.menu.html fi done diff --git a/scripts/static-menu.py b/scripts/static-menu.py index 9474d12..e30c702 100644 --- a/scripts/static-menu.py +++ b/scripts/static-menu.py @@ -2,23 +2,13 @@ import copy, json, os, sys from bs4 import BeautifulSoup as bs4 -config_file = sys.argv[1] -content_file = sys.argv[2] -link_prefix = sys.argv[3] if len(sys.argv) > 3 else '' +content_file = sys.argv[1] +menu_content = file(sys.argv[2]) content = bs4(file(content_file), 'lxml') for menu_container in content.select('.static-menu'): menu_container.clear() - for menu_item in json.load(file(config_file)): - href = os.path.relpath( - os.path.join(link_prefix, menu_item['url']), - os.path.dirname(content_file) - ) - link = bs4('', 'html.parser') - link.a['href'] = href - link.a['title'] = menu_item['header'] - link.a.string = menu_item['label'] - menu_container.append(link.a) + menu_container.append(bs4(menu_content, 'html.parser')) file(content_file, 'w').write(content.prettify().encode('utf-8')) -- cgit v1.2.3