micron writer
This commit is contained in:
parent
d37b0a67a4
commit
306423cd99
6 changed files with 47 additions and 2 deletions
1
web/plugins/micron/__init__.py
Normal file
1
web/plugins/micron/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .micron import *
|
||||
25
web/plugins/micron/micron.py
Normal file
25
web/plugins/micron/micron.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from pelican import signals, generators
|
||||
from itertools import chain
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
import os
|
||||
from pprint import pprint
|
||||
|
||||
def generate_micron(generator):
|
||||
template_path = os.path.join(generator.settings.get('THEME'), 'templates')
|
||||
out_path = generator.settings.get('MICRON_PATH', 'micron/')
|
||||
environment = Environment(loader=FileSystemLoader(template_path))
|
||||
if not os.path.exists(out_path):
|
||||
os.mkdir(out_path)
|
||||
for obj in generator.articles:
|
||||
filename = obj.slug + ".mu"
|
||||
template = environment.get_template( obj.template + '.mu')
|
||||
context = dict()
|
||||
context.update({ 'article' : obj })
|
||||
context.update(obj.settings)
|
||||
content = template.render(context)
|
||||
output_micron = os.path.join(out_path, filename)
|
||||
with open(output_micron, 'w') as mf:
|
||||
mf.write(content)
|
||||
|
||||
def register():
|
||||
signals.article_generator_finalized.connect(generate_micron)
|
||||
Loading…
Add table
Add a link
Reference in a new issue