working implementation, dogfooding on my own blog

This commit is contained in:
Thomas Reynolds 2011-06-08 20:53:46 -07:00
parent 746ddcc519
commit 6c5d75aca9
2 changed files with 43 additions and 8 deletions

View file

@ -1,3 +1,5 @@
require "rdiscount"
module Middleman module Middleman
module Features module Features
module Blog module Blog
@ -19,18 +21,53 @@ module Middleman
end end
if !app.settings.respond_to? :blog_summary_separator if !app.settings.respond_to? :blog_summary_separator
app.set :blog_summary_separator, "READMORE" app.set :blog_summary_separator, /READMORE/
end
if !app.settings.respond_to? :blog_summary_length
app.set :blog_summary_length, 250
end end
if !app.settings.respond_to? :blog_layout_engine if !app.settings.respond_to? :blog_layout_engine
app.set :blog_layout_engine, "erb" app.set :blog_layout_engine, "erb"
end end
if !app.settings.respond_to? :blog_index_template
app.set :blog_index_template, "index_template"
end
if !app.settings.respond_to? :blog_article_template if !app.settings.respond_to? :blog_article_template
app.set :blog_article_template, "article_template" app.set :blog_article_template, "article_template"
end end
$stderr.puts "== Blog: #{app.settings.blog_permalink}" $stderr.puts "== Blog: #{app.settings.blog_permalink}"
articles_glob = File.join(app.views, app.settings.blog_permalink.gsub(/(:\w+)/, "*") + ".*")
articles = Dir[articles_glob].map do |article|
template_content = File.read(article)
data, content = parse_front_matter(template_content)
data["date"] = Date.parse(data["date"])
yaml_regex = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
data["raw"] = template_content.split(yaml_regex).last
data["url"] = article.gsub(app.views, "").split(".html").first + ".html"
all_content = Tilt.new(article).render
data["body"] = all_content.gsub!(app.settings.blog_summary_separator, "")
sum = if data["raw"] =~ app.settings.blog_summary_separator
data["raw"].split(app.settings.blog_summary_separator).first
else data["raw"].match(/(.{1,#{app.settings.blog_summary_length}}.*?)(\n|\Z)/m).to_s
end
engine = RDiscount.new(sum)
data["summary"] = engine.to_html
data
end.sort { |a, b| b["date"] <=> a["date"] }
app.data_content("blog", { :articles => articles })
app.get(app.settings.blog_permalink) do app.get(app.settings.blog_permalink) do
options = {} options = {}
options[:layout] = settings.blog_layout options[:layout] = settings.blog_layout
@ -55,18 +92,15 @@ module Middleman
end end
end end
# Handle /archives/
require "middleman/builder"
Middleman::Builder.after_run "blog_archives" do
# source_paths << File.expand_path(File.join(File.dirname(__FILE__), "middleman-slickmap", "templates"))
# tilt_template "slickmap.html.haml", File.join(Middleman::Server.build_dir, sitemap_url), { :force => true }
end
end end
alias :included :registered alias :included :registered
end end
module Helpers module Helpers
def is_blog_article?
!current_article_title.blank?
end
def blog_title def blog_title
end end

View file

@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("shotgun", ["~> 0.8.0"]) s.add_runtime_dependency("shotgun", ["~> 0.8.0"])
s.add_runtime_dependency("thor", ["~> 0.14.0"]) s.add_runtime_dependency("thor", ["~> 0.14.0"])
s.add_runtime_dependency("tilt", ["~> 1.3.1"]) s.add_runtime_dependency("tilt", ["~> 1.3.1"])
s.add_runtime_dependency("rdiscount", ["~> 1.6.8"])
s.add_runtime_dependency("sinatra", ["~> 1.2.0"]) s.add_runtime_dependency("sinatra", ["~> 1.2.0"])
s.add_runtime_dependency("padrino-core", ["~> 0.9.23"]) s.add_runtime_dependency("padrino-core", ["~> 0.9.23"])
s.add_runtime_dependency("padrino-helpers", ["~> 0.9.23"]) s.add_runtime_dependency("padrino-helpers", ["~> 0.9.23"])