jekyll-github-pages-search 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gh_api_search.js +87 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c8189efe24691aee02d758b97950c5213722770
|
4
|
+
data.tar.gz: 0d3b204d8c419a23446263e22d8472b76b9860ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0929e288eea8b3d0a57ad86989157fd7308c555ebc150f7429e6c76958220a172d0fe79facfeed162a72a82bc1f94699c1e24ef41de24d41037558a05711c216
|
7
|
+
data.tar.gz: 43a3abdc925e81a269f6c136acf36540ce29981025eef6f9802ca62d80f7d9c05ca52c1f93a59179b0786a9e6cc20f8c8ae95d90ccb26572de9dcaa1834baa57
|
@@ -0,0 +1,87 @@
|
|
1
|
+
GITHUB_API_V3_SEARCH_URL = "https://api.github.com/search/pages";
|
2
|
+
PLUGIN_PREFIX = "data-gh-pages-search-";
|
3
|
+
|
4
|
+
// wait for jQuery to be ready
|
5
|
+
$( document ).ready(function() {
|
6
|
+
// when the form is submitted...
|
7
|
+
$("#gh-pages-search-button").click(function() {
|
8
|
+
// find the input bar, and grab its text
|
9
|
+
var searchInput = $("#gh-pages-search-input"),
|
10
|
+
query = searchInput.val(),
|
11
|
+
// also, determine from the attributes which repository we're searching on,
|
12
|
+
// and whether we are highlighting results
|
13
|
+
within = {{ in }},
|
14
|
+
path = {{ path }},
|
15
|
+
authors = {{ authors }},
|
16
|
+
tags = {{ tags }},
|
17
|
+
repo = {{ repo }},
|
18
|
+
user = {{ user }},
|
19
|
+
highlight = {{ highlight }};
|
20
|
+
|
21
|
+
// configure the request headers appropriately
|
22
|
+
var headers = ["application/vnd.github.the-vision-preview"];
|
23
|
+
if (highlight !== undefined)
|
24
|
+
headers.push("application/vnd.github.v3.text-match+json");
|
25
|
+
|
26
|
+
// initiate the GET request to the GitHub API.
|
27
|
+
$.ajax({
|
28
|
+
type: "GET",
|
29
|
+
headers: { "Accept": headers.join(",") },
|
30
|
+
accepts: { text: "application/json" },
|
31
|
+
dataType: "json",
|
32
|
+
// this is the URL we'll be GETing. be sure to read the developer docs for
|
33
|
+
// more information on the various parameters you can pass
|
34
|
+
url: GITHUB_API_V3_SEARCH_URL + "?q=" + [query, within, path, authors, tags, repo, user, highlight].join("+"),
|
35
|
+
success: function(msg) {
|
36
|
+
console.log(msg);
|
37
|
+
},
|
38
|
+
error: function(err) {
|
39
|
+
console.error(err);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
$( document ).ajaxComplete(function( event, xhr, settings ) {
|
46
|
+
var items = xhr.responseJSON.items, blobOfText = "";
|
47
|
+
|
48
|
+
// no results? let people know.
|
49
|
+
if (items.length == 0) {
|
50
|
+
blobOfText = "<h6>No results.</h6>"
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
blobOfText = "<h2>Found " + xhr.responseJSON.total_count + " matches, here's " + items.length + " of them.";
|
54
|
+
|
55
|
+
// iterate over every item we have...
|
56
|
+
for (var i = 0; i < items.length; i++) {
|
57
|
+
// first, let's present the item's title
|
58
|
+
blobOfText += "<h3>" + items[i].titles[0].text + "</h3>";
|
59
|
+
|
60
|
+
// next, since we asked for highlighting, we go through all the highlight results
|
61
|
+
var matches = items[i].text_matches;
|
62
|
+
for (var j = 0; j < matches.length; j++) {
|
63
|
+
var highlight_matches = matches[j].matches,
|
64
|
+
fragment = matches[j].fragment;
|
65
|
+
// we're going to look at each fragment (chunk of text) that matched our query
|
66
|
+
for (var k = 0; k < highlight_matches.length; k++) {
|
67
|
+
// each highlight within that chunk of text is represented by "start" and "stop"
|
68
|
+
// indices. we must also remember to shift these indices over each time we
|
69
|
+
// change the fragment text below
|
70
|
+
var indices = highlight_matches[k].indices,
|
71
|
+
shift_factor = ("<strong></strong>".length * k);
|
72
|
+
|
73
|
+
// here, we construct the fragment of matched text. we slice everything
|
74
|
+
// before the match, add some "strong" tags to the matched text, and
|
75
|
+
// then continue with the rest of the fragment.
|
76
|
+
fragment = fragment.substring(0, indices[0] + shift_factor) +
|
77
|
+
"<strong>" + highlight_matches[k].text + "</strong>" +
|
78
|
+
fragment.substring(indices[1] + shift_factor);
|
79
|
+
}
|
80
|
+
blobOfText += "<p>" + fragment + "</h1>";
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
// voila, set the results
|
86
|
+
$("#results").html(blobOfText);
|
87
|
+
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-github-pages-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen J. Torikian
|
@@ -73,6 +73,7 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- lib/jekyll-github-pages-search.rb
|
76
|
+
- lib/gh_api_search.js
|
76
77
|
homepage: https://github.com/gjtorikian/jekyll-github-pages-search
|
77
78
|
licenses:
|
78
79
|
- MIT
|