-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
142 lines (114 loc) · 3.49 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
###
# 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
require "slim"
# 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" }
# @app.data is a workaround to get an actual array of data within config.rb
case_studies = @app.data["case-studies"]
case_studies.each_with_index do |case_study, index|
proxy "/case-studies/#{case_study["slug"]}.html",
"/case-study.html",
locals: {
case_study: case_study,
next_case_study: case_studies[(index + 1) % case_studies.size],
previous_case_study: case_studies[index - 1]
},
ignore: true
end
# General configuration
# Reload the browser automatically whenever files change
configure :development do
activate :livereload
end
activate :sprockets
# Cloudflare adds a 4 hour cache to all assets by default, which we don't want for
# files like the how we work PDF, and we want even longer times for assets with a hash.
#
# There's no way to use a regex in Cloudflare's Page Rules, so a simple workaround is to add
# this -c0 prefix to the hash, which is unlikely to appear in any other file name.
# Then we configure Cloudflare to cache files matching *-c0*.* for a month, and remove caching
# for all other assets.
activate :asset_hash, prefix: "c0"
activate :directory_indexes
set :url_root, "https://ragnarson.com"
activate :search_engine_sitemap
activate :twitter_oembed do |twitter|
twitter.cache_dir = ".cache/"
end
###
# Helpers
###
helpers do
# Example usage:
#
# image_set_tag_3x "foo_1x.png", alt: "foo"
#
# Will assume there is a 2x and 3x version and provide those automagically.
#
def image_set_tag_3x(source, options = {})
srcset = [2, 3].map { |num|
name = source.sub("_1x.", "_#{num}x.")
"#{image_path(name)} #{num}x"
}.join(", ")
image_tag(source, options.merge(srcset: srcset))
end
def testimonial_image_tag(avatar)
image_tag "project/testimonial/#{avatar}", class: "testimonial-avatar rounded-circle"
end
def logo_image_tag(logo)
image_tag "project/logo/#{logo}"
end
def case_study_image_tag(name, options = {})
image_tag "case-studies/#{name}", options
end
def case_study_summary(summary)
if summary.length < 260
summary
else
"#{summary[0..260]}..."
end
end
def case_study_path(case_study)
"/case-studies/#{case_study["slug"]}.html"
end
def carousel_item_active(index)
"active" if index.zero?
end
def find_project(project_id)
result = data["projects"].select { |record| record["id"] == project_id }
result.any? ? result.first : nil
end
def case_study_style(case_study)
color_start = case_study["color-start"]
color_end = case_study["color-end"]
if color_start && color_end
"background-image: linear-gradient(to top, #{color_start}, #{color_start} 40%, #{color_end});"
end
end
def code_example
data["code-example"]
end
def sitemap_description
data["sitemap-description"]
end
end
configure :build do
activate :minify_css
activate :minify_javascript
activate :autoprefixer
end
activate :deploy do |deploy|
deploy.build_before = true
deploy.deploy_method = :git
deploy.strategy = :force_push
end