mirror of
https://github.com/vale981/ablog
synced 2025-03-06 01:31:39 -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:
|
else:
|
||||||
return ''
|
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):
|
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['ablog'] = Blog(app)
|
||||||
context['anchor'] = anchor
|
context['anchor'] = anchor
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ from docutils.parsers.rst import directives
|
||||||
from docutils.utils import relative_path
|
from docutils.utils import relative_path
|
||||||
|
|
||||||
import ablog
|
import ablog
|
||||||
|
from . import build_safe
|
||||||
from .blog import Blog, slugify, os_path_join, revise_pending_xrefs
|
from .blog import Blog, slugify, os_path_join, revise_pending_xrefs
|
||||||
|
|
||||||
if sys.version_info >= (3, 0):
|
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
|
"""Generate archive pages for all posts, categories, tags, authors, and
|
||||||
drafts."""
|
drafts."""
|
||||||
|
|
||||||
if app.builder.name not in {'html', 'dirhtml'}:
|
if not build_safe(app):
|
||||||
return
|
return
|
||||||
|
|
||||||
blog = Blog(app)
|
blog = Blog(app)
|
||||||
|
@ -562,7 +563,7 @@ def generate_atom_feeds(app):
|
||||||
"""Generate archive pages for all posts, categories, tags, authors, and
|
"""Generate archive pages for all posts, categories, tags, authors, and
|
||||||
drafts."""
|
drafts."""
|
||||||
|
|
||||||
if app.builder.name not in {'html', 'dirhtml'}:
|
if not build_safe(app):
|
||||||
return
|
return
|
||||||
|
|
||||||
blog = Blog(app)
|
blog = Blog(app)
|
||||||
|
|
Loading…
Add table
Reference in a new issue