1
Fork 0

inject config into templates

This commit is contained in:
Jake Howard 2017-01-13 22:14:13 +00:00
parent 1375206853
commit 1cc4621368

View file

@ -1,20 +1,20 @@
import os import os
from pelican import signals from pelican import signals, contents
from pelican import contents
from jinja2 import Environment, ChoiceLoader, FileSystemLoader from jinja2 import Environment, ChoiceLoader, FileSystemLoader
from config import social
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
def execjinja2(instance): def execjinja2(instance):
if type(instance) in (contents.Article, contents.Page): if type(instance) in (contents.Article, contents.Page):
base_path = os.path.dirname(os.path.abspath(__file__))
jinja2_env = Environment( # nosec jinja2_env = Environment( # nosec
loader=ChoiceLoader([ loader=ChoiceLoader([
FileSystemLoader( FileSystemLoader(
os.path.join(base_path, instance.settings['THEME'], 'templates') os.path.join(BASE_DIR, instance.settings['THEME'], 'templates')
), ),
FileSystemLoader( FileSystemLoader(
os.path.join(base_path, instance.settings['PATH']) os.path.join(BASE_DIR, instance.settings['PATH'])
) )
]), ]),
**instance.settings['JINJA_ENVIRONMENT'], **instance.settings['JINJA_ENVIRONMENT'],
@ -29,7 +29,8 @@ def execjinja2(instance):
kwargs['article'] = instance kwargs['article'] = instance
elif type(instance) is contents.Page: elif type(instance) is contents.Page:
kwargs['page'] = instance kwargs['page'] = instance
kwargs['instance'] = instance # avoid using outside common elements
kwargs['social'] = social
instance._content = jinja2_template.render(**kwargs) instance._content = jinja2_template.render(**kwargs)