From 489eb40c0a29116ccce98291b3e174cb4531587b Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 6 Jul 2017 00:12:28 +0200 Subject: Ability to compile multiple panels into single static page --- static.py | 33 +++++++++++++++++++++++++++------ templates/static.html | 6 +++--- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/static.py b/static.py index 3168843..16d82ae 100644 --- a/static.py +++ b/static.py @@ -1,13 +1,34 @@ -import os, sys +import copy, os, sys from bs4 import BeautifulSoup as bs4 -content_file = sys.argv[1] -page_header = sys.argv[2] if len(sys.argv) > 2 else '' +content_files = [] +page_header = '' + +arguments = sys.argv[1:] + +while True: + page_header = arguments[0] + arguments = arguments[1:] + if os.path.exists(page_header): + content_files.append(page_header) + page_header = '' + if len(arguments) == 0: + break template = bs4(file('templates/static.html'), 'lxml') + +content_wrapper = template.find('div', {'id': 'wrapper'}).extract() +del content_wrapper['id'] + template.select('h2 small')[0].string = page_header -template.find('div', {'id': 'content'}).append( - bs4(file(content_file).read(), 'lxml') -) + +footer = template.find('div', {'id': 'footer'}) + +for content_file in content_files: + content = copy.copy(content_wrapper) + content.div.append( + bs4(file(content_file).read(), 'html.parser') + ) + footer.insert_before(content) print template.prettify().encode('utf-8') diff --git a/templates/static.html b/templates/static.html index 736c354..b115e0f 100644 --- a/templates/static.html +++ b/templates/static.html @@ -19,11 +19,11 @@ -
-
+
+
-
+ -- cgit v1.2.3