langmenu plugin
This commit is contained in:
parent
1384610f07
commit
102fde3931
2 changed files with 44 additions and 0 deletions
|
@ -48,3 +48,5 @@ THEME = 'themes/bs3'
|
||||||
BOOTSTRAP_THEME = 'cyborg'
|
BOOTSTRAP_THEME = 'cyborg'
|
||||||
|
|
||||||
HIDE_SIDEBAR = True
|
HIDE_SIDEBAR = True
|
||||||
|
PLUGIN_PATHS = ['plugins']
|
||||||
|
PLUGINS = ['langmenu']
|
||||||
|
|
42
plugins/langmenu.py
Normal file
42
plugins/langmenu.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
'''
|
||||||
|
This plugin attemps to create something similar to menuitems,
|
||||||
|
but more meaningful with respect to l10n
|
||||||
|
'''
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from pelican import signals
|
||||||
|
|
||||||
|
|
||||||
|
def add_localmenuitems(generator):
|
||||||
|
menu = {} # lang: list of pages
|
||||||
|
for page in generator.context['pages']:
|
||||||
|
menu.setdefault(page.lang, [])
|
||||||
|
for tr in page.translations:
|
||||||
|
menu.setdefault(tr.lang, [])
|
||||||
|
print('we have langs ' + ','.join(menu.keys()))
|
||||||
|
for page in sorted(generator.context['pages'],
|
||||||
|
key=lambda x: x.navbar_sort):
|
||||||
|
defined_langs = []
|
||||||
|
menu[page.lang].append(page)
|
||||||
|
defined_langs.append(page.lang)
|
||||||
|
for tr in page.translations:
|
||||||
|
menu[tr.lang].append(tr)
|
||||||
|
defined_langs.append(tr.lang)
|
||||||
|
for lang in menu.keys():
|
||||||
|
if lang not in defined_langs:
|
||||||
|
menu[lang].append(page)
|
||||||
|
|
||||||
|
menuitems = {}
|
||||||
|
for lang in menu:
|
||||||
|
menuitems[lang] = []
|
||||||
|
for page in menu[lang]:
|
||||||
|
menuitems[lang].append((page.title, page.url))
|
||||||
|
|
||||||
|
print(menuitems['en'])
|
||||||
|
print(menuitems['it'])
|
||||||
|
generator.context['LOCALMENUITEMS'] = menuitems
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
signals.page_generator_finalized.connect(add_localmenuitems)
|
||||||
|
pass
|
Loading…
Reference in a new issue