-
Notifications
You must be signed in to change notification settings - Fork 25
/
config.rb
124 lines (103 loc) · 3.23 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
###
# Page options, layouts, aliases and proxies
###
# Per-page layout changes:
#
# With no layout
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
# With alternative layout
# page "/path/to/file.html", layout: :otherlayout
# 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" }
# General configuration
###
# Helpers
###
# Methods defined in the helpers block are available in templates
helpers do
def page_link(filename, link_text = nil)
qualified_filename = "/#{filename}.html"
page = sitemap.find_resource_by_path(qualified_filename)
link_text ||= page.data[:title]
link_to link_text, qualified_filename
end
def twitter_user(username)
content_tag( :a, :href => "https://twitter.com/#{username}" ) {
'@' + username.to_s
}
end
def clearer(content = nil)
content_tag( :div, :class => 'clear' ) { content.to_s }
end
def toc
@toc ||= TOC.from_file('lib/toc.txt')
end
def nav_list(options = {})
options.merge!({
:current_section => current_page.data.title.dasherize,
:link_path_template => current_page.data.nav_list_links || '/sections/%s.html',
})
toc.nav_list(options)
end
end
class String
def dasherize
strip.downcase.gsub('ö', 'o').gsub(/[^a-z0-9]+/, '-').gsub(/(^-|-$)/, '')
end
end
# Or, you can do the module thing. Just keep in mind that these won't
# get reloaded automatically, so you'll need to restart middleman.
require_relative 'lib/site_helper'
module SiteHelper
def section_link(section_title, text = nil, opts = {})
path = section_path(section_title)
# TODO: actually link to section
text ||= section_title
content_tag( :a, opts.reverse_merge(href: path) ) { text }
end
def linear_nav_links
title = current_page.data.title
prev_section_title, next_section_title = toc.prev_and_next(title)
clearer + content_tag(:div, :class => 'linear_nav_links') {
prev_section_link(prev_section_title) +
next_section_link(next_section_title)
}
end
def prev_section_link(section_title = nil, html_options = {})
return "" if section_title.nil?
href = section_path(section_title)
html_options = html_options.merge(:href => href, :class => 'prev')
"".tap { |s|
s << content_tag(:a, html_options) { "← " + section_title }
s << tag(:link, :rel => 'prev', :href => href)
}
end
def next_section_link(section_title = nil, html_options = {})
return "" if section_title.nil?
href = section_path(section_title)
html_options = html_options.merge(:href => href, :class => 'next')
"".tap { |s|
s << content_tag(:a, html_options) { section_title + " →" }
s << tag(:link, :rel => 'next', :href => href)
}
end
def section_path(section_title)
path = toc.section_path(section_title)
if current_page.path =~ /epic/
'#%s' % path
else
'/sections/%s.html' % path
end
end
end
helpers SiteHelper
# Build-specific configuration
configure :build do
# Minify CSS on build
# activate :minify_css
# Minify Javascript on build
# activate :minify_javascript
end