Commits

Sergey Astanin committed 84cc51c

update plugins for obraz pre-0.4

- remove unpublished.py (now hardcoded in obraz.py)
- read site config in tags.py
- accept config in markdown_extra.py

  • Participants
  • Parent commits db7ac31

Comments (0)

Files changed (3)

File plugins/markdown_extra.py

 
 @obraz.template_filter('markdownify')
 @obraz.file_filter(['.md', '.markdown'])
-def markdown_extra_filter(s):
-    config = obraz._default_config.copy()
-    config_file = '_config.yml'
-    config.update(obraz.load_yaml_mapping(config_file))
+def markdown_extra_filter(s, config):
     extensions = config.get("markdown",{}).get("extensions",[])
     return markdown(s, extensions)

File plugins/tags.py

 
 The following template variables are available inside a tag template:
 
-* `page.tag`: tag name
-* `page.posts`: list of tagged blog post objects provided by Obraz
+* `tag`: tag name
+* `posts`: list of tagged blog post objects provided by Obraz
 
 Requirements:
 
 import obraz
 
 __version__ = '0.1'
-default_page_info = {
-    'url': '/tags/{tag}.html',
-    'layout': 'tag',
-}
 
 
 @obraz.processor
     """Processing tags."""
     pages = site.get('pages', [])
     settings = site.get('tags_plugin', {})
-    for page_info in settings.get('pages', [default_page_info]):
+    for page_info in settings.get('pages', site.get("tags_plugin",[])):
         for tag, posts in site.get('tags', {}).items():
             page = {
                 'url': page_info['url'].format(tag=tag),

File plugins/unpublished.py

-# -*- coding: utf-8 -*-
  1. Andrey Vlasovskikh

    I'd like to discuss with you working with unpublished and draft posts. Currently Obraz supports only unpublished flag in the YAML front matter of a post, so it is only possible to mute some posts without any preview mode. Jekyll has recently developed the notion of draft posts, i.e. posts stored in _drafts folder without a date in the file name. They can be published temporarily by passing --drafts to jekyll build or jekyll serve. Would it be enough for you? What was the reason for deletion of your plugin?

    1. Sergey Astanin author

      I was playing with the idea of drafts a little, but I believe it's a solution for the wrong problem.The actual use case is previewing only one post (the one that's being edited) and doing it fast.

      I considered two interfaces:

      obraz preview path/to/_posts/some_post.md
      

      to render just one page using the same site settings; probably to a temporary file. Or

      obraz build --only path/to/_posts/some_post.md
      

      which would render the entire _site like if it had only one page. I tried implementing the latter, by tweaking 'include' and 'exclude_patterns', but I didn't like the code, because it felt like a hack.

      1. Andrey Vlasovskikh

        I've added support for draft posts located in _drafts as in Jekyll. You can use drafts for keeping your posts in VCS while not publishing them. Temporary publishing is possible via --drafts flag. Also I've added a very simple file watcher -w that allows reviewing your changes in the browser just after saving your post.

-
-# Copyright (c) 2013 Sergey Astanin
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-"""Don't publish posts which have a `published: false` header.
-
-How to use:
-
-  * put this file into _plugins/ directory of your site
-
-  * add
-
-        published: false
-
-    header to your posts which are not ready yet
-
-  * change the header to
-
-        published: true
-
-    or remove it when the post is ready to be published.
-
-To enable publishing of draft posts (like for local preview), add
-
-    future: true
-
-to site configuration (`_config.yml`).
-
-Requirements:
-
-  * Obraz >= 0.4
-
-"""
-
-import obraz
-
-
-@obraz.processor
-def dont_publish_drafts(site):
-    "Hide posts with `published: false`"
-    config = obraz._default_config.copy()
-    config_file = '_config.yml'
-    config.update(obraz.load_yaml_mapping(config_file))
-    show_future = config.get("future", False)
-
-    if not show_future:
-        posts = site.get("posts",[])
-        published = [ p for p in posts if p.get("published", True) ]
-        site["posts"] = published