-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.rb
120 lines (100 loc) · 2.79 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
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
#set :markdown_engine, :redcarpet
set :markdown, fenced_code_blocks: true, smartypants: true, footnotes: false
activate :autoprefixer
activate :inline_svg
activate :external_pipeline, {
name: :webpack,
command: build? ? 'yarn build' : 'yarn start',
source: 'tmp/build'
}
activate :blog do |blog|
# This will add a prefix to all links, template references and source paths
# blog.prefix = "blog"
blog.permalink = "{title}"
#blog.permalink = "blog/{year}/{title}.html"
blog.sources = "posts/{year}-{month}-{day}-{title}.html"
blog.taglink = "{tag}.html"
blog.layout = "post"
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"
blog.paginate = true
# blog.page_link = "page/{num}"
end
activate :directory_indexes # must be activated after the blog
helpers do
def host_with_port
if app.development?
"http://localhost:4567"
else
"https://shanson.co"
end
end
def image_url(path)
"#{host_with_port}#{image_path(path)}"
end
def lazy_image_tag(path, options = {})
image_tag("placeholder.png", options.merge({
data: { src: image_path(path) },
class: "lazy #{options[:class]}".strip
}))
end
def article_summary(article)
if article.data.excerpt.present?
article.data.excerpt
else
article.summary
end
end
def human_date(date)
date.strftime("%b %-d, %Y")
end
# don't have to worry about published: false here because those aren't
# built by default
def non_draft_articles(articles)
articles.select { |a| !a.data[:draft] }
end
def articles_for_tag(articles, tag)
non_draft_articles(articles)
.select { |a| a.data[:tags].include?(tag.to_s) }
end
# in minutes
def read_length(content)
words_per_minute = 200.0
num_words = content.split.size
(num_words / words_per_minute).ceil
end
def article_source(url)
host = URI.parse(url).host.downcase
host.start_with?("www.") ? host[4..-1] : host
end
def article_body(article)
if article.data.target.present?
link = link_to article.data.target, class: "arrow-link" do
%(
Read more on
#{article_source article.data.target}
#{inline_svg "ionicons/ios-arrow-round-forward.svg", class: "icon-arrow-round-forward"}
)
end
"#{article.body} <p>#{link}</p>"
else
article.body
end
end
end
configure :development do
activate :livereload
end
configure :build do
activate :asset_hash
activate :minify_css
end