mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
commit
ea97e9a9a8
3 changed files with 23 additions and 14 deletions
|
|
@ -6,6 +6,7 @@ import logging
|
||||||
import datetime
|
import datetime
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from codecs import open
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
@ -16,7 +17,7 @@ from jinja2.exceptions import 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
|
||||||
from pelican.utils import copy, process_translations, open
|
from pelican.utils import copy, process_translations
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -188,7 +189,7 @@ class ArticlesGenerator(Generator):
|
||||||
save_as = self.settings.get("%s_SAVE_AS" % template.upper(),
|
save_as = self.settings.get("%s_SAVE_AS" % template.upper(),
|
||||||
'%s.html' % template)
|
'%s.html' % template)
|
||||||
if not save_as:
|
if not save_as:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
write(save_as, self.get_template(template),
|
write(save_as, self.get_template(template),
|
||||||
self.context, blog=True, paginated=paginated,
|
self.context, blog=True, paginated=paginated,
|
||||||
|
|
@ -269,7 +270,7 @@ class ArticlesGenerator(Generator):
|
||||||
if 'category' not in metadata:
|
if 'category' not in metadata:
|
||||||
|
|
||||||
if os.path.dirname(f) == article_path: # if the article is not in a subdirectory
|
if os.path.dirname(f) == article_path: # if the article is not in a subdirectory
|
||||||
category = self.settings['DEFAULT_CATEGORY']
|
category = self.settings['DEFAULT_CATEGORY']
|
||||||
else:
|
else:
|
||||||
category = os.path.basename(os.path.dirname(f))\
|
category = os.path.basename(os.path.dirname(f))\
|
||||||
.decode('utf-8')
|
.decode('utf-8')
|
||||||
|
|
@ -352,7 +353,7 @@ class ArticlesGenerator(Generator):
|
||||||
|
|
||||||
self.authors = list(self.authors.items())
|
self.authors = list(self.authors.items())
|
||||||
self.authors.sort(key=lambda item: item[0].name)
|
self.authors.sort(key=lambda item: item[0].name)
|
||||||
|
|
||||||
self._update_context(('articles', 'dates', 'tags', 'categories',
|
self._update_context(('articles', 'dates', 'tags', 'categories',
|
||||||
'tag_cloud', 'authors', 'related_posts'))
|
'tag_cloud', 'authors', 'related_posts'))
|
||||||
|
|
||||||
|
|
@ -370,7 +371,7 @@ class PagesGenerator(Generator):
|
||||||
self.hidden_translations = []
|
self.hidden_translations = []
|
||||||
super(PagesGenerator, self).__init__(*args, **kwargs)
|
super(PagesGenerator, self).__init__(*args, **kwargs)
|
||||||
signals.pages_generator_init.send(self)
|
signals.pages_generator_init.send(self)
|
||||||
|
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
all_pages = []
|
all_pages = []
|
||||||
hidden_pages = []
|
hidden_pages = []
|
||||||
|
|
@ -453,13 +454,20 @@ class PdfGenerator(Generator):
|
||||||
"""Generate PDFs on the output dir, for all articles and pages coming from
|
"""Generate PDFs on the output dir, for all articles and pages coming from
|
||||||
rst"""
|
rst"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(PdfGenerator, self).__init__(*args, **kwargs)
|
||||||
try:
|
try:
|
||||||
from rst2pdf.createpdf import RstToPdf
|
from rst2pdf.createpdf import RstToPdf
|
||||||
|
pdf_style_path = os.path.join(self.settings['PDF_STYLE_PATH']) \
|
||||||
|
if 'PDF_STYLE_PATH' in self.settings.keys() \
|
||||||
|
else ''
|
||||||
|
pdf_style = self.settings['PDF_STYLE'] if 'PDF_STYLE' \
|
||||||
|
in self.settings.keys() \
|
||||||
|
else 'twelvepoint'
|
||||||
self.pdfcreator = RstToPdf(breakside=0,
|
self.pdfcreator = RstToPdf(breakside=0,
|
||||||
stylesheets=['twelvepoint'])
|
stylesheets=[pdf_style],
|
||||||
|
style_path=[pdf_style_path])
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise Exception("unable to find rst2pdf")
|
raise Exception("unable to find rst2pdf")
|
||||||
super(PdfGenerator, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
def _create_pdf(self, obj, output_path):
|
def _create_pdf(self, obj, output_path):
|
||||||
if obj.filename.endswith(".rst"):
|
if obj.filename.endswith(".rst"):
|
||||||
|
|
@ -467,7 +475,7 @@ class PdfGenerator(Generator):
|
||||||
output_pdf = os.path.join(output_path, filename)
|
output_pdf = os.path.join(output_path, filename)
|
||||||
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
# print "Generating pdf for", obj.filename, " in ", output_pdf
|
||||||
with open(obj.filename) as f:
|
with open(obj.filename) as f:
|
||||||
self.pdfcreator.createPdf(text=f, output=output_pdf)
|
self.pdfcreator.createPdf(text=f.read(), output=output_pdf)
|
||||||
logger.info(u' [ok] writing %s' % output_pdf)
|
logger.info(u' [ok] writing %s' % output_pdf)
|
||||||
|
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ except ImportError:
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from pelican.contents import Category, Tag, Author
|
from pelican.contents import Category, Tag, Author
|
||||||
from pelican.utils import get_date, open
|
from pelican.utils import get_date, pelican_open
|
||||||
|
|
||||||
|
|
||||||
_METADATA_PROCESSORS = {
|
_METADATA_PROCESSORS = {
|
||||||
|
|
@ -129,7 +129,7 @@ class MarkdownReader(Reader):
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Parse content and metadata of markdown files"""
|
"""Parse content and metadata of markdown files"""
|
||||||
text = open(filename)
|
text = pelican_open(filename)
|
||||||
md = Markdown(extensions=set(self.extensions + ['meta']))
|
md = Markdown(extensions=set(self.extensions + ['meta']))
|
||||||
content = md.convert(text)
|
content = md.convert(text)
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ class HtmlReader(Reader):
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Parse content and metadata of (x)HTML files"""
|
"""Parse content and metadata of (x)HTML files"""
|
||||||
with open(filename) as content:
|
with pelican_open(filename) as content:
|
||||||
metadata = {'title': 'unnamed'}
|
metadata = {'title': 'unnamed'}
|
||||||
for i in self._re.findall(content):
|
for i in self._re.findall(content):
|
||||||
key = i.split(':')[0][5:].strip()
|
key = i.split(':')[0][5:].strip()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import shutil
|
||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from codecs import open as _open
|
from codecs import open
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from jinja2 import Markup
|
from jinja2 import Markup
|
||||||
|
|
@ -14,6 +14,7 @@ from operator import attrgetter
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class NoFilesError(Exception):
|
class NoFilesError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -37,9 +38,9 @@ def get_date(string):
|
||||||
raise ValueError("'%s' is not a valid date" % string)
|
raise ValueError("'%s' is not a valid date" % string)
|
||||||
|
|
||||||
|
|
||||||
def open(filename):
|
def pelican_open(filename):
|
||||||
"""Open a file and return it's content"""
|
"""Open a file and return it's content"""
|
||||||
return _open(filename, encoding='utf-8').read()
|
return open(filename, encoding='utf-8').read()
|
||||||
|
|
||||||
|
|
||||||
def slugify(value):
|
def slugify(value):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue