Added build_safe function, and using it to avoide json builder (#47).

This commit is contained in:
Ahmet Bakan 2015-09-14 18:47:44 -07:00
parent 25f9b3bff3
commit 605540efcb
2 changed files with 14 additions and 3 deletions

View file

@ -19,10 +19,20 @@ def anchor(post):
else:
return ''
def build_safe(builder):
"""Return True when builder is expected to be safe. Safe builders are
HTML builders, excluding `PickleHTMLBuilder` and `JSONHTMLBuilder`
which run into issues when trying to serialize blog objects."""
if hasattr(builder, 'builder');
builder = builder.builder
return builder.format == 'html' and not builder.name in {'json', 'pickle'}
def html_page_context(app, pagename, templatename, context, doctree):
if app.builder.name in {'html', 'dirhtml'}:
if build_safe(app):
context['ablog'] = Blog(app)
context['anchor'] = anchor

View file

@ -18,6 +18,7 @@ from docutils.parsers.rst import directives
from docutils.utils import relative_path
import ablog
from . import build_safe
from .blog import Blog, slugify, os_path_join, revise_pending_xrefs
if sys.version_info >= (3, 0):
@ -480,7 +481,7 @@ def generate_archive_pages(app):
"""Generate archive pages for all posts, categories, tags, authors, and
drafts."""
if app.builder.name not in {'html', 'dirhtml'}:
if not build_safe(app):
return
blog = Blog(app)
@ -562,7 +563,7 @@ def generate_atom_feeds(app):
"""Generate archive pages for all posts, categories, tags, authors, and
drafts."""
if app.builder.name not in {'html', 'dirhtml'}:
if not build_safe(app):
return
blog = Blog(app)