Permalink
Browse files

Added tag pages and feeds, stolen from github.com/josegonzalez;

Moved repeated post page nav into an include;
  • Loading branch information...
lmorchard committed Jun 8, 2011
1 parent 5b21ad4 commit a79678828ab612c2edb8a8ac3f796199cb922a2e
@@ -10,6 +10,7 @@ meta:
name: l.m.orchard
email: l.m.orchard@pobox.com

tag_dir: tag
baseurl: /blog
markdown: rdiscount
pygments: true
@@ -2,5 +2,3 @@
<span class="date">{{ post.date | date_to_string }}</span> &raquo;
<a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>
</li>


@@ -0,0 +1,14 @@
<nav class="page-navigation">
<ul>
{% if page.previous.url %}
<li class="left">
<a href="{{ site.baseurl }}{{page.previous.url}}" accesskey="p" title="Previous Post: {{page.previous.title}}">&laquo; {{page.previous.title}}</a>
</li>
{% endif %}
{% if page.next.url %}
<li class="right">
<a href="{{ site.baseurl }}{{page.next.url}}" accesskey="n" title="next Post: {{page.next.title}}">{{page.next.title}} &raquo;</a>
</li>
{% endif %}
</ul>
</nav>
@@ -4,16 +4,26 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>{% if page.title %}{{ page.title }} - {% endif %}{{ site.meta.site_title }}</title>
<meta name="author" content="{{ site.meta.author.fullname }}" />
<link href="/blog/atom.xml" rel="alternate"
title="{{ site.meta.site_title }} (Atom)" type="application/atom+xml" />
<link href="/blog/rss.xml" rel="alternate"
title="{{ site.meta.site_title }} (RSS)" type="application/rss+xml" />

{% if page.tag %}
<link href="{{ site.baseurl }}/tag/{{page.tag | replace:' ', '-' | downcase }}/atom.xml"
rel="alternate" title="{{ page.title }} - {{ site.meta.site_title }} (Atom)"
type="application/atom+xml" />
{% else %}
<link href="/blog/atom.xml" rel="alternate"
title="{{ site.meta.site_title }} (Atom)" type="application/atom+xml" />
<link href="/blog/rss.xml" rel="alternate"
title="{{ site.meta.site_title }} (RSS)" type="application/rss+xml" />
{% endif %}

<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Homepage CSS -->

<link rel="stylesheet" href="/blog/css/screen.css"
type="text/css" media="screen, projection" />

</head>
<body>

@@ -1,41 +1,21 @@
---
layout: default
---
<nav class="page-navigation">
<ul>
{% if page.previous.url %}
<li class="left">
<a href="{{ site.baseurl }}{{page.previous.url}}" accesskey="p" title="Previous Post: {{page.previous.title}}">&laquo; {{page.previous.title}}</a>
</li>
{% endif %}
{% if page.next.url %}
<li class="right">
<a href="{{ site.baseurl }}{{page.next.url}}" accesskey="n" title="next Post: {{page.next.title}}">{{page.next.title}} &raquo;</a>
</li>
{% endif %}
</ul>
</nav>

{% include post-page-nav.html %}

<article class="post">
<h2 class="title">{{ page.title }}</h2>
<time title="{{ page.date | date_to_xmlschema }}" pubdate="{{ page.date | date_to_xmlschema }}">{{ page.date | date: '%B %d, %Y - %I:%M %p %Z' }}</time>
<ul class="tags">
{% for tag in page.tags %}
<li><a href="{{ site.baseurl }}/tag/{{tag | replace:' ', '-' | downcase }}">{{ tag }}</a>{% if forloop.last == false %}, {%endif %}</li>
{% endfor %}
</ul>
{{ content }}
</article>

<nav class="page-navigation">
<ul>
{% if page.previous.url %}
<li class="left">
<a href="{{ site.baseurl }}{{page.previous.url}}" title="Previous Post: {{page.previous.title}}">&laquo; {{page.previous.title}}</a>
</li>
{% endif %}
{% if page.next.url %}
<li class="right">
<a href="{{ site.baseurl }}{{page.next.url}}" title="next Post: {{page.next.title}}">{{page.next.title}} &raquo;</a>
</li>
{% endif %}
</ul>
</nav>
{% include post-page-nav.html %}

<section class="comments">
<div id="disqus_thread"></div>
@@ -0,0 +1,26 @@
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{{ site.meta.site_title }} - {{ page.title }}</title>
<link href="{{ site.meta.absolute_baseurl }}/atom.xml" rel="self"/>
<link href="{{ site.meta.absolute_baseurl }}"/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
<id>{{ site.meta.base_url }}</id>
<author>
<name>{{ site.meta.author.fullname }}</name>
<email>{{ site.meta.author.email }}</email>
</author>
{% for post in site.tags[page.tag] limit:15 %}

<entry>
<title>{{ post.title }}</title>
<link href="{{ site.meta.absolute_baseurl }}{{ post.url }}"/>
<updated>{{ post.date | date_to_xmlschema }}</updated>
<id>{{ site.meta.absolute_baseurl }}{{ post.id }}</id>
<content type="html">{{ post.content | markdownify | xml_escape }}</content>
</entry>

{% endfor %}
</feed>
@@ -0,0 +1,11 @@
---
layout: default
---
<article id="index">
<h2>{{ page.title }}</h2>
<ul class="posts">
{% for post in site.tags[page.tag] %}
{% include item.html %}
{% endfor %}
</ul>
</article>
@@ -0,0 +1,14 @@
---
layout: default
title: Tags
lead: These tags are for quick browsing, not for anything else
---

{% for tag in page.tags %}
<h4><a href="/tags/{{ tag | replace:' ', '-' | downcase }}" name="{{ tag | replace:' ','-' | downcase }}">{{ tag }}</a></h4>
<ul>
{% for post in site.tags[tag] %}
<li><a href="{{post.url}}">{{ post.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
@@ -0,0 +1,71 @@
require 'hpricot'
require 'nokogiri'
require 'rdiscount'

module Liquid

module ExtendedFilters

def date_to_month(input)
Date::MONTHNAMES[input]
end

def date_to_month_abbr(input)
Date::ABBR_MONTHNAMES[input]
end

def date_to_utc(input)
input.getutc
end

def html_truncatewords(text, max_length = 200, ellipsis = "")
ellipsis_length = ellipsis.length
doc = Nokogiri::HTML::DocumentFragment.parse text
content_length = doc.inner_text.length
actual_length = max_length - ellipsis_length
content_length > actual_length ? doc.truncate(actual_length).inner_html + ellipsis : text.to_s
end

def preview(text, delimiter = '<!-- end_preview -->')
if text.index(delimiter) != nil
text.split(delimiter)[0]
else
html_truncatewords(text)
end
end

def markdownify(input)
RDiscount.new(input).to_html
end

end

module NokogiriTruncator
module NodeWithChildren
def truncate(max_length)
return self if inner_text.length <= max_length
truncated_node = self.dup
truncated_node.children.remove

self.children.each do |node|
remaining_length = max_length - truncated_node.inner_text.length
break if remaining_length <= 0
truncated_node.add_child node.truncate(remaining_length)
end
truncated_node
end
end

module TextNode
def truncate(max_length)
Nokogiri::XML::Text.new(content[0..(max_length - 1)], parent)
end
end

end
Nokogiri::HTML::DocumentFragment.send(:include, NokogiriTruncator::NodeWithChildren)
Nokogiri::XML::Element.send(:include, NokogiriTruncator::NodeWithChildren)
Nokogiri::XML::Text.send(:include, NokogiriTruncator::TextNode)

Liquid::Template.register_filter(ExtendedFilters)
end
@@ -0,0 +1,100 @@
module Jekyll

class TagIndex < Page
def initialize(site, base, dir, tag)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
self.data['tag'] = tag

self.data['related'] = []
site.tags[tag].each do |post|
post.tags.each do |rel|
self.data['related'].push(rel)
end
end
self.data['related'] = self.data['related'].uniq

tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
self.data['title'] = "#{tag_title_prefix}#{tag}"
end
end

class TagFeed < Page
def initialize(site, base, dir, tag)
@site = site
@base = base
@dir = dir
@name = 'atom.xml'

self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'tag_feed.xml')
self.data['tag'] = tag
tag_title_prefix = site.config['tag_title_prefix'] || 'Tag: '
self.data['title'] = "#{tag_title_prefix}#{tag}"
end
end

class TagList < Page
def initialize(site, base, dir, tags)
@site = site
@base = base
@dir = dir
@name = 'index.html'

self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'tag_list.html')
self.data['tags'] = tags
end
end

class TagGenerator < Generator
safe true

def generate(site)
if site.layouts.key? 'tag_index'
dir = site.config['tag_dir'] || 'tags'
site.tags.keys.each do |tag|
write_tag_index(site, File.join(dir, tag.gsub(/\s/, "-").gsub(/[^\w-]/, '').downcase), tag)
end
end

if site.layouts.key? 'tag_feed'
dir = site.config['tag_dir'] || 'tags'
site.tags.keys.each do |tag|
write_tag_feed(site, File.join(dir, tag.gsub(/\s/, "-").gsub(/[^\w-]/, '').downcase), tag)
end
end

if site.layouts.key? 'tag_list'
dir = site.config['tag_dir'] || 'tags'
write_tag_list(site, dir, site.tags.keys.sort)
end
end

def write_tag_index(site, dir, tag)
index = TagIndex.new(site, site.source, dir, tag)
index.render(site.layouts, site.site_payload)
index.write(site.dest)
site.static_files << index
end

def write_tag_feed(site, dir, tag)
index = TagFeed.new(site, site.source, dir, tag)
index.render(site.layouts, site.site_payload)
index.write(site.dest)
site.static_files << index
end

def write_tag_list(site, dir, tags)
index = TagList.new(site, site.source, dir, tags)
index.render(site.layouts, site.site_payload)
index.write(site.dest)
site.static_files << index
end
end

end
@@ -1,6 +1,7 @@
---
layout: post
title: Moved to Jekyll and Disqus
tags: [ metablogging, jekyll, disqus, webdev, hosting ]
---
**TL;DR**: <em>My blog is now produced by [Jekyll][], with comments hosted by [Disqus][].</em>

@@ -155,6 +155,23 @@ section.content > article > pre {
padding: 1em 1em;
}

article.post > time {
display: block;
}

section.content article ul.tags:before {
content: "Tags: ";
}
section.content article ul.tags {
display: block;
margin: 0.25em 0 0.25em 0;
font-size: 0.85em;
}
section.content article ul.tags li {
list-style: none;
display: inline;
}

section.comments {
padding: 1.5em 2em;
background-color: #f8f8f8;
Oops, something went wrong.

0 comments on commit a796788

Please sign in to comment.