diff options
author | emkael <emkael@tlen.pl> | 2017-07-04 15:53:19 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-07-04 15:55:39 +0200 |
commit | bf0b6154fe7b5a7853b15ab5d401e3f6524f1ec5 (patch) | |
tree | 631d5dbc2eef57b8f07c895c126db14bbdbce0e7 /static-menu.py | |
parent | 904770f12304f5e7233a68e4a1eab0f9e0fbc2f7 (diff) |
Compiling static links into top menu of the pages
Diffstat (limited to 'static-menu.py')
-rw-r--r-- | static-menu.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/static-menu.py b/static-menu.py new file mode 100644 index 0000000..9474d12 --- /dev/null +++ b/static-menu.py @@ -0,0 +1,24 @@ +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 = 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('<a class="btn btn-default"></a>', 'html.parser') + link.a['href'] = href + link.a['title'] = menu_item['header'] + link.a.string = menu_item['label'] + menu_container.append(link.a) + +file(content_file, 'w').write(content.prettify().encode('utf-8')) |