Skip to content

Instantly share code, notes, and snippets.

@owengriffin
Created March 25, 2011 20:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save owengriffin/887565 to your computer and use it in GitHub Desktop.
Save owengriffin/887565 to your computer and use it in GitHub Desktop.
Gist data source for Nanoc3
data_sources:
-
# The type is the identifier of the data source. By default, this will be
# `filesystem_unified`.
type: filesystem_unified
# The path where items should be mounted (comparable to mount points in
# Unix-like systems). This is “/” by default, meaning that items will have
# “/” prefixed to their identifiers. If the items root were “/en/”
# instead, an item at content/about.html would have an identifier of
# “/en/about/” instead of just “/about/”.
items_root: /
# The path where layouts should be mounted. The layouts root behaves the
# same as the items root, but applies to layouts rather than items.
layouts_root: /
-
type: gist
config:
username: 'owengriffin'
require "httparty"
class Gist
include HTTParty
base_uri 'http://gist.github.com/'
def list(username)
self.class.get('/api/v1/json/gists/' + username)['gists']
end
def contents(id, filename)
self.class.get('/raw/' + id + '/' + filename)
end
end
def gists
@items.select { |item| item[:kind] == 'gist' }
end
class GistDataSource < Nanoc3::DataSource
identifier :gist
def items
items = []
api = Gist.new
api.list(self.config[:username]).each do |gist|
attributes = {
:url => 'http://gist.github.com/' + gist['repo'],
:title => 'Gist #' + gist['repo'] + ': ' + gist['description'],
:author => gist['owner'],
:created_at => gist['created_at'],
:kind => 'gist'
}
items << Nanoc3::Item.new(gist['description'], attributes, '/gist/' + gist['repo'])
end
items
end
end
!!! 5
%html
%head
%meta{:"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8"}/
%link(rel="stylesheet" href="/stylesheets/owengriffin.css" media="screen")/
%title
Owen Griffin -
= @item[:title]
%body
#page
= render 'header'
= render 'sidebar'
#content.gist
%h2.title
= item[:title]
.content
%script(src="https://gist.github.com/#{item.identifier.match(/\/([0-9]+)/)[1]}.js")
#footer
compile '/gist/*' do
filter :kramdown
layout 'kind_gist'
end
%h2 Gists
%ul.gists
- gists.each do |gist|
%li.gist
%a(href="#{gist.path}")= gist[:title]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment