Created
March 25, 2011 20:18
-
-
Save owengriffin/887565 to your computer and use it in GitHub Desktop.
Gist data source for Nanoc3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compile '/gist/*' do | |
filter :kramdown | |
layout 'kind_gist' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment