Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Commitf3e2dd2

Browse files
committed
Merge pull request#55 from github/quick-jump-search
Quick jump search
2 parents399a586 +d162731 commitf3e2dd2

File tree

14 files changed

+711
-158
lines changed

14 files changed

+711
-158
lines changed

‎Rules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
1111
# because “*” matches zero or more characters.
1212

13+
# Reset search-index by deleting it every time
14+
preprocessdo
15+
File.delete("output/search-index.json")
16+
end
17+
1318
compile'/static/*'do
1419
end
1520

@@ -22,6 +27,7 @@ compile '/feed/' do
2227
end
2328

2429
compile'/v3/*'do
30+
filter:search
2531
filter:erb
2632
filter:kramdown,:toc_levels=>[2]
2733
filter:colorize_syntax,

‎content/v3/auth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title:Authentication | GitHub API
2+
title:OtherAuthentication Methods | GitHub API
33
---
44

55
#Other Authentication Methods

‎content/v3/git.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title:Git | GitHub API
2+
title:GitData| GitHub API
33
---
44

55
#Git Data

‎content/v3/pulls/comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title:Pull Request Comments | GitHub API
2+
title:Review Comments | GitHub API
33
---
44

55
#Review Comments

‎layouts/header.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
<li><ahref="/v3/"class="nav-api">API</a></li>
88
<li><ahref="/changes/"class="nav-blog">Blog</a></li>
99
<li><ahref="https://github.com/contact">Support</a></li>
10+
<liid="search-container">
11+
<inputtype="text"id="searchfield"autocomplete="off"autocorrect="off"autocapitalize="off"spellcheck="false"/><labelclass="search-placeholder">Search</label>
12+
<divclass="cancel-search"></div>
13+
<ulid="search-results">
14+
15+
</ul>
16+
</li>
1017
</ul>
1118
</div>
1219
</div><!-- #header -->

‎lib/search_generator.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
require'json'
2+
require'nokogiri'
3+
4+
classSearchFilter <Nanoc::Filter
5+
identifier:search
6+
type:text
7+
8+
$search_file_path=File.join(Dir.pwd,"static","search-index.json")
9+
$search_file_contents={:pages=>[]}
10+
11+
sidebar=File.open(File.join(Dir.pwd,"layouts","sidebar.html"))
12+
$sidebar_doc=Nokogiri::HTML(sidebar)
13+
sidebar.close
14+
15+
defrun(content,params={})
16+
# uses nokogiri to determine parent section name
17+
containing_li_text= $sidebar_doc.xpath("//a[@href='#{@item.identifier}']/../../../h3/a[2]/text()")
18+
19+
# we're looking at an overview page
20+
containing_li_text= $sidebar_doc.xpath("//a[@href='#{@item.identifier}']/text()")ifcontaining_li_text.empty?
21+
22+
page={:url=>@item.identifier,:title=>@item[:title].split("|")[0].strip,:section=>"API/#{containing_li_text}"}
23+
24+
$search_file_contents[:pages] <<page
25+
$search_file_contents[:pages]=merge_sort($search_file_contents[:pages])
26+
27+
write_search_file
28+
29+
content
30+
end
31+
32+
defwrite_search_file
33+
begin
34+
File.open($search_file_path,'w'){|f|f.write(JSON.pretty_generate($search_file_contents))}
35+
rescue
36+
puts'WARNING: cannot write search file.'
37+
end
38+
end
39+
40+
private
41+
42+
# basically we need a merge sort for elements like "/v3/orgs." Otherwise,
43+
# nanoc puts "/v3/orgs/mebers" before "/v3/orgs." Children should respect their
44+
# parents, yo.
45+
defmerge_sort(a)
46+
returnaifa.size <=1
47+
l,r=split_array(a)
48+
result=combine(merge_sort(l),merge_sort(r))
49+
end
50+
51+
defsplit_array(a)
52+
mid=(a.size /2).round
53+
[a.take(mid),a.drop(mid)]
54+
end
55+
56+
defcombine(a,b)
57+
returnb.empty? ?a :bifa.empty? ||b.empty?
58+
smallest=a.first[:url] <=b.first[:url] ?a.shift :b.shift
59+
combine(a,b).unshift(smallest)
60+
end
61+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp