mirror of
https://github.com/vale981/ablog
synced 2025-03-06 09:41:39 -05:00
Fixed issue with postlist length being not set.
This commit is contained in:
parent
1031e17786
commit
c211483859
2 changed files with 43 additions and 30 deletions
|
@ -223,6 +223,8 @@ class Blog(object):
|
||||||
def recent(self, num, docname=None, **labels):
|
def recent(self, num, docname=None, **labels):
|
||||||
"""Yield *num* recent posts, excluding the one with `docname`."""
|
"""Yield *num* recent posts, excluding the one with `docname`."""
|
||||||
|
|
||||||
|
if num is None:
|
||||||
|
num = len(self)
|
||||||
for i, post in enumerate(self.posts):
|
for i, post in enumerate(self.posts):
|
||||||
if post.docname == docname:
|
if post.docname == docname:
|
||||||
num += 1
|
num += 1
|
||||||
|
|
|
@ -156,6 +156,38 @@ def purge_posts(app, env, docname):
|
||||||
env.domains['std'].data['labels'].pop(filename, None)
|
env.domains['std'].data['labels'].pop(filename, None)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_section_title(section):
|
||||||
|
"""Return section title as text."""
|
||||||
|
|
||||||
|
for title in section.traverse(nodes.title):
|
||||||
|
break
|
||||||
|
# A problem with the following is that title may contain pending
|
||||||
|
# references, e.g. :ref:`tag-tips`
|
||||||
|
title = title.astext()
|
||||||
|
|
||||||
|
|
||||||
|
def _get_update_dates(section, docname, post_date_format):
|
||||||
|
"""Return list of dates of updates found section."""
|
||||||
|
|
||||||
|
|
||||||
|
update_nodes = list(section.traverse(UpdateNode))
|
||||||
|
update_dates = []
|
||||||
|
for update_node in update_nodes:
|
||||||
|
try:
|
||||||
|
update = datetime.strptime(update_node['date'], post_date_format)
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError('invalid post update date in: ' + docname)
|
||||||
|
|
||||||
|
substitute = nodes.title(u'',
|
||||||
|
update_node[0][0].astext() + u' ' + update.strftime(post_date_format))
|
||||||
|
update_node[0].replace_self(substitute)
|
||||||
|
# for now, let updates look like note
|
||||||
|
update_node['classes'] = ['note', 'update']
|
||||||
|
|
||||||
|
update_dates.append(update)
|
||||||
|
return update_dates
|
||||||
|
|
||||||
|
|
||||||
def process_posts(app, doctree):
|
def process_posts(app, doctree):
|
||||||
"""Process posts and map posted document names to post details in the
|
"""Process posts and map posted document names to post details in the
|
||||||
environment."""
|
environment."""
|
||||||
|
@ -167,11 +199,10 @@ def process_posts(app, doctree):
|
||||||
if not hasattr(env, 'ablog_posts'):
|
if not hasattr(env, 'ablog_posts'):
|
||||||
env.ablog_posts = {}
|
env.ablog_posts = {}
|
||||||
|
|
||||||
|
|
||||||
post_nodes = list(doctree.traverse(PostNode))
|
post_nodes = list(doctree.traverse(PostNode))
|
||||||
if not post_nodes:
|
if not post_nodes:
|
||||||
return
|
return
|
||||||
pdf = app.config['post_date_format']
|
post_date_format = app.config['post_date_format']
|
||||||
docname = env.docname
|
docname = env.docname
|
||||||
|
|
||||||
# mark the post as 'orphan' so that
|
# mark the post as 'orphan' so that
|
||||||
|
@ -181,8 +212,8 @@ def process_posts(app, doctree):
|
||||||
blog = Blog(app)
|
blog = Blog(app)
|
||||||
auto_excerpt = blog.post_auto_excerpt
|
auto_excerpt = blog.post_auto_excerpt
|
||||||
multi_post = len(post_nodes) > 1 or blog.post_always_section
|
multi_post = len(post_nodes) > 1 or blog.post_always_section
|
||||||
|
|
||||||
for order, node in enumerate(post_nodes, start=1):
|
for order, node in enumerate(post_nodes, start=1):
|
||||||
# print node['excerpt']
|
|
||||||
if node['excerpt'] is None:
|
if node['excerpt'] is None:
|
||||||
node['excerpt'] = auto_excerpt
|
node['excerpt'] = auto_excerpt
|
||||||
|
|
||||||
|
@ -199,31 +230,11 @@ def process_posts(app, doctree):
|
||||||
|
|
||||||
# get updates here, in the section that post belongs to
|
# get updates here, in the section that post belongs to
|
||||||
# Might there be orphan updates?
|
# Might there be orphan updates?
|
||||||
update_nodes = list(section.traverse(UpdateNode))
|
update_dates = _get_update_dates(section, docname, post_date_format)
|
||||||
update_dates = []
|
|
||||||
for un in update_nodes:
|
|
||||||
try:
|
|
||||||
update = datetime.strptime(un['date'], pdf)
|
|
||||||
except ValueError:
|
|
||||||
raise ValueError('invalid post update date in: ' + docname)
|
|
||||||
|
|
||||||
un[0].replace_self(nodes.title(u'', un[0][0].astext() + u' ' +
|
|
||||||
update.strftime(pdf)))
|
|
||||||
# for now, let updates look like note
|
|
||||||
un['classes'] = ['note', 'update']
|
|
||||||
|
|
||||||
update_dates.append(update)
|
|
||||||
|
|
||||||
|
|
||||||
# Making sure that post has a title because all post titles
|
# Making sure that post has a title because all post titles
|
||||||
# are needed when resolving post lists in documents
|
# are needed when resolving post lists in documents
|
||||||
title = node['title']
|
title = node['title'] or _get_section_title(section)
|
||||||
if not title:
|
|
||||||
for title in section.traverse(nodes.title):
|
|
||||||
break
|
|
||||||
# A problem with the following is that title may contain pending
|
|
||||||
# references, e.g. :ref:`tag-tips`
|
|
||||||
title = title.astext()
|
|
||||||
|
|
||||||
# creating a summary here, before references are resolved
|
# creating a summary here, before references are resolved
|
||||||
excerpt = []
|
excerpt = []
|
||||||
|
@ -253,7 +264,7 @@ def process_posts(app, doctree):
|
||||||
date = node['date']
|
date = node['date']
|
||||||
if date:
|
if date:
|
||||||
try:
|
try:
|
||||||
date = datetime.strptime(date, pdf)
|
date = datetime.strptime(date, post_date_format)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError('invalid post published date in: ' + docname)
|
raise ValueError('invalid post published date in: ' + docname)
|
||||||
else:
|
else:
|
||||||
|
@ -269,9 +280,7 @@ def process_posts(app, doctree):
|
||||||
if not label:
|
if not label:
|
||||||
label = slugify(title)
|
label = slugify(title)
|
||||||
|
|
||||||
|
|
||||||
section_name = ''
|
section_name = ''
|
||||||
|
|
||||||
if multi_post and section.parent is not doctree:
|
if multi_post and section.parent is not doctree:
|
||||||
section_name = section.attributes['ids'][0]
|
section_name = section.attributes['ids'][0]
|
||||||
label += '-' + section_name
|
label += '-' + section_name
|
||||||
|
@ -320,7 +329,6 @@ def process_posts(app, doctree):
|
||||||
|
|
||||||
# instantiate catalogs and collections here
|
# instantiate catalogs and collections here
|
||||||
# so that references are created and no warnings are issued
|
# so that references are created and no warnings are issued
|
||||||
|
|
||||||
for key in ['tags', 'author', 'category', 'location', 'language']:
|
for key in ['tags', 'author', 'category', 'location', 'language']:
|
||||||
catalog = blog.catalogs[key]
|
catalog = blog.catalogs[key]
|
||||||
for label in postinfo[key]:
|
for label in postinfo[key]:
|
||||||
|
@ -343,6 +351,7 @@ def process_postlist(app, doctree, docname):
|
||||||
for coll in node[cat]:
|
for coll in node[cat]:
|
||||||
if coll in blog.catalogs[cat].collections:
|
if coll in blog.catalogs[cat].collections:
|
||||||
colls.append(blog.catalogs[cat].collections[coll])
|
colls.append(blog.catalogs[cat].collections[coll])
|
||||||
|
|
||||||
if colls:
|
if colls:
|
||||||
posts = set(blog.posts)
|
posts = set(blog.posts)
|
||||||
for coll in colls:
|
for coll in colls:
|
||||||
|
@ -353,6 +362,7 @@ def process_postlist(app, doctree, docname):
|
||||||
else:
|
else:
|
||||||
posts = list(blog.recent(node.attributes['length'], docname,
|
posts = list(blog.recent(node.attributes['length'], docname,
|
||||||
**node.attributes))
|
**node.attributes))
|
||||||
|
|
||||||
if node.attributes['sort']:
|
if node.attributes['sort']:
|
||||||
posts.sort() # in reverse chronological order, so no reverse=True
|
posts.sort() # in reverse chronological order, so no reverse=True
|
||||||
|
|
||||||
|
@ -458,7 +468,7 @@ def generate_archive_pages(app):
|
||||||
yield (collection.docname, context, 'collection.html')
|
yield (collection.docname, context, 'collection.html')
|
||||||
|
|
||||||
|
|
||||||
ppp = 5
|
#ppp = 5
|
||||||
#for page, i in enumerate(range(0, len(blog.posts), ppp)):
|
#for page, i in enumerate(range(0, len(blog.posts), ppp)):
|
||||||
if 1:
|
if 1:
|
||||||
context = {
|
context = {
|
||||||
|
@ -574,6 +584,7 @@ def generate_atom_feeds(app):
|
||||||
# and make work for Sphinx 'html-collect-pages'
|
# and make work for Sphinx 'html-collect-pages'
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
def register_posts(app):
|
def register_posts(app):
|
||||||
"""Register posts found in the Sphinx build environment."""
|
"""Register posts found in the Sphinx build environment."""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue