middleman-blog 0.1.5 → 3.0.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +5 -0
- data/.travis.yml +9 -0
- data/.yardopts +3 -0
- data/Gemfile +19 -0
- data/LICENSE +20 -0
- data/README.md +62 -0
- data/Rakefile +15 -0
- data/features/article_cli.feature +7 -0
- data/features/blog_sources.feature +9 -0
- data/features/calendar.feature +30 -0
- data/features/directory_indexes.feature +6 -0
- data/features/encoding.feature +0 -0
- data/features/filename_date.feature +9 -0
- data/features/next_previous.feature +8 -0
- data/features/preview.feature +29 -0
- data/features/support/env.rb +4 -0
- data/features/tags.feature +50 -0
- data/fixtures/blog-sources-app/config.rb +3 -0
- data/fixtures/blog-sources-app/source/_article_template.erb +1 -0
- data/fixtures/blog-sources-app/source/blog/2011-01-01-new-article.html.markdown +6 -0
- data/fixtures/blog-sources-app/source/index.html.erb +9 -0
- data/fixtures/blog-sources-app/source/layout.erb +13 -0
- data/fixtures/calendar-app/config.rb +5 -0
- data/fixtures/calendar-app/source/blog/2011-01-01-new-article.html.markdown +7 -0
- data/fixtures/calendar-app/source/blog/2011-01-02-another-article.html.markdown +8 -0
- data/fixtures/calendar-app/source/calendar.html.erb +13 -0
- data/fixtures/calendar-app/source/index.html.erb +3 -0
- data/fixtures/calendar-app/source/layout.erb +15 -0
- data/fixtures/filename-date-app/config.rb +1 -0
- data/fixtures/filename-date-app/source/2011-01-01-new-article.html.markdown +5 -0
- data/fixtures/filename-date-app/source/2011-01-03-filename-and-frontmatter.html.markdown +6 -0
- data/fixtures/filename-date-app/source/layout.erb +14 -0
- data/fixtures/indexes-app/config.rb +5 -0
- data/fixtures/indexes-app/source/2011/01/01/new-article.html.markdown +6 -0
- data/fixtures/indexes-app/source/_article_template.erb +1 -0
- data/fixtures/indexes-app/source/index.html.erb +9 -0
- data/fixtures/indexes-app/source/layout.erb +13 -0
- data/fixtures/preview-app/config.rb +3 -0
- data/fixtures/preview-app/source/2011/01/01/new-article.html.markdown +6 -0
- data/fixtures/preview-app/source/_article_template.erb +10 -0
- data/fixtures/preview-app/source/index.html.erb +9 -0
- data/fixtures/preview-app/source/layout.erb +22 -0
- data/fixtures/tags-app/config.rb +6 -0
- data/fixtures/tags-app/source/blog/2011-01-01-new-article.html.markdown +7 -0
- data/fixtures/tags-app/source/blog/2011-01-02-another-article.html.markdown +8 -0
- data/fixtures/tags-app/source/index.html.erb +3 -0
- data/fixtures/tags-app/source/layout.erb +13 -0
- data/fixtures/tags-app/source/tag.html.erb +7 -0
- data/fixtures/utf8ouch/config.rb +17 -0
- data/fixtures/utf8ouch/source/2010/11/13/telling-time.html.markdown +73 -0
- data/fixtures/utf8ouch/source/2011/01/01/new-article.html.markdown +6 -0
- data/{lib/middleman-blog/template → fixtures/utf8ouch}/source/_article_template.erb +0 -0
- data/{lib/middleman-blog/template → fixtures/utf8ouch}/source/archives/index.html.erb +0 -0
- data/fixtures/utf8ouch/source/feed.xml.builder +23 -0
- data/fixtures/utf8ouch/source/index.html.erb +9 -0
- data/fixtures/utf8ouch/source/layout.erb +30 -0
- data/lib/middleman-blog.rb +10 -2
- data/lib/middleman-blog/blog_article.rb +123 -0
- data/lib/middleman-blog/blog_data.rb +94 -0
- data/lib/middleman-blog/calendar_pages.rb +85 -0
- data/lib/middleman-blog/commands/article.rb +52 -0
- data/lib/middleman-blog/commands/article.tt +6 -0
- data/lib/middleman-blog/extension.rb +170 -0
- data/lib/middleman-blog/tag_pages.rb +33 -0
- data/lib/middleman-blog/template.rb +19 -8
- data/lib/middleman-blog/template/config.tt +101 -5
- data/lib/middleman-blog/template/shared/Gemfile.tt +4 -0
- data/lib/middleman-blog/template/source/2012-01-01-example-article.html.markdown +7 -0
- data/lib/middleman-blog/template/source/calendar.html.erb +15 -0
- data/lib/middleman-blog/template/source/feed.xml.builder +2 -2
- data/lib/middleman-blog/template/source/index.html.erb +8 -9
- data/lib/middleman-blog/template/source/layout.erb +18 -12
- data/lib/middleman-blog/template/source/tag.html.erb +7 -0
- data/lib/middleman-blog/version.rb +1 -1
- data/lib/{middleman_init.rb → middleman_extension.rb} +0 -0
- data/middleman-blog.gemspec +1 -2
- metadata +110 -63
- data/lib/middleman-blog/feature.rb +0 -162
- data/lib/middleman-blog/template/config.ru +0 -9
- data/lib/middleman-blog/template/source/2011/01/01/new-article.html.markdown +0 -6
@@ -1,162 +0,0 @@
|
|
1
|
-
module Middleman
|
2
|
-
module Features
|
3
|
-
module Blog
|
4
|
-
class << self
|
5
|
-
def registered(app)
|
6
|
-
# Include helpers
|
7
|
-
app.helpers Middleman::Features::Blog::Helpers
|
8
|
-
|
9
|
-
app.after_configuration do
|
10
|
-
if !app.settings.respond_to? :blog_permalink
|
11
|
-
app.set :blog_permalink, ":year/:month/:day/:title.html"
|
12
|
-
end
|
13
|
-
|
14
|
-
if !app.settings.respond_to? :blog_taglink
|
15
|
-
app.set :blog_taglink, "tags/:tag.html"
|
16
|
-
end
|
17
|
-
|
18
|
-
if !app.settings.respond_to? :blog_layout
|
19
|
-
app.set :blog_layout, "layout"
|
20
|
-
end
|
21
|
-
|
22
|
-
if !app.settings.respond_to? :blog_summary_separator
|
23
|
-
app.set :blog_summary_separator, /READMORE/
|
24
|
-
end
|
25
|
-
|
26
|
-
if !app.settings.respond_to? :blog_summary_length
|
27
|
-
app.set :blog_summary_length, 250
|
28
|
-
end
|
29
|
-
|
30
|
-
if !app.settings.respond_to? :blog_layout_engine
|
31
|
-
app.set :blog_layout_engine, "erb"
|
32
|
-
end
|
33
|
-
|
34
|
-
if !app.settings.respond_to? :blog_index_template
|
35
|
-
app.set :blog_index_template, "index_template"
|
36
|
-
end
|
37
|
-
|
38
|
-
if !app.settings.respond_to? :blog_article_template
|
39
|
-
app.set :blog_article_template, "article_template"
|
40
|
-
end
|
41
|
-
|
42
|
-
if !app.build?
|
43
|
-
$stderr.puts "== Blog: #{app.settings.blog_permalink}"
|
44
|
-
end
|
45
|
-
|
46
|
-
app.get("/#{app.blog_permalink}") do
|
47
|
-
process_request({
|
48
|
-
:layout => app.blog_layout,
|
49
|
-
:layout_engine => app.blog_layout_engine
|
50
|
-
})
|
51
|
-
|
52
|
-
current_body = body
|
53
|
-
current_body = current_body.first if current_body.class == Array
|
54
|
-
# No need for separator on permalink page
|
55
|
-
body current_body.gsub(app.blog_summary_separator, "")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
app.before_processing do
|
60
|
-
articles_glob = File.join(app.views, app.settings.blog_permalink.gsub(/(:\w+)/, "*") + ".*")
|
61
|
-
|
62
|
-
articles = Dir[articles_glob].map do |article|
|
63
|
-
template_content = File.read(article)
|
64
|
-
data, content = app.parse_front_matter(template_content)
|
65
|
-
data["date"] = Date.parse("#{data['date']}")
|
66
|
-
|
67
|
-
data["raw"] = content
|
68
|
-
data["url"] = article.gsub(app.views, "").split(".html").first + ".html"
|
69
|
-
|
70
|
-
all_content = Tilt.new(article).render
|
71
|
-
data["body"] = all_content.gsub(app.settings.blog_summary_separator, "")
|
72
|
-
|
73
|
-
sum = if data["raw"] =~ app.settings.blog_summary_separator
|
74
|
-
data["raw"].split(app.settings.blog_summary_separator).first
|
75
|
-
else
|
76
|
-
data["raw"].match(/(.{1,#{app.settings.blog_summary_length}}.*?)(\n|\Z)/m).to_s
|
77
|
-
end
|
78
|
-
|
79
|
-
engine = app.settings.markdown_engine
|
80
|
-
if engine.is_a? Symbol
|
81
|
-
engine = app.tilt_template_from_symbol(engine)
|
82
|
-
end
|
83
|
-
|
84
|
-
engine = engine.new { sum }
|
85
|
-
data["summary"] = engine.render
|
86
|
-
data
|
87
|
-
end.sort { |a, b| b["date"] <=> a["date"] }
|
88
|
-
|
89
|
-
tags = {}
|
90
|
-
articles.each do |article|
|
91
|
-
article["tags"] ||= ""
|
92
|
-
if !article["tags"].empty?
|
93
|
-
tags_array = article["tags"].split(',').map{|t| t.strip}
|
94
|
-
tags_array.each do |tag_title|
|
95
|
-
tag_key = tag_title.parameterize
|
96
|
-
tag_path = settings.blog_taglink.gsub(/(:\w+)/, tag_key)
|
97
|
-
(tags[tag_path] ||= {})["title"] = tag_title
|
98
|
-
tags[tag_path]["ident"] = tag_key
|
99
|
-
(tags[tag_path]["pages"] ||= {})[article["title"]] = article["url"]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
app.data_content("blog", { :articles => articles, :tags => tags })
|
105
|
-
true
|
106
|
-
end
|
107
|
-
end
|
108
|
-
alias :included :registered
|
109
|
-
end
|
110
|
-
|
111
|
-
module Helpers
|
112
|
-
def is_blog_article?
|
113
|
-
!current_article_title.blank?
|
114
|
-
end
|
115
|
-
|
116
|
-
def blog_title
|
117
|
-
end
|
118
|
-
|
119
|
-
def current_article_date
|
120
|
-
DateTime.parse("#{current_article_metadata.date}")
|
121
|
-
end
|
122
|
-
|
123
|
-
def current_article_title
|
124
|
-
current_article_metadata.title
|
125
|
-
end
|
126
|
-
|
127
|
-
def current_article_metadata
|
128
|
-
data.page
|
129
|
-
end
|
130
|
-
|
131
|
-
def current_article_tags
|
132
|
-
article_tags_hash = {}
|
133
|
-
if is_blog_article? && current_article_metadata.tags
|
134
|
-
article_tags = current_article_metadata.tags.split(',').map{|t| t.strip}
|
135
|
-
article_tags.each do |tag_title|
|
136
|
-
article_tags_hash[tag_title] = self.class.blog_taglink.gsub(/(:\w+)/, tag_title.parameterize)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
article_tags_hash
|
140
|
-
end
|
141
|
-
|
142
|
-
def blog_tags
|
143
|
-
data.blog.tags
|
144
|
-
end
|
145
|
-
|
146
|
-
def current_tag_data
|
147
|
-
data.blog.tags[request.path]
|
148
|
-
end
|
149
|
-
|
150
|
-
def current_tag_articles
|
151
|
-
data.blog.articles.map do |article|
|
152
|
-
article if current_tag_data.pages.has_value?(article.url)
|
153
|
-
end.compact
|
154
|
-
end
|
155
|
-
|
156
|
-
def current_tag_title
|
157
|
-
current_tag_data[:title]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# Rack config
|
2
|
-
|
3
|
-
# Look for index files in folders like Apache
|
4
|
-
require "rack/contrib/try_static"
|
5
|
-
use Rack::TryStatic, :root => "build", :urls => %w[/], :try => ['.html', 'index.html', '/index.html']
|
6
|
-
|
7
|
-
# Cache static assets
|
8
|
-
require "rack/contrib/static_cache"
|
9
|
-
use Rack::StaticCache, :urls => ['/'], :root => 'build'
|