Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
require 'bundler'
Bundler.require
require 'sinatra/content_for'
$:.unshift("lib")
require "source_file"
require "redirects"
class Blog < Sinatra::Base
helpers Sinatra::ContentFor
helpers do
def title
title = @title ? "#{@title} - " : ""
"#{title}Literate Programming"
end
def formatted_date
@date && Date.parse(@date).strftime("%-d %B %Y")
end
def format_outline(outline)
prev_level = 2
"<ul>" + outline.inject("") do |html, data|
level, link = data
if prev_level < level
html += "<ul>"
elsif prev_level > level
html += "</ul>"
end
prev_level = level
html += "<li>#{link}</li>"
html
end + "</ul>"
end
end
get '/' do
haml :index
end
get '/archive' do
@archives = SourceFile.archive_list
haml :archive
end
get '/atom.xml' do
require "rss"
archives = SourceFile.archive_data
rss = RSS::Maker.make("atom") do |maker|
maker.channel.author = "Steve Klabnik"
maker.channel.updated = SourceFile.last_updated
maker.channel.title = "Literate Programming"
maker.channel.id = "http://blog.steveklabnik.com/"
archives.each do |link, title, updated, summary|
maker.items.new_item do |item|
item.link = link
item.title = title
item.updated = updated
item.summary = summary
end
end
end
rss.to_s
end
get "/posts/?" do
redirect "/archive"
end
get '/posts/:id' do
begin
source = SourceFile.new(params[:id])
@title = source.metadata['title']
@title_hidden = source.metadata['title-hidden']
@content = source.content
@outline = source.outline
@date = source.metadata['date']
haml :post
rescue Errno::ENOENT # we couldn't find the file on disk.
pass
end
end
#lol posterous
REDIRECTS.each do |hsh|
get hsh[:from] do
redirect hsh[:to], 301 #yeah, this move is permanent
end
end
#lol octopress
get '/*' do
post = params[:splat].first.gsub("/", "-").gsub(".html", "")
redirect "posts/" + post, 301
end
end