diff --git a/ablog/__init__.py b/ablog/__init__.py index 130ba3a..cc727bc 100755 --- a/ablog/__init__.py +++ b/ablog/__init__.py @@ -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 diff --git a/ablog/post.py b/ablog/post.py index eaa298e..ea5a265 100644 --- a/ablog/post.py +++ b/ablog/post.py @@ -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)