Keeping not JSON serializable objects out of html context (#47)

ABlog objects are not JSON serializable. They are used for
creating archive pages, and work fine with HTML builders.
When json builder is used, it pickles HTML context along
with HTML, and this causes serialization issues. So ABlog
objects (functions, Catalog, Blog instance, etc.) are avoided
when builder is not one of html/dirhtml.
This commit is contained in:
Ahmet Bakan 2015-09-14 17:41:56 -07:00
parent aa36f76552
commit 698eaea6e0
2 changed files with 10 additions and 3 deletions

View file

@ -22,6 +22,7 @@ def anchor(post):
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'}:
context['ablog'] = Blog(app) context['ablog'] = Blog(app)
context['anchor'] = anchor context['anchor'] = anchor

View file

@ -361,7 +361,7 @@ def process_postlist(app, doctree, docname):
"""Replace `PostList` nodes with lists of posts. Also, register all posts """Replace `PostList` nodes with lists of posts. Also, register all posts
if they have not been registered yet.""" if they have not been registered yet."""
blog = Blog() blog = Blog(app)
if not blog: if not blog:
register_posts(app) register_posts(app)
@ -480,6 +480,9 @@ 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'}:
return
blog = Blog(app) blog = Blog(app)
for post in blog.posts: for post in blog.posts:
for redirect in post.redirect: for redirect in post.redirect:
@ -559,6 +562,9 @@ 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'}:
return
blog = Blog(app) blog = Blog(app)