add categories
authorRalf Jung <post@ralfj.de>
Mon, 12 Oct 2015 11:52:58 +0000 (13:52 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 12 Oct 2015 11:53:32 +0000 (13:53 +0200)
13 files changed:
ralf/_config.yml
ralf/_includes/post-feed.html [new file with mode: 0644]
ralf/_includes/post-header.html
ralf/_includes/post-list.html [new file with mode: 0644]
ralf/_includes/vars/blog-category.html [new file with mode: 0644]
ralf/_layouts/category_feed.html [new file with mode: 0644]
ralf/_layouts/category_index.html [new file with mode: 0644]
ralf/_layouts/feed.html [new file with mode: 0644]
ralf/_layouts/page.html [moved from ralf/_layouts/default.html with 80% similarity]
ralf/_plugins/categories.rb [new file with mode: 0644]
ralf/_plugins/readmes.rb
ralf/blog/feed.xml
ralf/blog/index.html

index d96c35d25a89274fc06e3f4d4195191536c829c2..a19a6d0182ce0257d3f6821298b1ee80386ebd2f 100644 (file)
@@ -7,6 +7,7 @@ timezone: "Europe/Berlin"
 
 blog:
     title: "Ralf's Ramblings"
 
 blog:
     title: "Ralf's Ramblings"
+    category_dir: "/blog/categories"
 
 readmes:
     src_base: "/home/r/src"
 
 readmes:
     src_base: "/home/r/src"
@@ -24,7 +25,7 @@ defaults:
   - scope:
         path: "" # all files in the project
     values:
   - scope:
         path: "" # all files in the project
     values:
-        layout: "default"
+        layout: "page"
   - scope:
         path: ""
         type: "posts"
   - scope:
         path: ""
         type: "posts"
diff --git a/ralf/_includes/post-feed.html b/ralf/_includes/post-feed.html
new file mode 100644 (file)
index 0000000..18959ed
--- /dev/null
@@ -0,0 +1,12 @@
+{% for post in include.posts limit:12 %}
+  <entry>
+    <title>{{ post.title | xml_escape }}</title>
+    <link href="{{ post.url | prepend: site.baseurl | prepend: site.url }}" />
+    <updated>{{ post.date | date_to_xmlschema }}</updated>
+    <id>{{ post.url | prepend: site.baseurl | prepend: site.url }}</id>
+    {% for cat in post.categories %}
+        <category term="{{ cat }}" label="{{ cat | capitalize }}"/>
+    {% endfor %}
+    <content type="html">{{ post.content | xml_escape }}</content>
+  </entry>
+{% endfor %}
index 6163cf5be14061788a762c36a9bb7c163fc6fbac..435447b48ad0fd26bbdd6a3fa98df2f48ceeada5 100644 (file)
@@ -1 +1,6 @@
-<div class="side">{{ include.item.date | date: "%b %-d, %Y" }}{% if include.item.author %} • {{ include.item.author }}{% endif %}{% if include.item.meta %} • {{ include.item.meta }}{% endif %} • <a href="{{ include.item.url }}">Permalink</a></div>
+<div class="side">{{ include.item.date | date: "%b %-d, %Y" }}
+    {% if include.item.author %} • {{ include.item.author }}{% endif %}
+    {% if include.item.meta %} • {{ include.item.meta }}{% endif %}
+    {% if include.item.categories %}  • {{ include.item.categories | category_links }}{% endif %}
+     • <a href="{{ include.item.url }}">Permalink</a>
+</div>
diff --git a/ralf/_includes/post-list.html b/ralf/_includes/post-list.html
new file mode 100644 (file)
index 0000000..7b14efc
--- /dev/null
@@ -0,0 +1,8 @@
+{% for post in include.posts %}
+    <header class="subtitle">
+      {% include post-header.html item=post %}
+      <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
+    </header>
+    {{ post.excerpt }}
+    <p><a href="{{ post.url }}">Read more...</a></p>
+{% endfor %}    
diff --git a/ralf/_includes/vars/blog-category.html b/ralf/_includes/vars/blog-category.html
new file mode 100644 (file)
index 0000000..a16df5a
--- /dev/null
@@ -0,0 +1 @@
+{% assign pretitle = site.blog.title %}
diff --git a/ralf/_layouts/category_feed.html b/ralf/_layouts/category_feed.html
new file mode 100644 (file)
index 0000000..db32965
--- /dev/null
@@ -0,0 +1,8 @@
+---
+layout: feed
+hide: true
+vars: "blog-category.html"
+---
+
+{% assign posts = site.categories[page.category] %}
+{% include post-feed.html posts=posts %}
diff --git a/ralf/_layouts/category_index.html b/ralf/_layouts/category_index.html
new file mode 100644 (file)
index 0000000..315dd44
--- /dev/null
@@ -0,0 +1,9 @@
+---
+layout: page
+hide: true
+rss: true
+vars: "blog-category.html"
+---
+
+{% assign posts = site.categories[page.category] %}
+{% include post-list.html posts=posts %}
diff --git a/ralf/_layouts/feed.html b/ralf/_layouts/feed.html
new file mode 100644 (file)
index 0000000..446a38d
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+    {% assign title = page.title %}
+    {% assign pretitle = page.pretitle %}
+    {% if page.vars %}{% include {{ page.vars | prepend: "vars/" }} %}{% endif %}
+    <title>{% if pretitle %}{{ pretitle | xml_escape }} • {% endif %}{{ title | xml_escape }}</title>
+    <link href="{{ page.url | prepend: site.baseurl | prepend: site.url }}" rel="self" type="application/atom+xml"/>
+    {% if page.category %}
+        <link href="{{ page.url | replace: '.xml','.html' | prepend: site.baseurl | prepend: site.url }}"/>
+    {% else %}
+        <link href="{{ "/blog/" | prepend: site.baseurl | prepend: site.url }}"/>
+    {% endif %}
+    <updated>{{ site.time | date_to_xmlschema }}</updated>
+    <author>
+        <name>Ralf Jung</name>
+    </author>
+    {{ content }}
+</rss>
similarity index 80%
rename from ralf/_layouts/default.html
rename to ralf/_layouts/page.html
index 3ac3deeb71deae0818ff5d74eb973d52b10d657d..a45f67fa3f0039624c099a218b7c7747fcab0d94 100644 (file)
 
     <link rel="stylesheet" href="{{ site.baseurl }}/style.css">
     <link rel="canonical" href="{{ site.url }}{{ site.baseurl }}{{ page.url | replace:'/index.html','/' }}">
 
     <link rel="stylesheet" href="{{ site.baseurl }}/style.css">
     <link rel="canonical" href="{{ site.url }}{{ site.baseurl }}{{ page.url | replace:'/index.html','/' }}">
-    {% if page.rss %}<link rel="alternate" type="application/rss+xml" title="{{ site.blog.title }}" href="{{ site.baseurl }}/blog/feed.xml" />{% endif %}
+    {% if page.rss %}
+        <link rel="alternate" type="application/atom+xml" title="{{ site.blog.title }}" href="{{ site.baseurl }}/blog/feed.xml" />
+        {% if page.category %}<link rel="alternate" type="application/atom+xml" title="{{ site.blog.title }} • {{ title }}" href="{{ site.baseurl }}{{ page.url | replace: '.html','.xml' }}" />{% endif %}
+    {% endif %}
   </head>
 
   <body><div id="-frame">
   </head>
 
   <body><div id="-frame">
diff --git a/ralf/_plugins/categories.rb b/ralf/_plugins/categories.rb
new file mode 100644 (file)
index 0000000..69375da
--- /dev/null
@@ -0,0 +1,65 @@
+module Jekyll
+
+  class CategoryPage < Page
+    def initialize(site, base, dir, name, category, layout)
+      @site = site
+      @base = base
+      @dir = dir
+      @name = name
+
+      self.process(@name)
+      self.read_yaml(File.join(base, '_layouts'), layout)
+      self.data['category'] = category
+
+      category_title_prefix = site.config['blog']['category_title_prefix'] || 'Category: '
+      self.data['title'] = "#{category_title_prefix}#{category.capitalize}"
+    end
+  end
+
+  class CategoryPageGenerator < Generator
+    safe true
+
+    def generate(site)
+      dir = site.config['blog']['category_dir'] || 'categories'
+      if site.layouts.key? 'category_index'
+        site.categories.each_key do |category|
+          site.pages << CategoryPage.new(site, site.source, dir, "#{category}.html", category, 'category_index.html')
+        end
+      end
+      if site.layouts.key? 'category_feed'
+        site.categories.each_key do |category|
+          site.pages << CategoryPage.new(site, site.source, dir, "#{category}.xml", category, 'category_feed.html')
+        end
+      end
+    end
+  end
+
+  # Adds some extra filters used during the category creation process.
+  module Filters
+
+    # Outputs a list of categories as comma-separated <a> links. This is used
+    # to output the category list for each post on a category page.
+    #
+    #  +categories+ is the list of categories to format.
+    #
+    # Returns string
+    def category_links(categories)
+      base_dir = @context.registers[:site].config['blog']['category_dir']
+      categories = categories.sort!.map do |category|
+        category_url = File.join(base_dir, "#{category}.html")
+        # Make sure the category directory begins with a slash.
+        category_dir = "/#{category_dir}" unless category_dir =~ /^\//
+        "<a class='category' href='#{category_url}'>#{category.capitalize}</a>"
+      end
+
+      case categories.length
+      when 0
+        ""
+      when 1
+        categories[0].to_s
+      else
+        categories.join(', ')
+      end
+    end
+  end
+end
index 922d3a896566d0ff2441fc15e0f180b20d7011f1..63df995ef9afd17a431ee2295d39baa5decb6d96 100644 (file)
@@ -12,7 +12,7 @@ module Jekyll
       
       content = File.read(src, self.merged_file_read_opts({})).each_line.to_a
 
       
       content = File.read(src, self.merged_file_read_opts({})).each_line.to_a
 
-      self.data['layout'] = 'default'
+      self.data['layout'] = 'page'
       self.data['title'] = content[0].match(/^#* ?(.*)\n$/)[1]
       slug = self.data['title'].match(/^([^:]*):.*$/)
       if slug
       self.data['title'] = content[0].match(/^#* ?(.*)\n$/)[1]
       slug = self.data['title'].match(/^([^:]*):.*$/)
       if slug
index 7a7e919aa8e57fca2bd85e98b25948a7756d8e2d..17b789de51ff6e998df69668d9e8d9b13cf4a62c 100644 (file)
@@ -1,31 +1,7 @@
 ---
 ---
-layout: null
+layout: feed
 slug: Subscribe
 slug: Subscribe
+vars: blog-index.html
 ---
 ---
-<?xml version="1.0" encoding="UTF-8"?>
-<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
-  <channel>
-    <title>{{ site.blog.title | xml_escape }}</title>
-    <description>{{ site.blog.title | xml_escape }}</description>
-    <link>{{ site.url }}{{ site.baseurl }}/</link>
-    <atom:link href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" rel="self" type="application/rss+xml"/>
-    <pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
-    <lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
-    <generator>Jekyll v{{ jekyll.version }}</generator>
-    {% for post in site.posts limit:10 %}
-      <item>
-        <title>{{ post.title | xml_escape }}</title>
-        <description>{{ post.content | xml_escape }}</description>
-        <pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
-        <link>{{ post.url | prepend: site.baseurl | prepend: site.url }}</link>
-        <guid isPermaLink="true">{{ post.url | prepend: site.baseurl | prepend: site.url }}</guid>
-        {% for tag in post.tags %}
-        <category>{{ tag | xml_escape }}</category>
-        {% endfor %}
-        {% for cat in post.categories %}
-        <category>{{ cat | xml_escape }}</category>
-        {% endfor %}
-      </item>
-    {% endfor %}
-  </channel>
-</rss>
+
+{% include post-feed.html posts=site.posts %}
index 380aaaadd3103898fcdcbb721c3188eb67a9c8a5..f85ed560a05fb5ccd2ab389936acb4c31e12747d 100644 (file)
@@ -5,16 +5,4 @@ rss: true
 sort: 10
 ---
 
 sort: 10
 ---
 
-{% assign num_posts = 5 %}
-{% for post in site.posts %}
-    {% assign num_posts = num_posts | minus: 1 %}
-    {% if num_posts >= 0 %}
-        <header class="subtitle">
-            {% include post-header.html item=post %}
-            <h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
-        </header>
-        {{ post.excerpt }}
-
-        <p><a href="{{ post.url }}">Read more...</a></p>
-    {% endif %}
-{% endfor %}
+{% include post-list.html posts=site.posts %}