forked from dmytro/startpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
173 lines (144 loc) · 4.53 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
165
166
167
168
169
170
171
172
173
# -*- coding: utf-8 -*-
require 'slim'
Slim::Engine.disable_option_validator!
require 'pry'
I18n.enforce_available_locales = true
# general settings
set :encoding, 'utf-8'
set :index_file, 'index.html'
set :css_dir, 'assets/stylesheets'
set :js_dir, 'assets/javascripts'
set :images_dir, 'assets/images'
set :partials_dir, 'partials'
set :haml, { :format => :html5 }
ignore '*.less'
activate :livereload
activate :directory_indexes
helpers do
def chapters( post )
headers = File.readlines( post.source_file ).collect do |x|
if x =~ /^\#{1,6}\s(.*)/
$1
else
nil
end
end.compact
case markdown_engine
when :redcarpet
headers.map { |x| [x, x.downcase.gsub( /\s/, "-" )] }
when :kramdown
headers.each_with_index.map { |x,i| [x,i == 0 ? "section" : "section-#{i}"] }
else
[]
end
end
def button_color(size)
case size
when "lg"; then "red-900"
when "sm"; then "red-500"
when "xs"; then "red-400"
else "red-600"
end
end
def button(url, title=nil, size: 'normal', expand_too:[])
title = title || sitemap.resources.find { |x| x.path =~ /#{url}/ }.data.title
href="#{base}/#{url}"
urls = expand_too << url
active = active_class urls
color = button_color(size)
current = page_active?(url) ? 'current' : ''
%Q{
<li class='#{active}'>
<a class='#{current} btn btn-#{size} btn-raised btn-material-#{color}' href='#{href}'>#{title}
<div class='ripple-wrapper'></div>
</a>
}
end
def nav(*params, **rest)
button(*params, size: "lg", **rest)
end
def nav2(*params, **rest)
button(*params, **rest)
end
def nav3(*params, **rest)
button(*params, size: "sm", **rest)
end
def nav4(*params, **rest)
button(*params, size: "xs", **rest)
end
def image_caption(image, text)
%{<figure>
#{image_tag image}
<figcaption> #{text} </figcaption>
</figure>}
end
def page_active?(urls)
Array(urls).each do |url|
return true if current_page.url.split("/").last == url.split("/").last
end
false
end
def active_class(url)
"active" if page_active?(url)
end
end
# set :markdown, tables: true, autolink: true, gh_blockcode: true, fenced_code_blocks: true, with_toc_data: true, smart: true
# set :markdown_engine, :redcarpet
set :markdown_engine, :kramdown
set :markdown, :layout_engine => :erb,
:tables => true,
:autolink => true,
footnotes: true,
:smartypants => true,
smart_quotes: [180, 180, 8222, 8220]
configure :development do
set :base, ""
activate :relative_assets
end
configure :build do
set :base, "/startpack"
activate :relative_assets
# activate :directory_indexes
activate :sprockets
activate :minify_css
activate :minify_javascript
set :relative_links, true
activate :disqus do |d|
d.shortname = 'startpack'
end
# somehow minifying html takes some html attributes away so it is causing
# some css not applied to certain elements... so until we find alternative
# way to monify html, we will disable this
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 'product.html'
ignore(/Icon\r$/)
ignore(/\.DS_Store/)
ignore(/^assets.*\.yml/)
ignore(/^assets\/stylesheets\/(?!all).*\.css/)
ignore(/^assets\/javascripts\/(?!all).*\.js/)
ignore(%r{^assets/stylesheets/colorschemas/.*})
ignore(%r{^assets/images/homepage-slider/pysanka-.*\.jpg$})
ignore(%r{/src/})
# if ENV['CDN_HOST']
# activate :asset_host
# set :asset_host, ENV['CDN_HOST']
# end
end