mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
update TemplatePagesGenerator:
* bugfix: now supports custom path for path where to find the content files
* TEMPLATE_PAGES settings is now of the form:
{ 'jinja2/src/file.html': 'dest/file.html' }
* update doc
This commit is contained in:
parent
e0e1b3eecf
commit
54eee3f28a
2 changed files with 16 additions and 17 deletions
|
|
@ -275,15 +275,15 @@ Template pages
|
||||||
==============
|
==============
|
||||||
|
|
||||||
If you want to generate custom pages besides your blog entries, you can point
|
If you want to generate custom pages besides your blog entries, you can point
|
||||||
any Jinja2 template file with a path pointing to the file and the URL it will
|
any Jinja2 template file with a path pointing to the file and the destination
|
||||||
match.
|
path for the generated file.
|
||||||
|
|
||||||
For instance, if you have a blog with four static pages, for a list of books,
|
For instance, if you have a blog with three static pages, for a list of books,
|
||||||
your resume and a contact page, you could have::
|
your resume and a contact page, you could have::
|
||||||
|
|
||||||
TEMPLATE_PAGES = {'/books.html': 'static/books.html',
|
TEMPLATE_PAGES = {'src/books.html': 'dest/books.html',
|
||||||
'/resume.html': 'static/resume.html',
|
'src/resume.html': 'dest/resume.html',
|
||||||
'/contact.html': 'static/contact.html'}
|
'src/contact.html': 'dest/contact.html'}
|
||||||
|
|
||||||
Feed settings
|
Feed settings
|
||||||
=============
|
=============
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ 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
|
||||||
|
|
@ -113,29 +112,29 @@ class Generator(object):
|
||||||
|
|
||||||
class _FileLoader(BaseLoader):
|
class _FileLoader(BaseLoader):
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path, basedir):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.fullpath = os.path.join(basedir, path)
|
||||||
|
|
||||||
def get_source(self, environment, template):
|
def get_source(self, environment, template):
|
||||||
path = template
|
if template != self.path or not os.path.exists(self.fullpath):
|
||||||
if not exists(path):
|
|
||||||
raise TemplateNotFound(template)
|
raise TemplateNotFound(template)
|
||||||
mtime = getmtime(path)
|
mtime = os.path.getmtime(self.fullpath)
|
||||||
with file(path) as f:
|
with file(self.fullpath) as f:
|
||||||
source = f.read().decode('utf-8')
|
source = f.read().decode('utf-8')
|
||||||
return source, path, lambda: mtime == getmtime(path)
|
return source, self.fullpath, \
|
||||||
|
lambda: mtime == os.path.getmtime(self.fullpath)
|
||||||
|
|
||||||
|
|
||||||
class TemplatePagesGenerator(Generator):
|
class TemplatePagesGenerator(Generator):
|
||||||
|
|
||||||
def generate_output(self, writer):
|
def generate_output(self, writer):
|
||||||
for urlpath, source in self.settings['TEMPLATE_PAGES'].items():
|
for source, dest in self.settings['TEMPLATE_PAGES'].items():
|
||||||
self.env.loader.loaders.insert(0, _FileLoader(source))
|
self.env.loader.loaders.insert(0, _FileLoader(source, self.path))
|
||||||
try:
|
try:
|
||||||
template = self.env.get_template(source)
|
template = self.env.get_template(source)
|
||||||
rurls = self.settings.get('RELATIVE_URLS')
|
rurls = self.settings.get('RELATIVE_URLS')
|
||||||
writer.write_file(
|
writer.write_file(dest, template, self.context, rurls)
|
||||||
urlpath.strip('/'), template, self.context, rurls)
|
|
||||||
finally:
|
finally:
|
||||||
del self.env.loader.loaders[0]
|
del self.env.loader.loaders[0]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue