origen 0.7.6 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/version.rb +1 -1
- data/templates/nanoc/lib/search_filter.rb +3 -2
- data/templates/nanoc_dynamic/content/search.js.erb +35 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55a0a4e8ad4368f828c29d55fcbd1e2c533276f7
|
4
|
+
data.tar.gz: 4a894872729fbb79801e9c98cb5d9e6cf7f2fc26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0be4fa923fbb1c97519f13c20a82b106cbf7bbeae07646e6a26bca64b6abd9df5fee15ee97452e54461998d48742423f56e44aa6d970b7119928c238f0395680
|
7
|
+
data.tar.gz: 39a0a321e38e7e1ff2f3acb953816428e57f6c961d0f4eace51678c6a54ab9c8dab6b6659c18a5ecaa02a65baaef4af35061a61b648af1734c6ce5c4dcb4634e
|
data/config/version.rb
CHANGED
@@ -10,8 +10,9 @@ class SearchFilter < Nanoc::Filter
|
|
10
10
|
url = assigns[:item_rep].path
|
11
11
|
#first_image = doc.xpath('//img/@src').to_a[0]
|
12
12
|
document = {
|
13
|
-
|
14
|
-
|
13
|
+
# See this next time you need to fix this: https://gist.github.com/LeCoupa/8c305ec8c713aad07b14
|
14
|
+
title: extract_first(doc, '//article/*/h1 | //article/*/h2 | //article/h1 | //article/h2'),
|
15
|
+
subtitle: extract_first(doc, '//article/*/h3 | //article/h3'),
|
15
16
|
body: extract_all(doc, '//article//*/text()'),
|
16
17
|
#img: (first_image.nil?) ? '' : first_image.value(),
|
17
18
|
#alt: extract_values(doc, '//article//img/@alt')
|
@@ -25,46 +25,65 @@ $.getJSON("<%= path '' %>" + "/" + search_json, function(json) {
|
|
25
25
|
});
|
26
26
|
|
27
27
|
$(function() {
|
28
|
-
$("#search button").click(function() {
|
28
|
+
$("#search button").click(function(e) {
|
29
29
|
search(true);
|
30
|
+
return false;
|
30
31
|
});
|
31
32
|
$("#search input").keypress(function(e) {
|
32
|
-
if(e.which
|
33
|
+
if(e.which === 13) {
|
33
34
|
e.preventDefault();
|
34
35
|
search(false);
|
36
|
+
return false;
|
35
37
|
}
|
36
38
|
});
|
37
39
|
})
|
38
40
|
|
39
41
|
function search(go) {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
// If the search index has populated
|
43
|
+
if (window.index) {
|
44
|
+
var term = $("#search input").val();
|
45
|
+
var results = window.index.search(term);
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
if(results && results.length === 1) {
|
48
|
+
window.location = "<%= path "" %>" + results[0].ref + "?highlight=" + escape(term);
|
49
|
+
} else if(results && results.length > 1) {
|
50
|
+
if (go) {
|
51
|
+
window.location = "<%= path "" %>" + results[0].ref + "?highlight=" + escape(term);
|
52
|
+
} else {
|
53
|
+
displayResults(results, term);
|
54
|
+
}
|
50
55
|
} else {
|
51
|
-
|
56
|
+
alert("Found nothing");
|
52
57
|
}
|
53
58
|
} else {
|
54
|
-
|
59
|
+
// Otherwise try again in 200ms
|
60
|
+
setTimeout(search(go), 200);
|
55
61
|
}
|
56
62
|
}
|
57
63
|
|
58
64
|
function displayResults(results, term) {
|
59
65
|
var resultTemplate = $("search-view-template");
|
60
|
-
var container = $("
|
66
|
+
var container = $(".search-results");
|
67
|
+
if (!container[0]) {
|
68
|
+
// Fall back to original behavior
|
69
|
+
container = $("article");
|
70
|
+
}
|
61
71
|
|
62
72
|
container.empty();
|
63
|
-
container.append("<h2>Results</h2>");
|
73
|
+
container.append("<h2>Search Results</h2>");
|
64
74
|
|
65
75
|
$.each(results, function(i, result) {
|
66
76
|
var article = window.articles[result.ref];
|
67
|
-
|
77
|
+
var text = article.title;
|
78
|
+
if (article.subtitle) {
|
79
|
+
if (text) {
|
80
|
+
text = text + " - " + article.subtitle;
|
81
|
+
} else {
|
82
|
+
text = article.subtitle;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
container.append("<p><a href=\"<%= path "" %>" + result.ref + "?highlight=" + escape(term) + "\">" + text + "</a></p>");
|
68
87
|
});
|
69
88
|
}
|
70
89
|
|