Some small fixes:

Prevent an abort during start (due no app parameter to Blog)
Cleanup disqus template (no comments)
Allow to run without Werkzeug/AtomFeed
etc
This commit is contained in:
Albert Mietus 2015-07-29 17:30:47 +02:00
parent 6d25236958
commit 38ef6c4de1
4 changed files with 17 additions and 11 deletions

1
ablog/__init__.py Executable file → Normal file
View file

@ -9,6 +9,7 @@ from .post import (PostDirective, PostListDirective, UpdateDirective,
missing_reference)
__version__ = '0.7.7'
__version__ += '-GAM'
def anchor(post):

View file

@ -94,7 +94,7 @@ class Blog(object):
# using a shared state
_dict = {}
def __init__(self, app=None):
def __init__(self, app):
self.__dict__ = self._dict
if not self._dict:

View file

@ -275,7 +275,7 @@ def process_posts(app, doctree):
except ValueError:
raise ValueError('invalid post date in: ' + docname)
else:
raise ValueError('invalid post date in: ' + docname)
raise ValueError('invalid post date (%s) in: ' % (date) + docname +" expected format=%s" % post_date_format)
else:
date = None
@ -361,7 +361,7 @@ def process_postlist(app, doctree, docname):
"""Replace `PostList` nodes with lists of posts. Also, register all posts
if they have not been registered yet."""
blog = Blog()
blog = Blog(app)
if not blog:
register_posts(app)
@ -389,7 +389,7 @@ def process_postlist(app, doctree, docname):
fmts = list(Formatter().parse(node.attributes['format']))
for text, key, __, __ in fmts:
if key not in {'date', 'title', 'author', 'location', 'language',
'category', 'tags'}:
'category', 'tags', None}:
raise KeyError('{} is not recognized in postlist format'
.format(key))
@ -407,6 +407,8 @@ def process_postlist(app, doctree, docname):
for text, key, __, __ in fmts:
if text:
par.append(nodes.Text(text))
if key is None:
continue
if key == 'date':
par.append(nodes.Text(post.date.strftime(date_format)))
else:
@ -440,7 +442,6 @@ def process_postlist(app, doctree, docname):
app.env.resolve_references(enode, docname, app.builder)
enode.parent = bli.parent
bli.append(enode)
bli.append(nodes.line())
node.replace_self(bl)
@ -566,7 +567,12 @@ def generate_atom_feeds(app):
if not url:
raise StopIteration
from werkzeug.contrib.atom import AtomFeed
try:
from werkzeug.contrib.atom import AtomFeed
except ImportError:
app.warn("Can't import werkzeug's AtomFeed. Continue without atom/rss/feeds support")
return
feed_path = os.path.join(app.builder.outdir, blog.blog_path, 'atom.xml')
feeds = [(blog.posts,
@ -648,7 +654,7 @@ def generate_atom_feeds(app):
def register_posts(app):
"""Register posts found in the Sphinx build environment."""
blog = Blog()
blog = Blog(app)
for docname, posts in getattr(app.env, 'ablog_posts', {}).items():
for postinfo in posts:
blog.register(docname, postinfo)

View file

@ -6,7 +6,7 @@
<link rel="alternate" type="application/atom+xml" href="{{ pathto(feed_path, 1) }}/atom.xml" title="{{ ablog.blog_title }}">
{% endif %}
{% if ablog.fontawesome_link_cdn%}
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<link href="{{ ablog.fontawesome_link_cdn }}" rel="stylesheet">
{% elif ablog.fontawesome_css_file %}
<link rel="stylesheet" href="{{ pathto('_static/' + ablog.fontawesome_css_file, 1) }}" type="text/css" />
{% endif %}
@ -30,12 +30,11 @@
<h2>Comments</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = '{{ ablog.disqus_shortname }}'; // required: replace example with your forum shortname
var disqus_shortname = '{{ ablog.disqus_shortname }}';
var disqus_identifier = '{{ablog.page_id(pagename)}}';
var disqus_title = '{{title|e}}';
var disqus_url = '{{ablog.page_url(pagename)}}';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';