diff options
| author | davidtsadler <davidtsadler@googlemail.com> | 2012-01-14 19:25:54 +0000 |
|---|---|---|
| committer | davidtsadler <davidtsadler@googlemail.com> | 2012-01-14 19:25:54 +0000 |
| commit | d9e379d1e7d3e3f802d74bb15ded562ab13354e3 (patch) | |
| tree | daedd0cc2b2f69abb4e0c23a9b80d21f466df2a5 /_site_build | |
| parent | bee356476f2932f69b05c0b1d8decd0e1843ff6b (diff) | |
Add categories for posts.
Diffstat (limited to '_site_build')
| -rw-r--r-- | _site_build/_includes/post_excerpt.html | 3 | ||||
| -rw-r--r-- | _site_build/_layouts/category_index.html | 10 | ||||
| -rw-r--r-- | _site_build/_layouts/post.html | 3 | ||||
| -rw-r--r-- | _site_build/_plugins/category_indexes.rb | 63 | ||||
| -rw-r--r-- | _site_build/css/style.css | 30 | ||||
| -rw-r--r-- | _site_build/index.html | 2 |
6 files changed, 92 insertions, 19 deletions
diff --git a/_site_build/_includes/post_excerpt.html b/_site_build/_includes/post_excerpt.html index 461cb55..48e4a1e 100644 --- a/_site_build/_includes/post_excerpt.html +++ b/_site_build/_includes/post_excerpt.html @@ -2,6 +2,9 @@ <header> <h1><a href="{{ post.url }}" rel="bookmark" target="_self" title="{{ post.title }}">{{ post.title }}</a></h1> <time datetime="{{ post.date | date: '%Y-%m-%d' }}" pubdate>{{ post.date | date: '%A' }} {{ post.date | ordinalize }} {{ post.date | date: '%B, %Y' }}</time> + {% if post.categories.size != 0 %} + <div class="categories">Posted in {{ post.categories | category_links }}</div> + {% endif %} </header> {{ post.content | truncate }} </article> diff --git a/_site_build/_layouts/category_index.html b/_site_build/_layouts/category_index.html new file mode 100644 index 0000000..729ff2e --- /dev/null +++ b/_site_build/_layouts/category_index.html @@ -0,0 +1,10 @@ +--- +layout: default +robots: follow, noindex, noodp, noydir, noarchive +--- +<section id="category"> + <h1>{{ page.title }}</h1> + {% for post in site.categories[page.category] %} + {% include post_excerpt.html %} + {% endfor %} +</section> diff --git a/_site_build/_layouts/post.html b/_site_build/_layouts/post.html index e45ca24..61f0d09 100644 --- a/_site_build/_layouts/post.html +++ b/_site_build/_layouts/post.html @@ -5,6 +5,9 @@ layout: default <header> <h1>{{ page.title }}</h1> <time datetime="{{ page.date | date: '%Y-%m-%d' }}" pubdate>{{ page.date | date: '%A' }} {{ page.date | ordinalize }} {{ page.date | date: '%B, %Y' }}</time> + {% if page.categories.size != 0 %} + <div class="categories">Posted in {{ page.categories | category_links }}</div> + {% endif %} </header> {{ content }} <footer> diff --git a/_site_build/_plugins/category_indexes.rb b/_site_build/_plugins/category_indexes.rb new file mode 100644 index 0000000..10dae02 --- /dev/null +++ b/_site_build/_plugins/category_indexes.rb @@ -0,0 +1,63 @@ +module Jekyll + # Monkey patch so that both GenerateCategoryIndexes and CategoryFilter have access to this method. + class Site + # A very simple implementation. + def parameterize(string, sep = '-') + string.downcase.gsub(/[^a-z0-9\-_]+/, sep) + end + end + + class CategoryIndex < Page + def initialize(site, base, dir, category) + @site = site + @base = base + @dir = dir + @name = 'index.html' + + self.process(@name) + self.read_yaml(File.join(base, '_layouts'), 'category_index.html') + self.data['category'] = category + + title_prefix = site.config['category_title_prefix'] || 'Category: ' + self.data['title'] = "#{title_prefix}#{category}" + + description_prefix = site.config['category_meta_description_prefix'] || 'Category: ' + self.data['description'] = "#{description_prefix}#{category}" + end + end + + class GenerateCategoryIndexes < Generator + safe true + priority :low + + def generate(site) + if site.config['generate_category_indexes'] && site.layouts.key?('category_index') + dir = site.config['category_dir'] || 'categories' + site.categories.keys.each do |category| + write_category_index(site, File.join("/#{dir}", site.parameterize(category)), category) + end + end + end + + def write_category_index(site, dir, category) + index = CategoryIndex.new(site, site.source, dir, category) + index.render(site.layouts, site.site_payload) + index.write(site.dest) + site.pages << index + end + end + + module CategoryFilter + def category_links(categories) + site = @context.registers[:site] + directory = site.config['category_dir'] || 'categories' + categories = categories.sort.map do |item| + '<a href="/' + directory + '/' + site.parameterize(item) + '/" rel="category tag" target="_self" title="View all posted in ' + item +'">' + item + '</a>' + end + categories.join(', ') + end + end + +end + +Liquid::Template.register_filter(Jekyll::CategoryFilter) diff --git a/_site_build/css/style.css b/_site_build/css/style.css index 1c85690..af0f67a 100644 --- a/_site_build/css/style.css +++ b/_site_build/css/style.css @@ -159,10 +159,14 @@ h1, h2, h3, h4, h5, h6 { padding: 0; } -article h1, section#about h1, section#archives h1 { +article h1, section#about h1, section#archives h1, section#category > h1 { font-size: 1.461538462em; /* 19 / 13 */ } +section#about h1, section#archives h1, section#category > h1 { + margin-bottom: 1em; +} + article h2, section#about h2, section#archives h2 { font-size: 1.1538461538em; /* 15 / 13 */ } @@ -206,16 +210,20 @@ article h2, section#about h2, section#archives h2 { text-transform: lowercase; } -li.prev-article a, li.next-article a { +article.excerpt { + margin-bottom: 2em; +} + +article li.prev-article a, article li.next-article a { display: block; } -li.prev-article { +article li.prev-article { float: left; width: 50%; } -li.next-article { +article li.next-article { float: right; text-align: right; width: 50%; @@ -230,24 +238,10 @@ article footer nav ul:after { visibility: hidden; } -article.excerpt { - margin-bottom: 2em; -} - -section#archives h1 { - margin-bottom: 1em; -} - section#archives ol { list-style-type: disc; } -section#archives time { - display: inline-block; - width: 4em; -} - - /* ==|== non-semantic helper classes ======================================== */ .ir { display: block; border: 0; text-indent: -999em; overflow: hidden; background-color: transparent; background-repeat: no-repeat; text-align: left; direction: ltr; } .ir br { display: none; } diff --git a/_site_build/index.html b/_site_build/index.html index 7b96318..71a3e34 100644 --- a/_site_build/index.html +++ b/_site_build/index.html @@ -3,7 +3,7 @@ layout: default title: Home robots: follow, noindex, noodp, noydir, noarchive --- -<section id="excerpts"> +<section id="recent-posts"> {% for post in site.posts limit:site.max_recent_posts %} {% include post_excerpt.html %} {% endfor %} |
