Commits

Andrey Vlasovskikh committed 7323a62

Tags plugin for Obraz site

  • Participants
  • Parent commits f5ead48

Comments (0)

Files changed (10)

File doc/_config.yml

 url: http://obraz.pirx.ru
-
+tags_plugin:
+  descriptions:
+    release: Release notes

File doc/_layouts/post.html

   </div>
   <h1>{{ page.title }}</h1>
   {{ content }}
+  <div class="tags">
+    {% if page.tags %}
+      Tags:
+      {% for tag in page.tags %}
+        <a href="/tags/{{ tag }}.html">{{ tag }}</a>
+      {%- endfor -%}
+      .
+    {% endif %}
+  </div>
   {% include 'buttons.html' %}
 </section>
 

File doc/_layouts/tag.html

+---
+layout: default
+title: Tagged Posts
+---
+<section id="news" class="hfeed">
+  {% set description = site.tags_plugin.descriptions[page.tag] %}
+  <h1>{{ description|default(page.tag)|title }} <a href="/tags/{{ page.tag }}.atom"><img src="/media/feed.png" alt="(feed)"/></a></h1>
+  {% for post in page.posts|sort(attribute='date', reverse=True) %}
+    <section class="hentry">
+      <div class="published">{{ post.date.strftime('%Y-%m-%d') }}</div>
+      <h4><a href="{{ post.url }}">{{ post.title }}</a></h4>
+    </section>
+  {% endfor %}
+</section>

File doc/_plugins/tags.py

+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2013 Andrey Vlasovskikh
+#
+# 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.
+
+"""Tags plugin for Obraz.
+
+This plugin generates separate pages for tags.
+
+You can configure it via the `tags_plugin` section of `_config.yml`. The
+default implicit configuration is:
+
+    tags_plugin:
+      pages:
+        - url: /tags/{tag}.html
+          layout: tag
+
+`pages` is a list of tag pages, it is possible to generate multiple sets of
+tag pages, e.g. HTML and RSS.
+
+The following template variables are available inside a tag template:
+
+* `tag`: tag name
+* `posts`: list of tagged blog post objects provided by Obraz
+
+Requirements:
+
+* Obraz == 0.4.x
+"""
+
+import obraz
+
+__version__ = '0.1'
+default_page_info = {
+    'url': '/tags/{tag}.html',
+    'layout': 'tag',
+}
+
+
+@obraz.processor
+def process_tags(basedir, destdir, site):
+    """Processing tags."""
+    pages = site.get('pages', [])
+    site.get('pages')
+    settings = site.get('tags_plugin', {})
+    for page_info in settings.get('pages', [default_page_info]):
+        for tag, posts in site.get('tags', {}).items():
+            page = {
+                'url': page_info['url'].format(tag=tag),
+                'layout': page_info['layout'],
+                'content': '',
+                'tag': tag,
+                'posts': posts,
+            }
+            pages.append(page)

File doc/_posts/2012-05-25-initial.md

 ---
 title: Initial Post
 layout: post
+tags:
+  - tmp
 ---
 
 This post actually contains nothing interesting.

File doc/_posts/2012-05-26-obraz-0.1.md

 ---
 title: Obraz 0.1 Released
 layout: post
+tags:
+  - release
 ---
 
 It's the first public release of Obraz. Added almost all the main features of

File doc/_posts/2012-05-27-obraz-0.1.2.md

 ---
 layout: post
 title: Obraz 0.1.2 Released
+tags:
+  - release
 ---
 
 This is a bugfix release.

File doc/_posts/2012-06-02-obraz-0.2.md

 ---
 layout: post
 title: Obraz 0.2 Released
+tags:
+  - release
 ---
 
 This release introduces an experimental plugin system.

File doc/_posts/2012-06-08-obraz-0.2.1.md

 ---
 layout: post
 title: Obraz 0.2.1 Released
+tags:
+  - release
 ---
 
 This is a bugfix release.

File doc/_posts/2012-12-19-obraz-0.3.md

 ---
 layout: post
 title: Obraz 0.3 Released
+tags:
+  - release
 ---
 
 In this release the command line arguments have been changed to be more