Skip to content

Commit ff22ed7

Browse files
committed
added auto generating of author and tag pages
1 parent ee30344 commit ff22ed7

22 files changed

+312
-63
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ gem "nokogiri"
1616
gem "rdiscount"
1717
gem "mime-types"
1818
gem "nanoc"
19+
gem "builder"
1920

2021
group :development, :test do
2122
gem "rake"

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ GEM
33
specs:
44
adsf (1.2.0)
55
rack (>= 1.0.0)
6+
builder (3.2.2)
67
celluloid (0.16.0)
78
timers (~> 4.0.0)
89
chunky_png (1.3.1)
@@ -76,6 +77,7 @@ PLATFORMS
7677

7778
DEPENDENCIES
7879
adsf
80+
builder
7981
chunky_png
8082
compass
8183
cri

Rakefile

+4-36
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,8 @@
1+
require "pathname"
2+
13
RakeRoot = Pathname.new(Rake.application.find_rakefile_location.last)
24

3-
require "net/https"
4-
require "nanoc"
5-
require "nanoc/cli"
5+
Dir[RakeRoot+'lib/tasks/*.rake'].each { |task| load task }
66

7+
task :test => [:compile, :checks]
78
task :default => :test
8-
9-
desc "Compile & Test"
10-
task :spec => :test
11-
task :test => [:check_ssl, :deploy] do
12-
Dir.chdir(RakeRoot) do
13-
Nanoc::CLI.run(%w(check stale))
14-
Nanoc::CLI.run(%w(check internal_links))
15-
# Nanoc::CLI.run(%w(check external_links))
16-
end
17-
end
18-
19-
desc "Deploy the Site"
20-
task :deploy do
21-
Dir.chdir(RakeRoot) do
22-
Nanoc::CLI.run(%w(compile))
23-
end
24-
end
25-
26-
desc "Check if SSL certificate is valid."
27-
task :check_ssl do
28-
http = Net::HTTP.new("rvm.io", 443)
29-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
30-
http.use_ssl = true
31-
32-
cert = nil
33-
http.start do |h|
34-
cert = h.peer_cert
35-
end
36-
37-
if (Time.new + 432000) > cert.not_after
38-
abort("There is a imminent problem brewing with SSL, it expires on: #{cert.not_after}")
39-
end
40-
end

Rules

+22-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
require "compass"
44
Compass.add_project_configuration('compass_config.rb')
5-
65
# For compass v0.10 should be:
76
# Compass.add_configuration "#{File.dirname(__FILE__)}/compass_config.rb"
87

8+
preprocess do
9+
AutoHelper.new(File.dirname(__FILE__), self).auto
10+
end
11+
912
compile "/assets/css/*/" do
1013
filter :sass, Compass.sass_engine_options
1114
end
@@ -29,20 +32,33 @@ end
2932
end
3033
end
3134

32-
compile '/blog/*' do
33-
filter :erb
34-
filter :rdiscount
35+
compile '/blog/feed' do
36+
filter :haml
37+
end
38+
39+
route '/blog/feed' do
40+
'/blog/feed.xml'
41+
end
42+
43+
compile '/blog/' do
44+
filter :haml
3545
filter :auto_ids
3646
filter :pre_code
37-
layout 'blog'
47+
layout 'default'
3848
end
3949

4050
compile '/blog/*/' do
41-
filter :erb
4251
filter :rdiscount
52+
filter :pre_code
53+
layout 'blog'
4354
filter :auto_ids
55+
end
56+
57+
compile '/(authors|tags)/*/' do
58+
filter :haml
4459
filter :pre_code
4560
layout 'blog'
61+
filter :auto_ids
4662
end
4763

4864
# TODO for nanoc 3.8:

config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ data_sources:
44
- type: filesystem_unified
55
items_root: /
66
layouts_root: /
7+
base_url: http://rvm.io

content/assets/css/_default.sass

-7
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,6 @@ br:before
184184
center
185185
text-align: center
186186

187-
a.anchor
188-
opacity: 0.3
189-
cursor: pointer
190-
191-
a.anchor:hover
192-
opacity: 0.7
193-
194187
\:link, :visited
195188
text-decoration: none
196189

content/assets/css/screen.sass

+21
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ $title-background: #292929
305305
margin-top: 2%
306306
font-size: 0.9em
307307
+round_border(5px, 5px, 5px, 5px)
308+
aside
309+
font-style: italic
310+
font-size: 80%
311+
#article
312+
p
313+
padding: 1px
314+
text-indent: 5px
315+
hr.medium
316+
margin: 0
317+
height: 2px
318+
background-color: #8b1417
319+
320+
h1, h2, h3
321+
a.anchor
322+
opacity: 0.3
323+
cursor: pointer
324+
325+
a.anchor:hover
326+
opacity: 0.7
327+
328+
308329
img
309330
max-width: 100%
310331
div

content/authors/mpapis.haml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Author Michal Papis
3+
created_at: 2014-09-29 01:35:10 +0200
4+
---
5+
%h2 Articles
6+
7+
%ul
8+
= links_for_articles(:author => "mpapis")

content/blog.haml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- sorted_articles.each_with_index do |item, index|
2+
- if index>0
3+
%hr.medium
4+
%h1
5+
= get_post_link(item)
6+
%aside
7+
= get_post_meta(item)
8+
%article
9+
= get_post_start(item)

