-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle frontmatter in the blog extension.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
# Copyright (c) 2015, Matt Layman | ||
|
||
from handroll.exceptions import AbortError | ||
from handroll.extensions.base import Extension | ||
from handroll.i18n import _ | ||
|
||
|
||
class BlogPost(object): | ||
|
||
def __init__(self, **kwargs): | ||
self.source_file = kwargs['source_file'] | ||
|
||
|
||
class BlogExtension(Extension): | ||
"""Track files marked as blog entries and generate a feed.""" | ||
|
||
handle_frontmatter_loaded = True | ||
handle_post_composition = True | ||
|
||
def __init__(self, config): | ||
super(BlogExtension, self).__init__(config) | ||
self.posts = [] | ||
|
||
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)) | ||
if is_post: | ||
self.posts.append(BlogPost( | ||
source_file=source_file, | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters