forked from dry-rb/dry-rb.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rb
246 lines (194 loc) · 6.26 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
require "socket"
require "better_errors"
require "slim"
require "lib/redcarpet_renderers"
require "lib/typography_helpers"
use BetterErrors::Middleware
# Settings ---------------------------------------------------------------------
# Private settings
# Pulled from the `.env` in the root directory. Exposed as `ENV["SETTING_NAME"]`
# across all templates/asset environments
activate :dotenv
# Public site settings
# Pulled from `site.yaml`. Exposed as `site.setting_name` in templates.
set :site, YAML::load_file(File.dirname(__FILE__) + "/site.yaml").to_hashugar
Time.zone = config.site.timezeone
set :site_title, "dry-rb"
set :site_url, "http://dry-rb.org"
set :site_description, "dry-rb is a collection of micro-libraries, each intended to encapsulate a common task in Ruby."
set :site_keywords, "dry-rb, ruby, micro-libraries"
# Configuration ----------------------------------------------------------------
# General configuration for Middleman assets
set :build_dir, "docs"
set :css_dir, "assets/stylesheets"
set :js_dir, "assets/javascripts"
set :images_dir, "images"
set :fonts_dir, "fonts"
set :vendor_dir, "vendor"
activate :external_pipeline,
name: :webpack,
command:
(if build?
"./node_modules/webpack/bin/webpack.js --bail"
else
"./node_modules/webpack/bin/webpack.js --watch -d"
end),
source: ".tmp/dist",
latency: 1
activate :syntax, css_class: "syntax"
set :markdown_engine, :redcarpet
set :markdown, fenced_code_blocks: true,
autolink: true,
smartypants: true,
hard_wrap: true,
smart: true,
superscript: true,
no_intra_emphasis: true,
lax_spacing: true,
with_toc_data: true,
tables: true
# Activate various extensions --------------------------------------------------
# Make sure that livereload uses the host FQDN so we can use it across network
activate :livereload, host: Socket.gethostbyname(Socket.gethostname).first
# Automatic image dimensions on image_tag helper
# activate :automatic_image_sizes
# Time.zone = "UTC"
###
# Blog settings
###
activate :blog do |blog|
# This will add a prefix to all links, template references and source paths
blog.prefix = "/news"
# Matcher for blog source files
blog.sources = "{year}-{month}-{day}.html"
# blog.taglink = "tags/{tag}.html"
blog.layout = "news-single"
blog.summary_separator = /(READMORE)/
# blog.summary_length = 250
# blog.year_link = "{year}.html"
# blog.month_link = "{year}/{month}.html"
# blog.day_link = "{year}/{month}/{day}.html"
# blog.default_extension = ".markdown"
# blog.tag_template = "tag.html"
# blog.calendar_template = "calendar.html"
# Enable pagination
# blog.paginate = true
# blog.per_page = 10
# blog.page_link = "page/{num}"
end
page "/feed.xml", layout: false
# Output everything as a `/directory/index.html` instead of individual files
activate :directory_indexes
# Page options -----------------------------------------------------------------
###
# Page options, layouts, aliases and proxies
###
# Per-page layout changes:
#
# page "/path/to/file.html", layout: :otherlayout
# With no layout
# page "/path/to/file.html", layout: false
#
# A path which all have the same layout:
# With alternative layout
# page "/path/to/file.html", layout: :otherlayout
#
# with_layout :admin do
# page "/admin/*"
# end
# A path which all have the same layout
# with_layout :admin do
# page "/admin/*"
# end
# Proxy (fake) files:
# page "/this-page-has-no-template.html", proxy: "/template-file.html" do
# @which_fake_page = "Rendering a fake page with a variable"
# end
# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", locals: {
# which_fake_page: "Rendering a fake page with a local variable" }
page "/", layout: "base"
page "/news/*", layout: "news-single"
page "*.json"
###
# Helpers
###
# Automatic image dimensions on image_tag helper
# activate :automatic_image_sizes
helpers do
def page_title
[config[:site_title], page_header, current_page.data.title].compact.join(' - ')
end
def page_header
current_page.data.name || recursive_name(current_page)
end
def recursive_name(page)
return nil unless page
return page.data.name if page.data.name
recursive_name(page.parent)
end
def nav
url = "#{current_resource.url.split('/')[0..2].join('/')}/"
root = sitemap.resources.detect { |page| page.url == url }
raise "page for #{url} not found" unless root
content_tag(:ul, nav_link(root, false))
end
def nav_header
name = current_resource.url.split('/')[2]
content_tag(:h2, name)
end
def nav_link(page, nest = true)
content_tag(:li) do
classes = []
classes << 'active' if current_resource.url == page.url
html = link_to(page.data.title, page.url, class: classes.join(' '))
if page.data.sections
links = nav_links(page.children, page).html_safe
html << (nest ? content_tag(:ul, links) : links)
end
html
end
end
def nav_links(pages, root)
root.data.sections.map do |name|
page = pages.sort_by { |s| s.path.length }.detect { |r| r.path.include?(name) }
raise "section #{name} not found" unless page
nav_link(page)
end.join
end
# Returns a list of pages matching a specific type
def list_pages_by_type(type)
return [] unless type
sitemap.resources.select do |resource|
resource.data.type == type
end.sort_by { |resource| resource.data.order }
end
# Return a list of pages matching a specific group
def list_pages_by_group(group)
return [] unless group
sitemap.resources.select do |resource|
resource.data.group == group
end.sort_by { |resource| resource.data.order }
end
def page
current_resource
end
def site
config.site
end
def partial(name)
super("partials/#{name}")
end
def author_url
author = site.authors[current_page.data.author]
link_to author.name, author.url
end
end
helpers TypographyHelpers
# Build-specific configuration
configure :build do
activate :gzip
activate :minify_css
activate :minify_javascript
activate :asset_hash
end