blog:
title: "Ralf's Ramblings"
+ category_dir: "/blog/categories"
readmes:
src_base: "/home/r/src"
- scope:
path: "" # all files in the project
values:
- layout: "default"
+ layout: "page"
- scope:
path: ""
type: "posts"
--- /dev/null
+{% 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 %}
-<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>
--- /dev/null
+{% 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 %}
--- /dev/null
+{% assign pretitle = site.blog.title %}
--- /dev/null
+---
+layout: feed
+hide: true
+vars: "blog-category.html"
+---
+
+{% assign posts = site.categories[page.category] %}
+{% include post-feed.html posts=posts %}
--- /dev/null
+---
+layout: page
+hide: true
+rss: true
+vars: "blog-category.html"
+---
+
+{% assign posts = site.categories[page.category] %}
+{% include post-list.html posts=posts %}
--- /dev/null
+<?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>
<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">
--- /dev/null
+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
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
---
-layout: null
+layout: feed
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 %}
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 %}