Skip to content

Commit 813bf15

Browse files
committed
Generate search results as part of the build
1 parent cfe006b commit 813bf15

File tree

3 files changed

+304
-42
lines changed

3 files changed

+304
-42
lines changed

Rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ compile '/feed/' do
2222
end
2323

2424
compile '/v3/*' do
25+
filter :search
2526
filter :erb
2627
filter :kramdown, :toc_levels => [2]
2728
filter :colorize_syntax,

lib/search_generator.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'json'
2+
3+
class SearchFilter < Nanoc::Filter
4+
identifier :search
5+
type :text
6+
7+
$search_file_path = File.join(Dir.pwd, "static", "search-index.json")
8+
$search_file_contents = { :pages => [] }
9+
10+
def initialize(hash = {})
11+
super
12+
end
13+
14+
def run(content, params={})
15+
page = { :url => @item.identifier, :title => @item[:title].split("|")[0].strip, :section => "API" }
16+
17+
$search_file_contents[:pages] << page
18+
19+
write_search_file
20+
21+
content
22+
end
23+
24+
def write_search_file
25+
begin
26+
File.open($search_file_path, 'w') {|f| f.write(JSON.pretty_generate($search_file_contents)) }
27+
rescue
28+
puts 'WARNING: cannot write search file.'
29+
end
30+
end
31+
end

static/search-index.json

Lines changed: 272 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,299 @@
11
{
2-
"pages" : [
2+
"pages": [
33
{
4-
"url" : "/v3/repos/",
5-
"title" : "Repositories",
6-
"section" : "API"
4+
"url": "/v3/activity/events/types/",
5+
"title": "Event types",
6+
"section": "API"
77
},
88
{
9-
"url" : "/v3/media/",
10-
"title" : "Media Types",
11-
"section" : "API/Overview"
9+
"url": "/v3/activity/events/",
10+
"title": "Events",
11+
"section": "API"
1212
},
1313
{
14-
"url" : "/v3/activity/",
15-
"title" : "Activity",
16-
"section" : "API"
14+
"url": "/v3/activity/feeds/",
15+
"title": "Feeds",
16+
"section": "API"
1717
},
1818
{
19-
"url" : "/v3/activity/events/",
20-
"title" : "Events",
21-
"section" : "API/Activity"
19+
"url": "/v3/activity/notifications/",
20+
"title": "Notifications",
21+
"section": "API"
2222
},
2323
{
24-
"url" : "/v3/activity/events/types/",
25-
"title" : "Event Types",
26-
"section" : "API/Activity"
24+
"url": "/v3/activity/settings/",
25+
"title": "Notification Settings",
26+
"section": "API"
2727
},
2828
{
29-
"url" : "/v3/activity/notifications/",
30-
"title" : "Notifications",
31-
"section" : "API/Activity"
29+
"url": "/v3/activity/starring/",
30+
"title": "Repository Starring",
31+
"section": "API"
3232
},
3333
{
34-
"url" : "/v3/gists/",
35-
"title" : "Gists",
36-
"section" : "API"
34+
"url": "/v3/activity/watching/",
35+
"title": "Repository Watching",
36+
"section": "API"
3737
},
3838
{
39-
"url" : "/v3/git/commits/",
40-
"title" : "Commits",
41-
"section" : "API/Git Data"
39+
"url": "/v3/activity/",
40+
"title": "Activity",
41+
"section": "API"
4242
},
4343
{
44-
"url" : "/v3/issues/comments/",
45-
"title" : "Comments",
46-
"section" : "API/Issues"
44+
"url": "/v3/auth/",
45+
"title": "Authentication",
46+
"section": "API"
4747
},
4848
{
49-
"url" : "/v3/issues/events/",
50-
"title" : "Events",
51-
"section" : "API/Issues"
49+
"url": "/v3/changelog/",
50+
"title": "GitHub API Changelog",
51+
"section": "API"
5252
},
5353
{
54-
"url" : "/v3/repos/comments/",
55-
"title" : "Comments",
56-
"section" : "API/Repositories"
54+
"url": "/v3/emojis/",
55+
"title": "GitHub Emojis API",
56+
"section": "API"
5757
},
5858
{
59-
"url" : "/v3/repos/contents/",
60-
"title" : "Contents",
61-
"section" : "API/Repositories"
59+
"url": "/v3/gists/comments/",
60+
"title": "Gist Comments",
61+
"section": "API"
6262
},
6363
{
64-
"url" : "/v3/search/#search-repositories",
65-
"title" : "Repositories",
66-
"section" : "API/Search"
64+
"url": "/v3/gists/",
65+
"title": "Gists",
66+
"section": "API"
67+
},
68+
{
69+
"url": "/v3/git/blobs/",
70+
"title": "Git Blobs",
71+
"section": "API"
72+
},
73+
{
74+
"url": "/v3/git/commits/",
75+
"title": "Git Commits",
76+
"section": "API"
77+
},
78+
{
79+
"url": "/v3/git/import/",
80+
"title": "Git Import",
81+
"section": "API"
82+
},
83+
{
84+
"url": "/v3/git/refs/",
85+
"title": "Git Refs",
86+
"section": "API"
87+
},
88+
{
89+
"url": "/v3/git/tags/",
90+
"title": "Git Tags",
91+
"section": "API"
92+
},
93+
{
94+
"url": "/v3/git/trees/",
95+
"title": "Git Trees",
96+
"section": "API"
97+
},
98+
{
99+
"url": "/v3/git/",
100+
"title": "Git",
101+
"section": "API"
102+
},
103+
{
104+
"url": "/v3/gitignore/",
105+
"title": "Gitignore templates",
106+
"section": "API"
107+
},
108+
{
109+
"url": "/v3/issues/assignees/",
110+
"title": "Issue Assignees",
111+
"section": "API"
112+
},
113+
{
114+
"url": "/v3/issues/comments/",
115+
"title": "Issue Comments",
116+
"section": "API"
117+
},
118+
{
119+
"url": "/v3/issues/events/",
120+
"title": "Issue Events",
121+
"section": "API"
122+
},
123+
{
124+
"url": "/v3/issues/labels/",
125+
"title": "Issue Labels",
126+
"section": "API"
127+
},
128+
{
129+
"url": "/v3/issues/milestones/",
130+
"title": "Issue Milestones",
131+
"section": "API"
132+
},
133+
{
134+
"url": "/v3/issues/",
135+
"title": "Issues",
136+
"section": "API"
137+
},
138+
{
139+
"url": "/v3/markdown/",
140+
"title": "Markdown Rendering",
141+
"section": "API"
142+
},
143+
{
144+
"url": "/v3/media/",
145+
"title": "Custom Media Types",
146+
"section": "API"
147+
},
148+
{
149+
"url": "/v3/meta/",
150+
"title": "GitHub Meta API",
151+
"section": "API"
152+
},
153+
{
154+
"url": "/v3/misc/",
155+
"title": "Miscellaneous",
156+
"section": "API"
157+
},
158+
{
159+
"url": "/v3/oauth/",
160+
"title": "OAuth",
161+
"section": "API"
162+
},
163+
{
164+
"url": "/v3/orgs/members/",
165+
"title": "Organization Members",
166+
"section": "API"
167+
},
168+
{
169+
"url": "/v3/orgs/teams/",
170+
"title": "Organization Teams",
171+
"section": "API"
172+
},
173+
{
174+
"url": "/v3/orgs/",
175+
"title": "Organizations",
176+
"section": "API"
177+
},
178+
{
179+
"url": "/v3/pulls/comments/",
180+
"title": "Pull Request Comments",
181+
"section": "API"
182+
},
183+
{
184+
"url": "/v3/pulls/",
185+
"title": "Pull Requests",
186+
"section": "API"
187+
},
188+
{
189+
"url": "/v3/rate_limit/",
190+
"title": "GitHub Rate Limit API",
191+
"section": "API"
192+
},
193+
{
194+
"url": "/v3/repos/collaborators/",
195+
"title": "Repo Collaborators",
196+
"section": "API"
197+
},
198+
{
199+
"url": "/v3/repos/comments/",
200+
"title": "Repo Comments",
201+
"section": "API"
202+
},
203+
{
204+
"url": "/v3/repos/commits/",
205+
"title": "Repo Commits",
206+
"section": "API"
207+
},
208+
{
209+
"url": "/v3/repos/contents/",
210+
"title": "Repo Contents",
211+
"section": "API"
212+
},
213+
{
214+
"url": "/v3/repos/downloads/",
215+
"title": "Repo Downloads",
216+
"section": "API"
217+
},
218+
{
219+
"url": "/v3/repos/forks/",
220+
"title": "Repo Forks",
221+
"section": "API"
222+
},
223+
{
224+
"url": "/v3/repos/hooks/",
225+
"title": "Repo Hooks",
226+
"section": "API"
227+
},
228+
{
229+
"url": "/v3/repos/keys/",
230+
"title": "Repo Deploy Keys",
231+
"section": "API"
232+
},
233+
{
234+
"url": "/v3/repos/merging/",
235+
"title": "Repo Merging",
236+
"section": "API"
237+
},
238+
{
239+
"url": "/v3/repos/releases/",
240+
"title": "Releases",
241+
"section": "API"
242+
},
243+
{
244+
"url": "/v3/repos/statistics/",
245+
"title": "Repo Statistics",
246+
"section": "API"
247+
},
248+
{
249+
"url": "/v3/repos/statuses/",
250+
"title": "Statuses",
251+
"section": "API"
252+
},
253+
{
254+
"url": "/v3/repos/",
255+
"title": "Repos",
256+
"section": "API"
257+
},
258+
{
259+
"url": "/v3/search/legacy/",
260+
"title": "Legacy Search",
261+
"section": "API"
262+
},
263+
{
264+
"url": "/v3/search/",
265+
"title": "Search",
266+
"section": "API"
267+
},
268+
{
269+
"url": "/v3/troubleshooting/",
270+
"title": "Troubleshooting",
271+
"section": "API"
272+
},
273+
{
274+
"url": "/v3/users/emails/",
275+
"title": "User Emails",
276+
"section": "API"
277+
},
278+
{
279+
"url": "/v3/users/followers/",
280+
"title": "User Followers",
281+
"section": "API"
282+
},
283+
{
284+
"url": "/v3/users/keys/",
285+
"title": "User Public Keys",
286+
"section": "API"
287+
},
288+
{
289+
"url": "/v3/users/",
290+
"title": "Users",
291+
"section": "API"
292+
},
293+
{
294+
"url": "/v3/",
295+
"title": "GitHub API v3",
296+
"section": "API"
67297
}
68-
]
69-
}
298+
]
299+
}

0 commit comments

Comments
 (0)