Skip to content

Commit 73fa743

Browse files
committed
feat(search): improve search results page look
Close #573 Close #275
1 parent 9d60af1 commit 73fa743

File tree

15 files changed

+3760
-1881
lines changed

15 files changed

+3760
-1881
lines changed

THANKS.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,4 @@ in making Elegant more elegant.
245245

246246
1. He submitted a [patch](https://github.com/Pelican-Elegant/elegant/pull/2)
247247
to the project
248-
249-
# 3rd Party Credits
250-
251-
Elegant is standing on the shoulders of these giants.
252-
253-
1. [Tipue Search](http://www.tipue.com/search/)
254-
1. [Bootstrap 2.3.2](http://getbootstrap.com/2.3.2/)
255-
1. [Solarized Light theme](http://ethanschoonover.com/solarized) converted to
256-
[Pelican Pygments](https://github.com/yuex/pelican-pygments-solarized-css)
257-
by [yuex 悟道洞穴人](https://github.com/yuex)
258248
<!-- yaspeller ignore:end -->

documentation/content/Advanced Features/tipue-search.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ Authors: Talha Mansoor, Jack De Winter
33
Title: Add Search to Your Site
44
Tags: unique
55
Date: 2019-07-03 19:56
6-
Slug: add-tipue-search
6+
Slug: add-search
77
Summary: Elegant can be configured to provide search for your static site, giving an alternate way to navigate the site.
88
Category: Advanced Features
99
---
1010

1111
Static sites usually do not offer search, as they are normally considered a dynamic task.
12-
Elegant uses the open-source [Tipue Search](http://www.tipue.com/search/) plugin, to offer
12+
Elegant uses the open-source [LunrJS](https://lunrjs.com/) JavaScript library, to offer
1313
search for your static site.
1414

1515
Here is an example of what the search result may look like:

gulpfile.babel.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ const rmProdCSS = cb => {
8585
};
8686
const minifyJS = () => {
8787
return src([
88-
"static/tipuesearch/tipuesearch_set.js",
89-
"static/tipuesearch/tipuesearch.min.js",
9088
"static/applause-button/applause-button.js",
9189
"static/photoswipe/photoswipe.js",
9290
"static/photoswipe/photoswipe-ui-default.js",
9391
"static/photoswipe/photoswipe-array-from-dom.js",
92+
"static/lunr/lunr.js",
9493
"static/clipboard/clipboard.js",
9594
"static/js/copy-to-clipboard.js",
95+
"static/js/lunr-search-result.js",
9696
"!static/js/elegant.prod.js"
9797
])
9898
.pipe(concat("elegant.prod.js"))
@@ -110,7 +110,6 @@ const compileCSS = () => {
110110
];
111111
return src([
112112
"static/applause-button/applause-button.css",
113-
"static/tipuesearch/tipuesearch.css",
114113
"static/photoswipe/photoswipe.css",
115114
"static/photoswipe/default-skin/default-skin.css",
116115
"static/css/*.css",

static/css/elegant.prod.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/css/links.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ div.recent-posts-posted a {
4444
text-decoration: none;
4545
}
4646
}
47+
#lunr-search-result > div.lunr-search-result-item > h4 > a,
4748
a.ampl {
4849
color: royalblue;
4950
display: inline-block;

static/css/search.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#lunr-search-result {
2+
& div.lunr-search-result-item {
3+
margin: 0 0 20px 0;
4+
}
5+
& p.lunr-result-fail,
6+
& p.lunr-search-result-item-body {
7+
font-family: var(--serifFontFamily);
8+
font-size: rfs(1rem);
9+
line-height: 1.6;
10+
text-transform: none;
11+
margin: 10px 0 0 0;
12+
}
13+
& p.lunr-result-fail {
14+
color: maroon;
15+
text-align: center;
16+
font-size: rfs(1.125rem);
17+
}
18+
}

static/js/elegant.prod.js

Lines changed: 66 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/js/lunr-search-result.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
function lunr_search(term) {
2+
if (!tipuesearch) {
3+
console.error("Pelican Elegant: Tipue search plugin is required");
4+
return;
5+
}
6+
7+
const items = tipuesearch["pages"];
8+
const documents = tipuesearch["pages"];
9+
let counter = 0;
10+
11+
for (item in documents) {
12+
documents[item]["id"] = counter;
13+
counter = counter + 1;
14+
}
15+
16+
idx = lunr(function() {
17+
this.ref("id");
18+
this.field("title");
19+
this.field("url");
20+
this.field("text", { boost: 10 });
21+
this.field("tags");
22+
23+
items.forEach(function(doc) {
24+
this.add(doc);
25+
}, this);
26+
});
27+
28+
if (term && idx && documents) {
29+
const resultHeadingRoot = document.getElementById(
30+
"lunr-search-result-heading"
31+
);
32+
const resultIntro = `
33+
<h1>Search Results for <code>${term}</code></h1>
34+
`;
35+
36+
resultHeadingRoot.insertAdjacentHTML("beforeend", resultIntro);
37+
38+
const resultRoot = document.getElementById("lunr-search-result");
39+
//put results on the screen.
40+
var results = idx.search(term);
41+
if (results.length > 0) {
42+
//if results
43+
for (var i = 0; i < results.length; i++) {
44+
var ref = results[i]["ref"];
45+
var url = documents[ref]["url"];
46+
var title = documents[ref]["title"];
47+
var body = documents[ref]["text"].substring(0, 280) + "...";
48+
49+
const resultItem = `
50+
<div class="lunr-search-result-item">
51+
<h4>
52+
<a href=${url}>
53+
${title}
54+
</a>
55+
</h4>
56+
</a>
57+
<p class="lunr-search-result-item-body">${body}
58+
</p>
59+
</div>
60+
`;
61+
62+
resultRoot.insertAdjacentHTML("beforeend", resultItem);
63+
}
64+
} else {
65+
const resultFailure = `<p class="lunr-result-fail">No results found for <span class="lunr-search-term">${term}</span></p>`;
66+
67+
resultRoot.insertAdjacentHTML("beforeend", resultFailure);
68+
}
69+
}
70+
return false;
71+
}
72+
73+
function getQueryVariable(variable) {
74+
var query = window.location.search.substring(1);
75+
var vars = query.split("&");
76+
77+
for (var i = 0; i < vars.length; i++) {
78+
var pair = vars[i].split("=");
79+
80+
if (pair[0] === variable) {
81+
return decodeURIComponent(pair[1].replace(/\+/g, "%20"));
82+
}
83+
}
84+
}
85+
86+
var searchTerm = getQueryVariable("q");
87+
if (searchTerm) {
88+
lunr_search(searchTerm);
89+
}

0 commit comments

Comments
 (0)