Skip to content

Commit

Permalink
Refactor on_frontmatter_loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Jul 11, 2015
1 parent 5fdd2b7 commit fbdd293
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions handroll/extensions/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,10 @@ def on_pre_composition(self, director):
self._resolver = director.resolver

def on_frontmatter_loaded(self, source_file, frontmatter):
"""Scan for blog posts.
If a post is found, record it.
"""
is_post = frontmatter.get('blog', False)
if type(is_post) != bool:
raise AbortError(
_('Invalid blog frontmatter (expects True or False): '
'{blog_value}').format(blog_value=is_post))
# TODO: Validate that the post has the required fields.
if not is_post:
"""Record any new blog posts."""
if not self._is_post(frontmatter):
return
# TODO: Validate that the post has the required fields.
post = BlogPost(
date=frontmatter['date'],
source_file=source_file,
Expand All @@ -112,6 +104,15 @@ def on_post_composition(self, director):
self._generate_list_page(director, blog_posts)
self._should_generate = False

def _is_post(self, frontmatter):
"""Check if the front matter looks like a blog post."""
is_post = frontmatter.get('blog', False)
if type(is_post) != bool:
raise AbortError(
_('Invalid blog frontmatter (expects True or False): '
'{blog_value}').format(blog_value=is_post))
return is_post

def _generate_atom_feed(self, director, blog_posts):
"""Generate the atom feed."""
logger.info(_('Generating Atom XML feed ...'))
Expand Down

0 comments on commit fbdd293

Please sign in to comment.