micron writer

This commit is contained in:
NN Solex 2023-05-14 17:13:00 +03:00
parent d37b0a67a4
commit 306423cd99
6 changed files with 47 additions and 2 deletions

View file

@ -0,0 +1,5 @@
{% extends "base.mu" %}
{% block content %}
-
{{ article.content }}
{% endblock %}

View file

@ -0,0 +1,10 @@
>{% block title %}{{ SITENAME }}{% endblock title %}
{% block content %}
{% endblock %}
{% if DESCRIPTION %}
-
{{ DESCRIPTION }}
-
{% endif %}

View file

@ -43,6 +43,8 @@ AUTHOR_SAVE_AS = ''
AUTHORS_SAVE_AS = ''
TAGS_SAVE_AS = ''
MICRON_PATH = 'micron'
PATH = 'content'
ARTICLE_PATHS = ['tags',]
PAGE_PATHS = ['pages',]
@ -57,4 +59,4 @@ CATEGORY_SAVE_AS = 'projects/{slug}/index.html'
DELETE_OUTPUT_DIRECTORY = True
PLUGINS = ['geohash', 'geodata']
PLUGINS = ['geohash', 'geodata', 'micron']

View file

@ -0,0 +1 @@
from .micron import *

View 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)