forked from github/pelican
added a static pages generator
Conflicts: pelican/__init__.py pelican/generators.py pelican/settings.py
This commit is contained in:
parent
c0ed9e1cff
commit
7127676f71
3 changed files with 36 additions and 4 deletions
|
|
@ -9,7 +9,8 @@ from pelican import signals
|
||||||
|
|
||||||
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
from pelican.generators import (ArticlesGenerator, PagesGenerator,
|
||||||
StaticGenerator, PdfGenerator,
|
StaticGenerator, PdfGenerator,
|
||||||
LessCSSGenerator, SourceFileGenerator)
|
LessCSSGenerator, SourceFileGenerator,
|
||||||
|
StaticPageGenerator)
|
||||||
from pelican.log import init
|
from pelican.log import init
|
||||||
from pelican.settings import read_settings
|
from pelican.settings import read_settings
|
||||||
from pelican.utils import (clean_output_dir, files_changed, file_changed,
|
from pelican.utils import (clean_output_dir, files_changed, file_changed,
|
||||||
|
|
@ -170,7 +171,8 @@ class Pelican(object):
|
||||||
signals.finalized.send(self)
|
signals.finalized.send(self)
|
||||||
|
|
||||||
def get_generator_classes(self):
|
def get_generator_classes(self):
|
||||||
generators = [StaticGenerator, ArticlesGenerator, PagesGenerator]
|
generators = [StaticGenerator, ArticlesGenerator, PagesGenerator,
|
||||||
|
StaticPageGenerator]
|
||||||
if self.settings['PDF_GENERATOR']:
|
if self.settings['PDF_GENERATOR']:
|
||||||
generators.append(PdfGenerator)
|
generators.append(PdfGenerator)
|
||||||
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
if self.settings['LESS_GENERATOR']: # can be True or PATH to lessc
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import random
|
||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from os.path import exists, getmtime
|
||||||
|
|
||||||
from codecs import open
|
from codecs import open
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
@ -12,8 +13,8 @@ from functools import partial
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from operator import attrgetter, itemgetter
|
from operator import attrgetter, itemgetter
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader
|
from jinja2 import (Environment, FileSystemLoader, PrefixLoader, ChoiceLoader,
|
||||||
from jinja2.exceptions import TemplateNotFound
|
BaseLoader, TemplateNotFound)
|
||||||
|
|
||||||
from pelican.contents import Article, Page, Category, is_valid_content
|
from pelican.contents import Article, Page, Category, is_valid_content
|
||||||
from pelican.readers import read_file
|
from pelican.readers import read_file
|
||||||
|
|
@ -110,6 +111,34 @@ class Generator(object):
|
||||||
self.context[item] = value
|
self.context[item] = value
|
||||||
|
|
||||||
|
|
||||||
|
class _FileLoader(BaseLoader):
|
||||||
|
|
||||||
|
def __init__(self, path):
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
def get_source(self, environment, template):
|
||||||
|
path = template
|
||||||
|
if not exists(path):
|
||||||
|
raise TemplateNotFound(template)
|
||||||
|
mtime = getmtime(path)
|
||||||
|
with file(path) as f:
|
||||||
|
source = f.read().decode('utf-8')
|
||||||
|
return source, path, lambda: mtime == getmtime(path)
|
||||||
|
|
||||||
|
|
||||||
|
class StaticPageGenerator(Generator):
|
||||||
|
|
||||||
|
def generate_output(self, writer):
|
||||||
|
for urlpath, source in self.settings['STATIC_PAGES'].items():
|
||||||
|
self.env.loader.loaders.insert(0, _FileLoader(source))
|
||||||
|
try:
|
||||||
|
template = self.env.get_template(source)
|
||||||
|
rurls = self.settings.get('RELATIVE_URLS')
|
||||||
|
writer.write_file(urlpath.strip('/'), template, self.context, rurls)
|
||||||
|
finally:
|
||||||
|
del self.env.loader.loaders[0]
|
||||||
|
|
||||||
|
|
||||||
class ArticlesGenerator(Generator):
|
class ArticlesGenerator(Generator):
|
||||||
"""Generate blog articles"""
|
"""Generate blog articles"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ _DEFAULT_CONFIG = {'PATH': '.',
|
||||||
'WEBASSETS': False,
|
'WEBASSETS': False,
|
||||||
'PLUGINS': [],
|
'PLUGINS': [],
|
||||||
'MARKDOWN_EXTENSIONS': ['toc', ],
|
'MARKDOWN_EXTENSIONS': ['toc', ],
|
||||||
|
'STATIC_PAGES': {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue