forked from DataDog/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rules
241 lines (197 loc) · 5.7 KB
/
Rules
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
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# A few helpful tips about the Rules file:
#
# * The string given to #compile and #route are matching patterns for
# identifiers--not for paths. Therefore, you can’t match on extension.
#
# * The order of rules is important: for each item, only the first matching
# rule is applied.
#
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
# “content/about.html”). To select all children, grandchildren, … of an
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
require './lib/rule_helper'
require './lib/generate_ja_pages'
require 'octokit'
preprocess do
create_redirect_pages
if ENV.has_key?('JPASSIST')
$jpassist = true
list_update_pages
else
$jpassist = false
end
generate_ja_pages
# def rchomp(sep = $/)
# self.start_with?(sep) ? self[sep.size..-1] : self
# end
# def snippetizer(item)
# if item["has_snippets"] == "True"
# doc = Nokogiri::HTML.fragment(item.content)
# doc.css(".snippetizer").each do |snippet|
# print snippet
# # # id = @item.identifier.gsub("(/(.+)/", "$&")
# id = item.identifier.chomp('/').rchomp('/') + '-' + snippet['id']
# # # print id
# # # print snippet.content
# new_snippet = {id => snippet.content}
# print new_snippet
# $global_snippets.merge(new_snippet)
# end
# end
# end
if ENV.has_key?('NANOCRUNSLOW')
$goodconnection = false
else
$goodconnection = true
end
if ENV.has_key?('github_personal_token') && $goodconnection
$client = $client ||= Octokit::Client.new(:access_token => ENV['github_personal_token'])
$client.user.login
end
$cbfingerprints = get_cache_bust_fingerprints()
$en_local_hash = get_local_hash('en')
$ja_local_hash = get_local_hash('ja')
$example_items = collect_example_items()
$video_items = collect_video_items()
$ja_example_items = collect_ja_example_items()
$ja_video_items = collect_ja_video_items()
$integration_items = collect_integration_items()
$ja_integration_items = collect_ja_integration_items()
$guide_items = collect_guide_items()
$ja_guide_items = collect_ja_guide_items()
create_tag_pages($example_items,{:identifier => "/examples/%%tag%%/"})
create_tag_pages($video_items,{:identifier => "/videos/%%tag%%/"})
create_tag_pages($ja_example_items,{:identifier => "/ja/examples/%%tag%%/", :template => "example-subindex-ja"})
create_tag_pages($ja_video_items,{:identifier => "/ja/videos/%%tag%%/", :template => "video-subindex-ja"})
@items.each do |item|
language = "en"
otherlang = "ja"
langpath = ""
phrases = $en_local_hash
if item.identifier.match('/ja/')
language = "ja"
otherlang = ""
langpath = "/ja"
phrases = $ja_local_hash
end
item["language"] = language
item["otherlang"] = otherlang
item["langpath"] = langpath
phrases.each do | key, val |
item[key] = val
end
# snippetizer(item)
end
end
compile '/partials/*' do
filter :erb
end
route '/partials/*' do
nil
end
compile 'sitemap' do
filter :erb
end
compile '/tipuesearch/tipuesearch_content/' do
filter :erb
end
compile '/tipuesearch/*/' do
end
compile '/static/bootstrap/scss/*' do
end
compile '/static/bootstrap/scss/mixins/*' do
end
# compile '/static/bootstrap/scss/*' do
# filter :sass, syntax: :scss, style: :compressed
# filter :autoprefixer
# end
compile '/static/css/*' do
unless item.identifier.start_with?('/static/css/_')
filter :sass, syntax: :scss, style: :compressed
filter :autoprefixer
end
end
compile '/static/*' do
# if @item.identifier.match('cachebustercss')
# filter :erb
# end
end
compile '*' do
unless item.binary? or item[:title] == 'redirect'
filter :erb
case item[:extension]
when 'md'
filter :kramdown,
:syntax_highligher => 'rouge',
:syntax_highlighter_opts => { :line_numbers => false }
else
filter :colorize_syntax, :default_colorizer => :rouge, colorizers: {
javascript: :rouge,
console: :rouge,
python: :rouge,
ruby: :rouge,
pycon: :rouge,
json: :rouge
}
end
# filter :kramdown
id = @item.identifier
unless id.match('/api/')
filter :header_links
filter :insert_common_links
end
case
# when id.match('/ja/guides/basic_agent_usage/')
# layout 'basic_agent_usage-ja'
when id.match('/guides/basic_agent_usage/')
layout 'basic_agent_usage'
when id.match('/integrations') && @item[:kind] == 'integration'
layout 'integration_layout'
else
if item[:title] != 'redirect'
layout 'default'
end
end
end
end
route 'sitemap' do
item.identifier.chop + '.xml'
end
route '/tipuesearch/*' do
unless item.identifier.include?('#')
"/tipuesearch/#{basename(item.attributes[:filename])}.js"
end
end
route '/static/favicon/' do
'/favicon.ico'
end
route '/static/bootstrap/scss/*' do
nil
end
# route '/static/bootstrap/scss/mixins/*' do
# nil
# end
# route '/static/bootstrap/scss/*' do
# '/static/bootstrap/css/' + File.basename(item.identifier) + '.css'
# end
route '/static/css/*' do
unless item.identifier.start_with?('/static/css/_')
fp = fingerprint(item[:filename])
# item.identifier.chop + '.css'
item.identifier.gsub(/\/$/, '') + fp + '.css'
end
end
route '/static/CNAME/' do
'/CNAME'
end
route '/static/*' do
item.identifier.chop + '.' + item[:extension]
end
route '*' do
# Write item with identifier /foo/ to /foo/index.html
item.identifier.downcase + 'index.html'
end
layout '*', :erb