put jinja2 parser for content into repo
This commit is contained in:
parent
39aa802b0e
commit
b64eb0b460
3 changed files with 42 additions and 4 deletions
3
Makefile
3
Makefile
|
@ -34,9 +34,6 @@ install: env node_modules pelican_plugins
|
||||||
pelican_plugins: env
|
pelican_plugins: env
|
||||||
rm -rf $(PLUGINS_DIR) || "No existing extensions"
|
rm -rf $(PLUGINS_DIR) || "No existing extensions"
|
||||||
git clone --recursive https://github.com/getpelican/pelican-plugins $(PLUGINS_DIR) || "Git Fail"
|
git clone --recursive https://github.com/getpelican/pelican-plugins $(PLUGINS_DIR) || "Git Fail"
|
||||||
@echo ">> Hotfixing..."
|
|
||||||
rm -rf $(PLUGINS_DIR)/pelican-jinja2content
|
|
||||||
git clone https://github.com/RealOrangeOne/pelican-jinja2content -b patch-1 --depth=1 $(PLUGINS_DIR)/pelican-jinja2content
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
pyvenv env
|
pyvenv env
|
||||||
|
|
|
@ -62,7 +62,7 @@ PLUGIN_PATHS = ["pelican_plugins", "plugins"]
|
||||||
PLUGINS = [
|
PLUGINS = [
|
||||||
"sitemap",
|
"sitemap",
|
||||||
"filetime_from_git",
|
"filetime_from_git",
|
||||||
"pelican-jinja2content",
|
"jinja2content",
|
||||||
"metatags",
|
"metatags",
|
||||||
"autopages",
|
"autopages",
|
||||||
"screenfetch"
|
"screenfetch"
|
||||||
|
|
41
plugins/jinja2content.py
Normal file
41
plugins/jinja2content.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from pelican import signals
|
||||||
|
from pelican import contents
|
||||||
|
|
||||||
|
from jinja2 import Environment, ChoiceLoader, FileSystemLoader
|
||||||
|
|
||||||
|
|
||||||
|
def execjinja2(instance):
|
||||||
|
if type(instance) in (contents.Article, contents.Page):
|
||||||
|
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
jinja2_env = Environment(
|
||||||
|
trim_blocks=True,
|
||||||
|
lstrip_blocks=True,
|
||||||
|
loader=ChoiceLoader([
|
||||||
|
FileSystemLoader(
|
||||||
|
os.path.join(base_path, instance.settings['THEME'], 'templates')
|
||||||
|
),
|
||||||
|
FileSystemLoader(
|
||||||
|
os.path.join(base_path, instance.settings['PATH'])
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
extensions=instance.settings['JINJA_EXTENSIONS'],
|
||||||
|
)
|
||||||
|
|
||||||
|
if 'JINJA_FILTERS' in instance.settings:
|
||||||
|
jinja2_env.filters.update(instance.settings['JINJA_FILTERS'])
|
||||||
|
|
||||||
|
jinja2_template = jinja2_env.from_string(instance._content)
|
||||||
|
|
||||||
|
kwargs = instance._context
|
||||||
|
if type(instance) is contents.Article:
|
||||||
|
kwargs['article'] = instance
|
||||||
|
elif type(instance) is contents.Page:
|
||||||
|
kwargs['page'] = instance
|
||||||
|
|
||||||
|
instance._content = jinja2_template.render(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
signals.content_object_init.connect(execjinja2)
|
Reference in a new issue