content/blog.md

-1
This file was deleted.

content/blog/2014-09-04-rvm-blog.md

-7
This file was deleted.

content/blog/2014-09-29-rvm-blog.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Welcome to RVM Blog
3+
created_at: 2014-09-29 09:00:00 +0000
4+
kind: article
5+
author: mpapis
6+
author_full: Michal Papis
7+
tags:
8+
- news
9+
- site
10+
---
11+
### Welcome
12+
13+
I have been planning to build the blog for quite some time and here it
14+
is, I will be writing here about progress on RVM 2.0, releases for all
15+
RVM related software and hosting guest blog posts about anything rvm
16+
related.
17+
18+
<!-- more -->
19+
20+
### Help RVM
21+
22+
For anyone interested in writing for RVM blog please contact
23+
<mpapis@gmail.com>.
24+
25+
If you find the layout ugly or just want to help me make it better,
26+
please see
27+
[the rvm-site project on github](https://github.com/rvm/rvm-site).

content/blog/feed.haml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
= atom_feed :title => 'RVM blog', :author_name => 'Michal Papis', :author_uri => 'http://rvm.io', :limit => 10

layouts/blog.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
%a{ :name => "top" }
1616
%h1
1717
= item[:title]
18+
%hr.medium
1819
%aside
19-
Posted at:
20-
= item[:created_at]
20+
= get_post_meta(item)
2121
%article
2222
=yield
2323
%a{ :name => "bottom" }

layouts/shared/blog_menu.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
|
66
= link_to 'RVM Blog', '/blog/', style: "color: red;"
77
%ul
8-
= sorted_articles.map{|post| "<li>#{link_to("#{post.attributes[:created_at].to_s} #{post.attributes[:title]}", post)}</li>" }.join("\n")
8+
= links_for_articles
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
---
3+
---
4+
title: Author <%= author_full %>
5+
created_at: <%= Time.new %>
6+
---
7+
%h2 Articles
8+
9+
%ul
10+
= links_for_articles(:author => "<%= author %>")

layouts/templates/tag_page.haml.erb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
---
3+
---
4+
title: Tag <%= tag %>
5+
created_at: <%= Time.new %>
6+
---
7+
%h2 Articles
8+
9+
%ul
10+
= links_for_articles(:tag => "<%= tag %>")

lib/auto.rb

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
require 'pathname'
2+
3+
class AutoHelper
4+
attr_reader :root, :site, :tags, :authors
5+
6+
def initialize(root, site)
7+
@root = Pathname(root)
8+
@site = site
9+
@tags = []
10+
@authors = {}
11+
end
12+
13+
def parse_tags(item)
14+
item.attributes[:tags].each { |tag| @tags << tag unless @tags.include?(tag) }
15+
end
16+
17+
def parse_author(item)
18+
authors[item.attributes[:author]] = item.attributes[:author_full]
19+
end
20+
21+
def parse_site
22+
site.items.each do |item|
23+
parse_tags (item) if item.attributes[:tags]
24+
parse_author(item) if item.attributes[:author]
25+
end
26+
end
27+
28+
def write_file(file, content)
29+
file.open('w') { |file| file.write(content) }
30+
end
31+
32+
def render_layout(layout_name, mapping = {})
33+
layout = @site.layouts.find { |l| l.identifier == layout_name.cleaned_identifier }
34+
filter = Nanoc::Filter.named('erb').new(mapping)
35+
filter.run(layout.raw_content)
36+
end
37+
38+
def create_tag_page(tag_page, tag)
39+
write_file(tag_page, render_layout("templates/tag_page", tag: tag))
40+
end
41+
42+
def create_tag_feed(feed_page, tag)
43+
#TODO
44+
end
45+
46+
def ensure_tag_page(tags_dir, tag)
47+
tag_page = tags_dir + "#{tag}.haml"
48+
feed_page = tags_dir + "#{tag}_feed.haml"
49+
50+
create_tag_page(tag_page, tag) unless tag_page.exist?
51+
create_tag_feed(feed_page, tag) unless feed_page.exist?
52+
end
53+
54+
def ensure_tag_pages
55+
tags_dir = root + 'content' + 'tags'
56+
tags_dir.mkpath
57+
58+
tags.each do |tag|
59+
ensure_tag_page(tags_dir, tag)
60+
end
61+
end
62+
63+
def create_author_page(author_page, author, author_full)
64+
write_file(author_page, render_layout("templates/author_page", author: author, author_full: author_full))
65+
end
66+
67+
def create_author_feed(feed_page, author, author_full)
68+
#TODO
69+
end
70+
71+
def ensure_author_page(authors_dir, author, author_full)
72+
author_page = authors_dir + "#{author}.haml"
73+
feed_page = authors_dir + "#{author}_feed.haml"
74+
75+
create_author_page(author_page, author, author_full) unless author_page.exist?
76+
create_author_feed(feed_page, author, author_full) unless feed_page.exist?
77+
end
78+
79+
def ensure_author_pages
80+
authors_dir = root + 'content' + 'authors'
81+
authors_dir.mkpath
82+
83+
authors.each_pair do |author, author_full|
84+
ensure_author_page(authors_dir, author, author_full)
85+
end
86+
end
87+
88+
def auto
89+
parse_site
90+
ensure_tag_pages
91+
ensure_author_pages
92+
end
93+
end

0 commit comments

Comments
 (0)