middleman-blog 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/lib/middleman-blog.rb +2 -3
- data/lib/middleman-blog/feature.rb +155 -0
- data/lib/middleman-blog/template.rb +24 -0
- data/lib/middleman-blog/template/config.ru +9 -0
- data/lib/middleman-blog/template/config.tt +18 -0
- data/lib/middleman-blog/template/source/2011/01/01/new-article.html.markdown +6 -0
- data/lib/middleman-blog/template/source/archives/index.html.erb +10 -0
- data/lib/middleman-blog/template/source/feed.xml.builder +23 -0
- data/lib/middleman-blog/template/source/index.html.erb +9 -0
- data/lib/middleman-blog/template/source/layout.erb +30 -0
- data/lib/middleman-blog/version.rb +1 -1
- data/lib/middleman_init.rb +1 -0
- data/middleman-blog.gemspec +7 -7
- metadata +37 -16
- data/.rvmrc +0 -1
- data/README.rdoc +0 -123
- data/lib/middleman-blog/blog_engine.rb +0 -108
- data/lib/middleman-blog/separator.rb +0 -5
- data/lib/middleman-blog/tilt.rb +0 -54
data/.gitignore
CHANGED
data/lib/middleman-blog.rb
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
require "middleman-blog/
|
2
|
-
require "middleman-blog/
|
3
|
-
require "middleman-blog/blog_engine"
|
1
|
+
require "middleman-blog/feature"
|
2
|
+
require "middleman-blog/template"
|
@@ -0,0 +1,155 @@
|
|
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
|
+
# No need for separator on permalink page
|
53
|
+
body body.gsub!(app.blog_summary_separator, "")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
app.before_processing do
|
58
|
+
articles_glob = File.join(app.views, app.settings.blog_permalink.gsub(/(:\w+)/, "*") + ".*")
|
59
|
+
|
60
|
+
articles = Dir[articles_glob].map do |article|
|
61
|
+
template_content = File.read(article)
|
62
|
+
data, content = app.parse_front_matter(template_content)
|
63
|
+
data["date"] = Date.parse(data["date"])
|
64
|
+
|
65
|
+
data["raw"] = content
|
66
|
+
data["url"] = article.gsub(app.views, "").split(".html").first + ".html"
|
67
|
+
|
68
|
+
all_content = Tilt.new(article).render
|
69
|
+
data["body"] = all_content.gsub!(app.settings.blog_summary_separator, "")
|
70
|
+
|
71
|
+
sum = if data["raw"] =~ app.settings.blog_summary_separator
|
72
|
+
data["raw"].split(app.settings.blog_summary_separator).first
|
73
|
+
else
|
74
|
+
data["raw"].match(/(.{1,#{app.settings.blog_summary_length}}.*?)(\n|\Z)/m).to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
engine = app.settings.markdown_engine.new { sum }
|
78
|
+
data["summary"] = engine.render
|
79
|
+
data
|
80
|
+
end.sort { |a, b| b["date"] <=> a["date"] }
|
81
|
+
|
82
|
+
tags = {}
|
83
|
+
articles.each do |article|
|
84
|
+
article["tags"] ||= ""
|
85
|
+
if !article["tags"].empty?
|
86
|
+
tags_array = article["tags"].split(',').map{|t| t.strip}
|
87
|
+
tags_array.each do |tag_title|
|
88
|
+
tag_key = tag_title.parameterize
|
89
|
+
tag_path = blog_taglink.gsub(/(:\w+)/, tag_key)
|
90
|
+
(tags[tag_path] ||= {})["title"] = tag_title
|
91
|
+
tags[tag_path]["ident"] = tag_key
|
92
|
+
(tags[tag_path]["pages"] ||= {})[article["title"]] = article["url"]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
app.data_content("blog", { :articles => articles, :tags => tags })
|
98
|
+
true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
alias :included :registered
|
102
|
+
end
|
103
|
+
|
104
|
+
module Helpers
|
105
|
+
def is_blog_article?
|
106
|
+
!current_article_title.blank?
|
107
|
+
end
|
108
|
+
|
109
|
+
def blog_title
|
110
|
+
end
|
111
|
+
|
112
|
+
def current_article_date
|
113
|
+
DateTime.parse(current_article_metadata.date)
|
114
|
+
end
|
115
|
+
|
116
|
+
def current_article_title
|
117
|
+
current_article_metadata.title
|
118
|
+
end
|
119
|
+
|
120
|
+
def current_article_metadata
|
121
|
+
data.page
|
122
|
+
end
|
123
|
+
|
124
|
+
def current_article_tags
|
125
|
+
article_tags_hash = {}
|
126
|
+
if is_blog_article? && current_article_metadata.tags
|
127
|
+
article_tags = current_article_metadata.tags.split(',').map{|t| t.strip}
|
128
|
+
article_tags.each do |tag_title|
|
129
|
+
article_tags_hash[tag_title] = self.class.blog_taglink.gsub(/(:\w+)/, tag_title.parameterize)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
article_tags_hash
|
133
|
+
end
|
134
|
+
|
135
|
+
def blog_tags
|
136
|
+
data.blog.tags
|
137
|
+
end
|
138
|
+
|
139
|
+
def current_tag_data
|
140
|
+
data.blog.tags[request.path]
|
141
|
+
end
|
142
|
+
|
143
|
+
def current_tag_articles
|
144
|
+
data.blog.articles.map do |article|
|
145
|
+
article if current_tag_data.pages.has_value?(article.url)
|
146
|
+
end.compact
|
147
|
+
end
|
148
|
+
|
149
|
+
def current_tag_title
|
150
|
+
current_tag_data[:title]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Blog
|
3
|
+
class Template < Middleman::Templates::Base
|
4
|
+
def self.source_root
|
5
|
+
File.dirname(__FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
def build_scaffold
|
9
|
+
template "template/config.tt", File.join(location, "config.rb")
|
10
|
+
directory "template/source", File.join(location, "source")
|
11
|
+
|
12
|
+
empty_directory File.join(location, "source", options[:css_dir])
|
13
|
+
empty_directory File.join(location, "source", options[:js_dir])
|
14
|
+
empty_directory File.join(location, "source", options[:images_dir])
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_rack
|
18
|
+
template "template/config.ru", File.join(location, "config.ru")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Middleman::Templates.register(:blog, Middleman::Blog::Template)
|
@@ -0,0 +1,9 @@
|
|
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'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
activate :blog
|
2
|
+
# set :blog_permalink, ":year/:month/:day/:title.html"
|
3
|
+
# set :blog_summary_separator, /READMORE/
|
4
|
+
# set :blog_summary_length, 500
|
5
|
+
|
6
|
+
page "/feed.xml", :layout => false
|
7
|
+
|
8
|
+
# Build-specific configuration
|
9
|
+
configure :build do
|
10
|
+
# For example, change the Compass output style for deployment
|
11
|
+
# activate :minify_css
|
12
|
+
|
13
|
+
# Minify Javascript on build
|
14
|
+
# activate :minify_javascript
|
15
|
+
|
16
|
+
# Enable cache buster
|
17
|
+
# activate :cache_buster
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
xml.instruct!
|
2
|
+
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
|
3
|
+
xml.title "Blog Name"
|
4
|
+
xml.subtitle "Blog subtitle"
|
5
|
+
xml.id "http://blog.url.com/"
|
6
|
+
xml.link "href" => "http://blog.url.com/"
|
7
|
+
xml.link "href" => "http://blog.url.com/feed.xml", "rel" => "self"
|
8
|
+
xml.updated data.blog.articles.first.date.to_time.iso8601
|
9
|
+
xml.author { xml.name "Blog Author" }
|
10
|
+
|
11
|
+
data.blog.articles.each do |article|
|
12
|
+
xml.entry do
|
13
|
+
xml.title article.title
|
14
|
+
xml.link "rel" => "alternate", "href" => article.url
|
15
|
+
xml.id article.url
|
16
|
+
xml.published article.date.to_time.iso8601
|
17
|
+
xml.updated article.date.to_time.iso8601
|
18
|
+
xml.author { xml.name "Article Author" }
|
19
|
+
xml.summary article.summary, "type" => "html"
|
20
|
+
xml.content article.body, "type" => "html"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<% data.blog.articles[0...5].each_with_index do |article, i| %>
|
2
|
+
<article class="<%= (i == 0) ? 'first' : '' %>">
|
3
|
+
<h1><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e %Y') %></span></h1>
|
4
|
+
|
5
|
+
<%= article.summary %>
|
6
|
+
|
7
|
+
<div class="more"><a href="<%= article.url %>">read on »</a></div>
|
8
|
+
</article>
|
9
|
+
<% end %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<meta http-equiv='X-UA-Compatible' content='IE=edge;chrome=1' />
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
|
9
|
+
<div id="main" role="main">
|
10
|
+
<% if is_blog_article? %>
|
11
|
+
<% content_for :blog_article, yield %>
|
12
|
+
<%= partial settings.blog_article_template %>
|
13
|
+
<% else %>
|
14
|
+
<%= yield %>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<aside>
|
19
|
+
<h2>
|
20
|
+
Recent Articles
|
21
|
+
<a href="/archives">Archive</a>
|
22
|
+
</h2>
|
23
|
+
<ol>
|
24
|
+
<% data.blog.articles[0...10].each do |article| %>
|
25
|
+
<li><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e') %></span></li>
|
26
|
+
<% end %>
|
27
|
+
</li>
|
28
|
+
</aside>
|
29
|
+
</body>
|
30
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
require "middleman-blog"
|
data/middleman-blog.gemspec
CHANGED
@@ -6,18 +6,18 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "middleman-blog"
|
7
7
|
s.version = Middleman::Blog::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["
|
10
|
-
s.email = ["
|
11
|
-
s.homepage = "
|
12
|
-
s.summary = %q{
|
13
|
-
s.description = %q{
|
9
|
+
s.authors = ["Thomas Reynolds"]
|
10
|
+
s.email = ["me@tdreyno.com"]
|
11
|
+
s.homepage = "https://github.com/tdreyno/middleman-blog"
|
12
|
+
s.summary = %q{A blog foundation using Middleman}
|
13
|
+
s.description = %q{A blog foundation using Middleman}
|
14
14
|
|
15
15
|
s.rubyforge_project = "middleman-blog"
|
16
16
|
|
17
|
-
s.add_dependency "middleman", "~> 1.2.0"
|
18
|
-
|
19
17
|
s.files = `git ls-files`.split("\n")
|
20
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
20
|
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency("middleman", ["~> 2.0.2"])
|
23
23
|
end
|
metadata
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-blog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
|
-
-
|
13
|
+
- Thomas Reynolds
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
18
|
+
date: 2011-08-20 00:00:00 Z
|
15
19
|
dependencies:
|
16
20
|
- !ruby/object:Gem::Dependency
|
17
21
|
name: middleman
|
@@ -21,12 +25,17 @@ dependencies:
|
|
21
25
|
requirements:
|
22
26
|
- - ~>
|
23
27
|
- !ruby/object:Gem::Version
|
24
|
-
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
version: 2.0.2
|
25
34
|
type: :runtime
|
26
35
|
version_requirements: *id001
|
27
|
-
description:
|
36
|
+
description: A blog foundation using Middleman
|
28
37
|
email:
|
29
|
-
-
|
38
|
+
- me@tdreyno.com
|
30
39
|
executables: []
|
31
40
|
|
32
41
|
extensions: []
|
@@ -35,18 +44,24 @@ extra_rdoc_files: []
|
|
35
44
|
|
36
45
|
files:
|
37
46
|
- .gitignore
|
38
|
-
- .rvmrc
|
39
47
|
- Gemfile
|
40
|
-
- README.rdoc
|
41
48
|
- Rakefile
|
49
|
+
- lib/.DS_Store
|
42
50
|
- lib/middleman-blog.rb
|
43
|
-
- lib/middleman-blog
|
44
|
-
- lib/middleman-blog/
|
45
|
-
- lib/middleman-blog/
|
51
|
+
- lib/middleman-blog/.DS_Store
|
52
|
+
- lib/middleman-blog/feature.rb
|
53
|
+
- lib/middleman-blog/template.rb
|
54
|
+
- lib/middleman-blog/template/config.ru
|
55
|
+
- lib/middleman-blog/template/config.tt
|
56
|
+
- lib/middleman-blog/template/source/2011/01/01/new-article.html.markdown
|
57
|
+
- lib/middleman-blog/template/source/archives/index.html.erb
|
58
|
+
- lib/middleman-blog/template/source/feed.xml.builder
|
59
|
+
- lib/middleman-blog/template/source/index.html.erb
|
60
|
+
- lib/middleman-blog/template/source/layout.erb
|
46
61
|
- lib/middleman-blog/version.rb
|
62
|
+
- lib/middleman_init.rb
|
47
63
|
- middleman-blog.gemspec
|
48
|
-
|
49
|
-
homepage: http://rubygems.org/gems/middleman-blog
|
64
|
+
homepage: https://github.com/tdreyno/middleman-blog
|
50
65
|
licenses: []
|
51
66
|
|
52
67
|
post_install_message:
|
@@ -59,19 +74,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
74
|
requirements:
|
60
75
|
- - ">="
|
61
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
62
80
|
version: "0"
|
63
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
82
|
none: false
|
65
83
|
requirements:
|
66
84
|
- - ">="
|
67
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
68
89
|
version: "0"
|
69
90
|
requirements: []
|
70
91
|
|
71
92
|
rubyforge_project: middleman-blog
|
72
|
-
rubygems_version: 1.6
|
93
|
+
rubygems_version: 1.8.6
|
73
94
|
signing_key:
|
74
95
|
specification_version: 3
|
75
|
-
summary:
|
96
|
+
summary: A blog foundation using Middleman
|
76
97
|
test_files: []
|
77
98
|
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm ruby-1.9.2-p180@middleman-blog
|
data/README.rdoc
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
= middleman-blog
|
2
|
-
|
3
|
-
Create a blog with Middleman
|
4
|
-
|
5
|
-
== Features
|
6
|
-
|
7
|
-
- metadata (yaml) for your post templates (similar to https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter)
|
8
|
-
- helper methods to access the metadata from every template/layout file
|
9
|
-
- template languages: markdown, textile, rdoc
|
10
|
-
|
11
|
-
== TODO
|
12
|
-
|
13
|
-
- test suite
|
14
|
-
- better documentation
|
15
|
-
- installer/generator
|
16
|
-
- more helpers
|
17
|
-
- more build-in features (releated posts, tags etc.)
|
18
|
-
|
19
|
-
== Usage
|
20
|
-
|
21
|
-
Example: https://github.com/matt-hh/middleman-blog-example
|
22
|
-
|
23
|
-
1. Install
|
24
|
-
|
25
|
-
gem install middleman-blog
|
26
|
-
|
27
|
-
Additionally you need one of the following gems for your post templates: Kramdown, Maruku, RedCloth, BlueCloth, RDiscount ...
|
28
|
-
|
29
|
-
2. Create your project
|
30
|
-
|
31
|
-
mm-init your-middleman-project
|
32
|
-
|
33
|
-
3. Create config/blogs.yml with default values
|
34
|
-
|
35
|
-
blog:
|
36
|
-
title: My Blog
|
37
|
-
author: your name
|
38
|
-
mail: your mail
|
39
|
-
whatever: a value
|
40
|
-
another-blog:
|
41
|
-
title: My second Blog
|
42
|
-
|
43
|
-
Yes, you can define default values for more than one blog...
|
44
|
-
|
45
|
-
4. Create layout files:
|
46
|
-
|
47
|
-
blog_index.haml:
|
48
|
-
|
49
|
-
%h1= current_blog_value('title')
|
50
|
-
= yield
|
51
|
-
|
52
|
-
blog_post.haml:
|
53
|
-
|
54
|
-
%h1= current_post_value('title')
|
55
|
-
= yield
|
56
|
-
|
57
|
-
5. Activate feature in config.rb
|
58
|
-
|
59
|
-
require "middleman-blog"
|
60
|
-
activate :blog_engine
|
61
|
-
|
62
|
-
page "/blog/index.html", :layout => :blog_index, :layout_engine => 'haml'
|
63
|
-
page "/blog/*", :layout => :blog_post, :layout_engine => 'haml'
|
64
|
-
|
65
|
-
page "/another-blog/index.html", :blog_post => :blog_index, :layout_engine => 'haml'
|
66
|
-
page "/another-blog/*", :blog_post => :blog_post, :layout_engine => 'haml'
|
67
|
-
|
68
|
-
6. Create directories in your source folder
|
69
|
-
|
70
|
-
mkdir blog
|
71
|
-
mkdir my-second-blog
|
72
|
-
|
73
|
-
In these folders you can create your posts.
|
74
|
-
|
75
|
-
blog/my-first-post.html.md
|
76
|
-
|
77
|
-
title: Title of my first post
|
78
|
-
date: 2011-06-05
|
79
|
-
----
|
80
|
-
|
81
|
-
|
82
|
-
My first blog post...
|
83
|
-
|
84
|
-
Important: 2 newlines between "----" and "My first..."
|
85
|
-
|
86
|
-
== Metadata
|
87
|
-
|
88
|
-
- "----\n\n\n" separates the metadata from your post data.
|
89
|
-
- metadata supports ERB
|
90
|
-
- you can define whatever you want
|
91
|
-
- special keys for blogs.yml:
|
92
|
-
sort_by: name of another key (default is date)
|
93
|
-
sort_direction: normal | reverse (default is reverse)
|
94
|
-
- special keys for yaml header:
|
95
|
-
date: default is mtime for template file
|
96
|
-
|
97
|
-
== Helper methods
|
98
|
-
|
99
|
-
- current_blog
|
100
|
-
- current_blog_meta(key) or current_blog[key]
|
101
|
-
- current_post
|
102
|
-
- current_post_meta(key) or current_post[key]
|
103
|
-
- next_post
|
104
|
-
- prev_post
|
105
|
-
- current_blog_ident
|
106
|
-
- current_post_ident
|
107
|
-
- current_post_index
|
108
|
-
|
109
|
-
=== Examples
|
110
|
-
|
111
|
-
- Link to the next post
|
112
|
-
|
113
|
-
link_to next_post['title'], next_post['link']
|
114
|
-
|
115
|
-
- List of 10 last posts
|
116
|
-
|
117
|
-
%ul
|
118
|
-
- current_blog["posts"][0,10].each do |post|
|
119
|
-
%li= link_to post['title'], post['link']
|
120
|
-
|
121
|
-
== Links
|
122
|
-
|
123
|
-
* https://github.com/tdreyno/middleman
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module Middleman
|
2
|
-
module Features
|
3
|
-
module BlogEngine
|
4
|
-
|
5
|
-
class << self
|
6
|
-
def registered(app)
|
7
|
-
app.helpers BlogEngine::Helpers
|
8
|
-
end
|
9
|
-
alias :included :registered
|
10
|
-
end
|
11
|
-
|
12
|
-
module Helpers
|
13
|
-
def blog(blog_ident)
|
14
|
-
blogs[blog_ident] || {"posts" => []}
|
15
|
-
end
|
16
|
-
def current_blog
|
17
|
-
blog(current_blog_ident)
|
18
|
-
end
|
19
|
-
def blog_meta(blog_ident, key)
|
20
|
-
blog(blog_ident)[key] || no_value
|
21
|
-
end
|
22
|
-
def current_blog_meta(key)
|
23
|
-
blog_meta(current_blog_ident,key)
|
24
|
-
end
|
25
|
-
def blog_post(blog_ident, post_ident)
|
26
|
-
blog(blog_ident)["posts"].find {|post| post["ident"] == post_ident } || {}
|
27
|
-
end
|
28
|
-
def current_post
|
29
|
-
blog_post(current_blog_ident, current_post_ident)
|
30
|
-
end
|
31
|
-
def blog_post_meta(blog_ident, post_ident, key)
|
32
|
-
blog_post(blog_ident, post_ident)[key] || blog_meta(blog_ident, key) || no_value
|
33
|
-
end
|
34
|
-
def current_post_meta(key)
|
35
|
-
blog_post_meta(current_blog_ident, current_post_ident, key)
|
36
|
-
end
|
37
|
-
def next_post
|
38
|
-
current_blog["posts"][current_post_index + 1]
|
39
|
-
end
|
40
|
-
def prev_post
|
41
|
-
current_blog["posts"][current_post_index - 1]
|
42
|
-
end
|
43
|
-
def current_blog_ident
|
44
|
-
(File.dirname request_path).gsub(%r{^/}, '') || "blog"
|
45
|
-
end
|
46
|
-
def current_post_ident
|
47
|
-
File.basename(request_path).split(".", 2)[0]
|
48
|
-
end
|
49
|
-
def current_post_index
|
50
|
-
current_blog["posts"].index current_post
|
51
|
-
end
|
52
|
-
|
53
|
-
def blogs
|
54
|
-
Middleman::Features::BlogEngine::Meta.new(self).data
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
def request_path
|
59
|
-
self.env['REQUEST_PATH'] || ""
|
60
|
-
end
|
61
|
-
def no_value
|
62
|
-
"-- no value --"
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
class Meta
|
68
|
-
attr_reader :data
|
69
|
-
|
70
|
-
def initialize(app)
|
71
|
-
@app = app
|
72
|
-
|
73
|
-
config_file = File.join(@app.class.root, "config", "blogs.yml")
|
74
|
-
raise "could not find \"#{config_file}\" " unless File.exists?(config_file)
|
75
|
-
blog_config = YAML.load_file(config_file)
|
76
|
-
@data = blog_config
|
77
|
-
|
78
|
-
blog_config.each do |blog_ident,blog_values|
|
79
|
-
blog_source_dir = File.join(@app.class.views, blog_ident)
|
80
|
-
@data[blog_ident]["posts"] = []
|
81
|
-
Dir["#{blog_source_dir}/*.html.*"].each do |file|
|
82
|
-
if file =~ /.*\.html\.(markdown|mkd|md|textile|rdoc)$/
|
83
|
-
post_ident = File.basename(file).split(".", 2)[0]
|
84
|
-
|
85
|
-
post_meta_yml = ERB.new( (File.read(file).split(/#{Middleman::Blog::SEPARATOR}/, 2))[0] || "" ).result
|
86
|
-
post_meta = YAML.load(post_meta_yml) || {}
|
87
|
-
post_meta["ident"] = post_ident
|
88
|
-
post_meta["link"] = "/%s" % File.join( blog_ident, File.basename(file, '.*') )
|
89
|
-
post_meta["date"] = File.mtime(file).to_s unless post_meta["date"]
|
90
|
-
@data[blog_ident]["posts"] << post_meta
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
sort_key = @data[blog_ident]["sort_key"] || "date"
|
95
|
-
@data[blog_ident]["posts"].sort_by! { |post| post[sort_key] }
|
96
|
-
sort_direction = @data[blog_ident]["sort_direction"] || "reverse"
|
97
|
-
@data[blog_ident]["posts"].reverse! if sort_direction == "reverse"
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/lib/middleman-blog/tilt.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Tilt
|
2
|
-
|
3
|
-
module MiddlemanBlogTemplate
|
4
|
-
def prepare
|
5
|
-
@data = data.gsub(/^.*?#{Middleman::Blog::SEPARATOR}/m, '')
|
6
|
-
super
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
# MARKDOWN
|
12
|
-
|
13
|
-
class MarukuMiddlemanBlogTemplate < MarukuTemplate
|
14
|
-
include Tilt::MiddlemanBlogTemplate
|
15
|
-
end
|
16
|
-
register MarukuMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
|
17
|
-
|
18
|
-
class KramdownMiddlemanBlogTemplate < KramdownTemplate
|
19
|
-
include Tilt::MiddlemanBlogTemplate
|
20
|
-
end
|
21
|
-
register KramdownMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
|
22
|
-
|
23
|
-
class BlueClothMiddlemanBlogTemplate < BlueClothTemplate
|
24
|
-
include Tilt::MiddlemanBlogTemplate
|
25
|
-
end
|
26
|
-
register BlueClothMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
|
27
|
-
|
28
|
-
class RedcarpetMiddlemanBlogTemplate < RedcarpetTemplate
|
29
|
-
include Tilt::MiddlemanBlogTemplate
|
30
|
-
end
|
31
|
-
register RedcarpetMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
|
32
|
-
|
33
|
-
class RDiscountMiddlemanBlogTemplate < RDiscountTemplate
|
34
|
-
include Tilt::MiddlemanBlogTemplate
|
35
|
-
end
|
36
|
-
register RDiscountMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
|
37
|
-
|
38
|
-
# TEXTILE
|
39
|
-
|
40
|
-
class RedClothMiddlemanBlogTemplate < RedClothTemplate
|
41
|
-
include Tilt::MiddlemanBlogTemplate
|
42
|
-
end
|
43
|
-
register RedClothMiddlemanBlogTemplate, 'textile'
|
44
|
-
|
45
|
-
# RDOC
|
46
|
-
|
47
|
-
class RDocMiddlemanBlogTemplate < RDocTemplate
|
48
|
-
include Tilt::MiddlemanBlogTemplate
|
49
|
-
end
|
50
|
-
register RDocMiddlemanBlogTemplate, 'rdoc'
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|