Skip to content

Commit 264d7db

Browse files
committed
Properly sort search-results.json
1 parent 813bf15 commit 264d7db

File tree

2 files changed

+64
-40
lines changed

2 files changed

+64
-40
lines changed

lib/search_generator.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def run(content, params={})
1616

1717
$search_file_contents[:pages] << page
1818

19+
$search_file_contents[:pages] = merge_sort($search_file_contents[:pages])
20+
1921
write_search_file
2022

2123
content
@@ -28,4 +30,26 @@ def write_search_file
2830
puts 'WARNING: cannot write search file.'
2931
end
3032
end
33+
34+
private
35+
36+
# basically we need a merge sort for elements like "/v3/orgs." Otherwise,
37+
# nanoc puts "/v3/orgs/mebers" before "/v3/orgs." Children should respect their
38+
# parents, yo.
39+
def merge_sort(a)
40+
return a if a.size <= 1
41+
l, r = split_array(a)
42+
result = combine(merge_sort(l), merge_sort(r))
43+
end
44+
45+
def split_array(a)
46+
mid = (a.size / 2).round
47+
[a.take(mid), a.drop(mid)]
48+
end
49+
50+
def combine(a, b)
51+
return b.empty? ? a : b if a.empty? || b.empty?
52+
smallest = a.first[:url] <= b.first[:url] ? a.shift : b.shift
53+
combine(a, b).unshift(smallest)
54+
end
3155
end

static/search-index.json

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
{
22
"pages": [
33
{
4-
"url": "/v3/activity/events/types/",
5-
"title": "Event types",
4+
"url": "/v3/",
5+
"title": "GitHub API v3",
6+
"section": "API"
7+
},
8+
{
9+
"url": "/v3/activity/",
10+
"title": "Activity",
611
"section": "API"
712
},
813
{
914
"url": "/v3/activity/events/",
1015
"title": "Events",
1116
"section": "API"
1217
},
18+
{
19+
"url": "/v3/activity/events/types/",
20+
"title": "Event types",
21+
"section": "API"
22+
},
1323
{
1424
"url": "/v3/activity/feeds/",
1525
"title": "Feeds",
@@ -35,11 +45,6 @@
3545
"title": "Repository Watching",
3646
"section": "API"
3747
},
38-
{
39-
"url": "/v3/activity/",
40-
"title": "Activity",
41-
"section": "API"
42-
},
4348
{
4449
"url": "/v3/auth/",
4550
"title": "Authentication",
@@ -55,14 +60,19 @@
5560
"title": "GitHub Emojis API",
5661
"section": "API"
5762
},
63+
{
64+
"url": "/v3/gists/",
65+
"title": "Gists",
66+
"section": "API"
67+
},
5868
{
5969
"url": "/v3/gists/comments/",
6070
"title": "Gist Comments",
6171
"section": "API"
6272
},
6373
{
64-
"url": "/v3/gists/",
65-
"title": "Gists",
74+
"url": "/v3/git/",
75+
"title": "Git",
6676
"section": "API"
6777
},
6878
{
@@ -96,13 +106,13 @@
96106
"section": "API"
97107
},
98108
{
99-
"url": "/v3/git/",
100-
"title": "Git",
109+
"url": "/v3/gitignore/",
110+
"title": "Gitignore templates",
101111
"section": "API"
102112
},
103113
{
104-
"url": "/v3/gitignore/",
105-
"title": "Gitignore templates",
114+
"url": "/v3/issues/",
115+
"title": "Issues",
106116
"section": "API"
107117
},
108118
{
@@ -130,11 +140,6 @@
130140
"title": "Issue Milestones",
131141
"section": "API"
132142
},
133-
{
134-
"url": "/v3/issues/",
135-
"title": "Issues",
136-
"section": "API"
137-
},
138143
{
139144
"url": "/v3/markdown/",
140145
"title": "Markdown Rendering",
@@ -160,6 +165,11 @@
160165
"title": "OAuth",
161166
"section": "API"
162167
},
168+
{
169+
"url": "/v3/orgs/",
170+
"title": "Organizations",
171+
"section": "API"
172+
},
163173
{
164174
"url": "/v3/orgs/members/",
165175
"title": "Organization Members",
@@ -171,8 +181,8 @@
171181
"section": "API"
172182
},
173183
{
174-
"url": "/v3/orgs/",
175-
"title": "Organizations",
184+
"url": "/v3/pulls/",
185+
"title": "Pull Requests",
176186
"section": "API"
177187
},
178188
{
@@ -181,13 +191,13 @@
181191
"section": "API"
182192
},
183193
{
184-
"url": "/v3/pulls/",
185-
"title": "Pull Requests",
194+
"url": "/v3/rate_limit/",
195+
"title": "GitHub Rate Limit API",
186196
"section": "API"
187197
},
188198
{
189-
"url": "/v3/rate_limit/",
190-
"title": "GitHub Rate Limit API",
199+
"url": "/v3/repos/",
200+
"title": "Repos",
191201
"section": "API"
192202
},
193203
{
@@ -251,8 +261,8 @@
251261
"section": "API"
252262
},
253263
{
254-
"url": "/v3/repos/",
255-
"title": "Repos",
264+
"url": "/v3/search/",
265+
"title": "Search",
256266
"section": "API"
257267
},
258268
{
@@ -261,13 +271,13 @@
261271
"section": "API"
262272
},
263273
{
264-
"url": "/v3/search/",
265-
"title": "Search",
274+
"url": "/v3/troubleshooting/",
275+
"title": "Troubleshooting",
266276
"section": "API"
267277
},
268278
{
269-
"url": "/v3/troubleshooting/",
270-
"title": "Troubleshooting",
279+
"url": "/v3/users/",
280+
"title": "Users",
271281
"section": "API"
272282
},
273283
{
@@ -284,16 +294,6 @@
284294
"url": "/v3/users/keys/",
285295
"title": "User Public Keys",
286296
"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"
297297
}
298298
]
299299
}

0 commit comments

Comments
 (0)