-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rules
122 lines (110 loc) · 3.5 KB
/
Rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env ruby
require 'time'
require 'compass'
Compass.add_project_configuration 'compass_config.rb'
preprocess do
# Link the all the given items in order in a doubly linked list.
#
# The previous and next item identifier are stored in item[:navigation_prev]
# and item[:navigation_next] respectively.
#
# see navigation_prev() and navigation_next()
def setup_previous_next_nav(items)
first, last = 0, (items.length - 1)
items.each_with_index do |item, i|
item[:navigation_prev] = items[i - 1].identifier if i > first
item[:navigation_next] = items[i + 1].identifier if i < last
end
end
# setup some items for tags pages
def generate_tag_pages_items
# build a Hash like {'tagname' => [article1, article0], ...}
sorted_articles.inject Hash.new do |injected, article|
article_tags = article[:tags] || Array.new
article_tags.each { |tag| (injected[tag] ||= Array.new) << article }
injected
end.each do |tag, tagged|
content = "<%= render '/_blog_archives.erb', articles: @item[:article_ids].map { |id| @items[id] } %>"
attributes = {
navbar: 'Archives',
title: "Tag: #{tag}",
kind: 'tag-archive',
tag: tag,
article_ids: tagged.map(&:identifier)
}
identifier = "/blog/tags/#{tag}.erb" # FIXME: slugize ?
@items.create(content, attributes, identifier)
end
end
# inspired by http://nanoc.ws/docs/guides/paginating-articles/
def generate_blog_pages_items
slices = sorted_articles.each_slice(@config[:paginate])
slices.each_with_index do |subarticles, i|
content = "<%= render '/_blog_page.erb', articles: @item[:article_ids].map { |id| @items[id] } %>"
attributes = {
navbar: 'Blog',
kind: 'blog-page',
no_page_header: true,
article_ids: subarticles.map(&:identifier),
}
identifier = if i.zero?
then "/index.erb"
else "/blog/page/#{i + 1}.erb"
end
@items.create(content, attributes, identifier)
end
end
generate_tag_pages_items
generate_blog_pages_items
setup_previous_next_nav sorted_articles.reverse
setup_previous_next_nav blog_pages.reverse
end
layout '/**/*.erb', :erb
# favicon
passthrough '/favicon.*'
# some exceptional files
%w[/sitemap.xml /robots.txt /humans.txt /atom.xml].each do |f|
compile "#{f}.erb" do
filter :erb
end
end
# stylesheets
ignore '/style/**/_*' # partials
# /style/foo.scss → /style/foo.css
compile '/style/**/*.scss' do
filter :sass, Compass.sass_engine_options
filter :relativize_paths, :type => :css
write @item.identifier.without_ext + '.css'
end
# blog articles
# /blog/articles/foo.html → /blog/1970/01/01/foo/index.html
compile '/blog/articles/**/*.erb' do
filter :erb
filter :octohl
layout '/article.erb'
layout '/default.erb'
t = attribute_to_time(@item[:created_at]).strftime('%Y/%m/%d')
name = File.basename @item.identifier.without_ext
write "/blog/#{t}/#{name}/index.html"
end
# site pages
compile '/**/*.erb' do
filter :erb
filter :octohl
layout '/page.erb'
layout '/default.erb'
end
# /foo/bar/index.erb → /foo/bar/index.html
route '/**/index.erb' do
@item.identifier.without_ext + ".html"
end
# /foo/bar/oni.erb → /foo/bar/oni/index.html
# + special cases handling for item having a path attribute set.
route '/**/*.erb' do
@item[:path] or @item.identifier.without_ext + '/index.html'
end
# static stuff
# /static/foo.bar → /foo.bar
compile '/static/**/*' do
write @item.identifier.to_s.sub(/\A\/static/, '')
end