-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.rb
164 lines (134 loc) · 4.16 KB
/
config.rb
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
# -*- coding: utf-8 -*-
require 'slim'
require 'babosa'
Slim::Engine.disable_option_validator!
require 'pry'
set :encoding, 'utf-8'
set :index_file, 'index.html'
###
# Automatic image dimensions on image_tag helper
# activate :automatic_image_sizes
# Reload the browser automatically whenever files change
configure :development do
activate :livereload
end
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
set :partials_dir, 'partials'
helpers do
def skip_index_files
["index.html", "tag.html", "tags.html", "letters.html"]
end
def skip?(resource)
skip_index_files.include?(resource.destination_path)
end
# Find all songs that have title.
def titled
sitemap
.resources
.find_all { |res| !res.data.title.nil? && !skip?(res) }
end
# Find songs that start with a given letter
def starts_with(letter)
titled.find_all { |art| transliterated(art.dup.data.title[0]) == transliterated(letter.dup) }
end
def alphabet
@alphabet ||= "АБВГҐДЕЄЖЗИІЇЙКЛМНОПРСТУФХЦЧШЩЮЬЯ".split('')
end
# Find all articles that have tags.
def tagged
sitemap
.resources
.find_all { |res| !res.data.tags.nil? }
end
def tags
tagged
.map(&:data)
.map(&:tags)
.flatten
.uniq
.compact
end
def with_tag(tag)
tagged
.find_all {|res| res.data.tags.include? tag }
end
def tag_path(tag)
"tags/#{transliterated(tag)}.html"
end
def path_to_letter(letter)
"letters/#{transliterated(letter)}.html"
end
def transliterated(word)
word.to_slug.transliterate(:ukrainian).to_s
.downcase
.gsub(/[^A-Za-z0-9]/i,'_')
end
def tag_cloud
size_min, size_max = 1, 3
articles = {}
tags.each do |tag|
articles[tag] = tagged.find_all {|res| res.data.tags.include? tag }
end
counts = articles.map do |tag, posts|
[tag, posts.count]
end
min, max = counts.map(&:last).minmax
weight = counts.map do |name, count|
# logarithmic distribution
weight = (max == min) ? 0 : (Math.log(count) - Math.log(min))/(Math.log(max) - Math.log(min))
[name, weight]
end
weight.sort_by! { rand }
weight.map do |tag|
name, weight = tag
size = size_min + ((size_max - size_min) * weight).to_f
[name, size]
end
end
end
ready do
tags.each do |tag|
articles = with_tag(tag)
proxy tag_path(tag), "tag.html", locals: { tag: tag, articles: articles}, :ignore => true
end
alphabet.each do |letter|
articles = starts_with(letter)
proxy path_to_letter(letter), "letter.html", locals: { letter: letter, articles: articles}, :ignore => true
end
end
# Build-specific configuration
configure :build do
activate :relative_assets
# activate :directory_indexes
activate :sprockets
activate :minify_css
activate :minify_javascript
set :relative_links, true
activate :minify_html do |html|
html.remove_multi_spaces = true # Remove multiple spaces
html.remove_comments = true # Remove comments
html.remove_intertag_spaces = false # Remove inter-tag spaces
html.remove_quotes = true # Remove quotes
html.simple_doctype = false # Use simple doctype
html.remove_script_attributes = false # Remove script attributes
html.remove_style_attributes = false # Remove style attributes
html.remove_link_attributes = false # Remove link attributes
html.remove_form_attributes = false # Remove form attributes
html.remove_input_attributes = false # Remove input attributes
html.remove_javascript_protocol = false # Remove JS protocol
html.remove_http_protocol = false # Remove HTTP protocol
html.remove_https_protocol = false # Remove HTTPS protocol
html.preserve_line_breaks = false # Preserve line breaks
html.simple_boolean_attributes = true # Use simple boolean attributes
end
activate :asset_hash
activate :gzip
ignore '*.less'
ignore 'readme.md'
ignore(/Icon\r$/)
ignore(/\.DS_Store/)
ignore(/^assets\/stylesheets\/(?!all).*\.css/)
ignore(/^assets\/javascripts\/(?!all).*\.js/)
end