mirror of
https://github.com/vale981/ablog
synced 2025-03-05 17:21:38 -05:00
Added build_safe function, and using it to avoide json builder (#47).
This commit is contained in:
parent
25f9b3bff3
commit
605540efcb
2 changed files with 14 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue