-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rules
182 lines (165 loc) · 4.97 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# 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.
# ignore everything starting with underscore
ignore '/**/_*'
# preprocess blarg entries
preprocess do
@items.find_all('/blarg/*.md').select{
|b| b[:hidden].nil?
}.each do |b|
created_at = Time.parse(File.basename(b.identifier.without_ext).split('_')[0])
b[:created_at] = created_at
b[:created_at_s] = created_at.strftime("on %B #{created_at.day.ordinalize}, %Y")
b[:kind] = 'article'
end
articles_to_paginate = sorted_articles
article_groups = []
until articles_to_paginate.empty?
article_groups << articles_to_paginate.slice!(0..@config[:page_size]-1)
end
article_groups.each_with_index do |subarticles, i|
first = i*config[:page_size] + 1
last = (i+1)*config[:page_size]
pagination = ""
if article_groups.length > 1
pagination += <<-EOF
<nav aria-label="Naev Development Blarg">
<ul class="pagination justify-content-center">
EOF
if i > 0
pagination += <<-EOF
<li class="page-item">
<a class="page-link" href="<%= relative_path_to(@items['/page/#{i}.md']) %>" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
EOF
end
(0..2).reverse_each do |j|
if i > j
pagination += <<-EOF
<li class="page-item"><a class="page-link" href="<%= relative_path_to(@items['/page/#{i-j}.md']) %>">#{i-j}</a></li>
EOF
end
end
pagination += <<-EOF
<li class="page-item active"><a class="page-link" href="#">#{i+1}</a></li>
EOF
(0..2).each do |j|
if article_groups.length > i+j+1
pagination += <<-EOF
<li class="page-item"><a class="page-link" href="<%= relative_path_to(@items['/page/#{i+2+j}.md']) %>">#{i+2+j}</a></li>
EOF
end
end
if article_groups.length > i+1
pagination += <<-EOF
<li class="page-item">
<a class="page-link" href="<%= relative_path_to(@items['/page/#{i+2}.md']) %>" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
EOF
end
pagination += <<-EOF
</ul>
</nav>
EOF
end
content = <<-EOF
#{pagination}
<hr>
<ul class='list-unstyled'>
EOF
subarticles.each do |b|
content += <<-EOF
<li class='mt-3 mb-4'>
<div class='blog-post'>
<h4><%= link_to('#{b[:title]}', @items['#{b.identifier}'].reps[@rep.name].path ) %></h4>
<p class="text-muted"><%= ("by #{b[:author]}, #{b[:created_at_s]}").upcase %></p>
<%= @items['#{b.identifier}'].reps[@rep.name].compiled_content %>
</div>
<hr>
</li>
EOF
end
content += <<-EOF
</ul>
#{pagination}
EOF
@items.create(
content,
{ :extension => 'md',
:title => "Naev Development Blarg (Page #{i+1})"},
"/page/#{i+1}.md"
)
end
end
# some special files
compile '/sitemap.rb' do
filter :erb
write '/sitemap.xml'
end
compile '/robots.txt' do
filter :erb
write '/robots.txt'
end
compile '/feed.rb' do
filter :erb
write '/feed/index.xml'
end
# favoicon
[16, 32, 64, 128, 180, 196].each do |s|
compile '/favicon.png', rep: "s#{s.to_s}" do
filter :thumbnailize, :width => s, :height => s
write "/favicon-#{s.to_s}.png"
end
end
compile '/favicon.png', rep: :ico do
filter :thumbnailize, :width => 48, :height => 48, :filetype => 'ico'
write '/favicon.ico'
end
compile '/**/*.md' do
if item['hidden'].nil?
filter :erb
# Markdown
filter :kramdown
# Standard procesing
layout '/default.html'
filter :relativize_paths, :type => :css
filter :relativize_paths, :type => :html
filter :tidy
basename = (item.identifier=='/index.md') ? '' : item.identifier.without_ext
write basename+'/index.html'
end
end
# Javascript and friends
compile '/**/*.js' do
filter :concat_js
filter :uglify_js, :comments => :none
write ext: 'js'
end
# CSS and friends
compile '**/*.{css,scss}' do
filter :erb
filter :sass, syntax: :scss if item[:extension] == 'scss'
filter :rainpress
write ext: 'css'
end
# Other objects
compile '/**/*' do
write item.identifier.to_s
end
layout '/**/*', :erb