forked from Secretchronicles/main-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRules
151 lines (121 loc) · 3.9 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require "time"
# A few helpful tips about the Rules file:
#
# * The string given to #compile and #route are matching patterns for
# identifiers--not for paths. Therefore, you can’t match on extension.
#
# * The order of rules is important: for each item, only the first matching
# rule is applied.
#
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
# “content/about.html”). To select all children, grandchildren, … of an
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
LANGUAGES = Dir["content/*"].map{|str| File.basename(str)}.select{|str| str.chars.count == 2}
# Generate the RSS feeds
preprocess do
LANGUAGES.each do |lang|
feed = <<-ATOM
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<link rel="self" type="application/atom+xml" href="https://secretchronicles.org/#{lang}/feed/"/>
<link rel="alternate" type="text/html" href="https://secretchronicles.org/#{lang}/"/>
<title>Secretchronicles #{lang} Feed</title>
<updated>#{Time.now.utc.iso8601}</updated>
<id>secretchronicles.org;#{lang}feed</id>
ATOM
news = news_for(lang)
news.each_with_index do |news_item, i|
# Generate atom scaffold for this item. Note that we do not have
# the compiled :default rep yet, so we must defer injection of the
# actual content until the #compile step. By utilizing the #identifier,
# we can safely retrieve the same item from nanoc we are handling here,
# and use ERB (via #compile below) to inject the compiled content.
item_atom = <<-ATOM
<% item = items.find{|item| item.identifier == "#{news_item.identifier}"} %>
<entry>
<link href="<%= item.path %>"/>
<title>#{news_item[:title]}</title>
<id>secretchronicles.org/#{lang};#{news.count - i}</id>
<updated>#{news_item[:date].iso8601}</updated>
<author><name>#{news_item[:author]}</name></author>
<summary type="html"><%= CGI.escape_html(item[:summary]) %></summary>
<content type="html"><%= CGI.escape_html(item.compiled_content) %></content>
</entry>
ATOM
feed << "\n" << item_atom
end
feed << "\n</feed>\n"
@items << Nanoc::Item.new(feed, {}, "/#{lang}/feed/")
end
end
LANGUAGES.each do |lang|
compile "/#{lang}/" do
filter :erb
filter :kramdown, :coderay_line_numbers => nil, :coderay_css => :class
layout "default_#{lang}"
end
compile '/' do
end
compile "/#{lang}/news/" do
filter :erb
layout "default_#{lang}"
end
compile "/#{lang}/archive/" do
filter :erb
layout "default_#{lang}"
end
compile "/#{lang}/feed/" do
filter :erb
end
compile "/#{lang}/pages/*/" do
filter :kramdown, :coderay_line_numbers => nil, :coderay_css => :class
layout "default_#{lang}"
end
compile "/#{lang}/news/*/" do
filter :kramdown, :coderay_line_numbers => nil, :coderay_css => :class
layout "blogpost_#{lang}"
end
end
route "/*/news/*/" do
if item.identifier =~ /(\d{4})-(\d{2})-(\d{2})-(.*)$/
$` + "#$1/#$2/#$3/#$4" + "index.html"
else
raise "Invalid news post filename format #{item.identifier}"
end
end
LANGUAGES.each do |lang|
route "/#{lang}/" do
"/#{lang}/index.html"
end
route "/#{lang}/news/" do
"/#{lang}/news/index.html"
end
route "/#{lang}/archive/" do
"/#{lang}/news/archive/index.html"
end
route "/#{lang}/feed/" do
"/#{lang}/feed.atom"
end
route "/" do
"/index.html"
end
route "/#{lang}/pages/*/" do
"/#{lang}/" + item.identifier.split("/")[3] + "/index.html"
end
end
compile '/stylesheets/*/' do
# don’t filter or layout
end
compile "/assets/*/" do
# don’t filter binary assets
end
route '/stylesheets/*/' do
item.identifier.chop + ".css"
end
route "/assets/*/" do
item.identifier.chop + "." + item[:extension]
end
layout '*', :erb