blog feature
This commit is contained in:
parent
9849e2aa2f
commit
746ddcc519
|
@ -74,6 +74,9 @@ module Middleman::Features
|
|||
# Parse YAML metadata from templates
|
||||
autoload :FrontMatter, "middleman/features/front_matter"
|
||||
|
||||
# Treat project as a blog
|
||||
autoload :Blog, "middleman/features/blog"
|
||||
|
||||
# Proxy web services requests in dev mode only
|
||||
# autoload :Proxy, "middleman/features/proxy"
|
||||
|
||||
|
|
87
lib/middleman/features/blog.rb
Normal file
87
lib/middleman/features/blog.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
module Middleman
|
||||
module Features
|
||||
module Blog
|
||||
class << self
|
||||
def registered(app)
|
||||
# Depend on FrontMatter
|
||||
app.activate Middleman::Features::FrontMatter
|
||||
|
||||
# Include helpers
|
||||
app.helpers Middleman::Features::Blog::Helpers
|
||||
|
||||
app.after_feature_init do
|
||||
if !app.settings.respond_to? :blog_permalink
|
||||
app.set :blog_permalink, "/:year/:month/:day/:title.html"
|
||||
end
|
||||
|
||||
if !app.settings.respond_to? :blog_layout
|
||||
app.set :blog_layout, "layout"
|
||||
end
|
||||
|
||||
if !app.settings.respond_to? :blog_summary_separator
|
||||
app.set :blog_summary_separator, "READMORE"
|
||||
end
|
||||
|
||||
if !app.settings.respond_to? :blog_layout_engine
|
||||
app.set :blog_layout_engine, "erb"
|
||||
end
|
||||
|
||||
if !app.settings.respond_to? :blog_article_template
|
||||
app.set :blog_article_template, "article_template"
|
||||
end
|
||||
|
||||
$stderr.puts "== Blog: #{app.settings.blog_permalink}"
|
||||
app.get(app.settings.blog_permalink) do
|
||||
options = {}
|
||||
options[:layout] = settings.blog_layout
|
||||
options[:layout_engine] = settings.blog_layout_engine
|
||||
|
||||
extensionless_path, template_engine = resolve_template(request.path)
|
||||
|
||||
full_file_path = "#{extensionless_path}.#{template_engine}"
|
||||
system_path = File.join(settings.views, full_file_path)
|
||||
data, content = self.class.parse_front_matter(File.read(system_path))
|
||||
|
||||
# Forward remaining data to helpers
|
||||
self.class.data_content("page", data)
|
||||
|
||||
output = render(request.path, options)
|
||||
|
||||
# No need for separator on permalink page
|
||||
output.gsub!(settings.blog_summary_separator, "")
|
||||
|
||||
status 200
|
||||
output
|
||||
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
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module Helpers
|
||||
def blog_title
|
||||
end
|
||||
|
||||
def current_article_date
|
||||
DateTime.parse(current_article_metadata.date)
|
||||
end
|
||||
|
||||
def current_article_title
|
||||
current_article_metadata.title
|
||||
end
|
||||
|
||||
def current_article_metadata
|
||||
data.page
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,6 +5,13 @@ module Middleman::Features::FrontMatter
|
|||
class << self
|
||||
def registered(app)
|
||||
app.extend ClassMethods
|
||||
|
||||
::Tilt::register MarukuTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register KramdownTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register BlueClothTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
|
||||
::Tilt::register RedClothTemplate, 'textile'
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
@ -26,13 +33,37 @@ module Middleman::Features::FrontMatter
|
|||
[data, content]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# class FrontMatter < Tilt::RDiscountTemplate
|
||||
# def prepare
|
||||
# options, @data = Middleman::Server.parse_front_matter(@data)
|
||||
# super
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Tilt.register 'markdown', FrontMatter
|
||||
module YamlAware
|
||||
def prepare
|
||||
options, @data = Middleman::Server.parse_front_matter(@data)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# MARKDOWN
|
||||
class MarukuTemplate < ::Tilt::MarukuTemplate
|
||||
include Middleman::Features::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
class KramdownTemplate < ::Tilt::KramdownTemplate
|
||||
include Middleman::Features::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
class BlueClothTemplate < ::Tilt::BlueClothTemplate
|
||||
include Middleman::Features::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate
|
||||
include Middleman::Features::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
class RDiscountTemplate < ::Tilt::RDiscountTemplate
|
||||
include Middleman::Features::FrontMatter::YamlAware
|
||||
end
|
||||
|
||||
# TEXTILE
|
||||
class RedClothTemplate < ::Tilt::RedClothTemplate
|
||||
include Middleman::Features::FrontMatter::YamlAware
|
||||
end
|
||||
end
|
|
@ -40,9 +40,6 @@ module Middleman
|
|||
# Activate custom features
|
||||
register Middleman::Features
|
||||
|
||||
# Activate Yaml Front Matter
|
||||
register Middleman::Features::FrontMatter
|
||||
|
||||
# Activate built-in helpers
|
||||
register Middleman::Features::DefaultHelpers
|
||||
|
||||
|
@ -156,7 +153,6 @@ module Middleman
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
full_file_path = "#{extensionless_path}.#{template_engine}"
|
||||
system_path = File.join(settings.views, full_file_path)
|
||||
data, content = self.class.parse_front_matter(File.read(system_path))
|
||||
|
|
Loading…
Reference in a new issue