-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.rb
202 lines (177 loc) · 5.37 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
Dotenv.load
Bundler.require
require './lib/middleman/renderers/custom'
###
# Blog settings
###
lang = (ENV['MM_LANG'] || 'ja').to_sym
cname = ({
en: 'ngs.io',
ja: 'ja.ngs.io'
})[lang]
Time.zone = "Asia/Tokyo"
activate :directory_indexes
activate :syntax
activate :i18n, langs: [lang]
# activate :livereload
set :markdown_engine, :custom
set :markdown_engine_prefix, ::Middleman::Renderers
set :markdown, :fenced_code_blocks => true, :smartypants => true, :autolink => true, :tables => true, :with_toc_data => true
set :build_dir, ENV.fetch('BUILD_DIR', "build-#{lang}")
set :partials_dir, 'partials'
set :site_url, "https://#{cname}"
activate :blog do |blog|
blog.permalink = "{year}/{month}/{day}/{title}/index.html"
blog.sources = "#{lang}/{year}-{month}-{day}-{title}.html"
blog.taglink = "t/{tag}/index.html"
blog.layout = "article"
blog.summary_separator = /(READMORE)/
blog.summary_length = 500
blog.year_link = "{year}/index.html"
blog.month_link = "{year}/{month}/index.html"
blog.day_link = "{year}/{month}/{day}/index.html"
blog.default_extension = ".md"
blog.tag_template = "tag.html"
blog.calendar_template = "calendar.html"
blog.paginate = true
blog.per_page = 10
blog.page_link = "p{num}"
end
if ENV['NO_SIMILAR']
module Middleman::Blog::BlogArticle
def similar_articles
blog_controller.data.articles
end
end
else
activate :similar, tagger: {
mecab: 1,
tags: 3
}
end
page "/feed.xml", layout: false
page "/rss.xml", layout: false
page "/sitemap.xml", layout: false
page "/404.html", directory_index: false
require 'slim'
require 'sass'
require 'coffee-script'
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
ready do
::Middleman::Renderers::MiddlemanRedcarpetHTML.scope = self
def redirect_to path, res
proxy path, 'redirect.html', locals: { url: res.url }, layout: false
end
sitemap.resources.each do|res|
url = res.url
if res.is_a? Middleman::Blog::BlogArticle
redirect_to "blog#{url.sub(%r{/$}, '.html')}", res
redirect_to "blog#{url}index.html", res
proxy "#{url}amp.html", 'amp.html', locals: { article: res }, layout: false, directory_index: false
elsif url.match %r{^/p\d+/$}
redirect_to "blog#{url.sub(%r{p(\d)}, 'page/\1')}index.html", res
elsif url.match %r{^/t/(.+)/$}
redirect_to "blog#{url.sub(%r{t/(.+)}, 'categories/\1')}index.html", res
elsif url.match %r{^/20(\d{2}[\d/]+)/$}
redirect_to "blog#{url}index.html", res
end
end
end
after_configuration do
# https://git.io/vxQ8e
module TagPagesExtension
def link( tag )
safe_tag = safe_parameterize(tag)
safe_tag = URI.encode(tag) if safe_tag == ''
apply_uri_template @tag_link_template, tag: safe_tag
end
end
Middleman::Blog::TagPages.prepend(TagPagesExtension)
end
configure :development do
activate :google_analytics do |ga|
ga.tracking_id = 'UA-XXXXXX-YY'
end
set :asset_host, 'http://127.0.0.1:4567'
end
activate :sprockets
activate :ogp do |ogp|
ogp.namespaces = {
fb: data.send(lang).ogp.fb,
og: data.send(lang).ogp.og,
twitter: data.send(lang).ogp.twitter
}
ogp.base_url = "https://#{cname}"
ogp.blog = true
end
configure :build do
activate :minify_css
activate :minify_javascript
activate :asset_hash, ignore: 'images/**/*', exts: %w(.woff2 .eot .svg .ttf .woff .otf .css .js .jpg .png .gif)
ignore '.DS_Store'
ignore '.*.swp'
ignore '_drafts'
ignore 'redirect.html'
ignore 'amp.html'
set :asset_host, "https://#{cname}"
if lang == :en
ignore '/about/index.ja.html'
ignore '/ja/*'
activate :google_analytics do |ga|
ga.tracking_id = 'UA-200187-32'
end
else
ignore '/about/index.en.html'
ignore '/en/*'
activate :google_analytics do |ga|
ga.tracking_id = 'UA-200187-34'
end
end
activate :favicon_maker, :icons => {
"favicon-hires.png" => [
{ icon: "apple-touch-icon-152x152-precomposed.png" },
{ icon: "apple-touch-icon-144x144-precomposed.png" },
{ icon: "apple-touch-icon-120x120-precomposed.png" },
{ icon: "apple-touch-icon-114x114-precomposed.png" },
{ icon: "apple-touch-icon-76x76-precomposed.png" },
{ icon: "apple-touch-icon-72x72-precomposed.png" },
{ icon: "apple-touch-icon-60x60-precomposed.png" },
{ icon: "apple-touch-icon-57x57-precomposed.png" },
{ icon: "apple-touch-icon-precomposed.png", size: "57x57" },
{ icon: "apple-touch-icon.png", size: "57x57" },
{ icon: "favicon-196x196.png" },
{ icon: "favicon-160x160.png" },
{ icon: "favicon-96x96.png" },
{ icon: "mstile-144x144", format: "png" }
],
"favicon-lores.png" => [
{ icon: "favicon-32x32.png" },
{ icon: "favicon-16x16.png" },
{ icon: "favicon.png", size: "16x16" },
{ icon: "favicon.ico", size: "64x64,32x32,24x24,16x16" }
]
}
end
activate :disqus do |d|
d.shortname = lang == :en ? "ngsio" : "jangsio"
end
helpers do
def alt_lang
I18n.locale.to_s == 'en' ? "ja_JP" : "en_US"
end
def alt_lang_name
I18n.locale.to_s == 'en' ? "日本語" : "English"
end
def alt_host
I18n.locale.to_s == 'en' ? "ja.ngs.io" : "ngs.io"
end
def alt_href
"https://#{alt_host}#{current_resource.url}"
end
def alt_link
link_to %Q{<span class="fal fa-globe"></span> #{alt_lang_name}},
alt_href, href_lang: alt_lang, rel: "alternate"
end
end