-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): improve search results page look
- Loading branch information
Showing
15 changed files
with
3,760 additions
and
1,881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#lunr-search-result { | ||
& div.lunr-search-result-item { | ||
margin: 0 0 20px 0; | ||
} | ||
& p.lunr-result-fail, | ||
& p.lunr-search-result-item-body { | ||
font-family: var(--serifFontFamily); | ||
font-size: rfs(1rem); | ||
line-height: 1.6; | ||
text-transform: none; | ||
margin: 10px 0 0 0; | ||
} | ||
& p.lunr-result-fail { | ||
color: maroon; | ||
text-align: center; | ||
font-size: rfs(1.125rem); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
function lunr_search(term) { | ||
if (!tipuesearch) { | ||
console.error("Pelican Elegant: Tipue search plugin is required"); | ||
return; | ||
} | ||
|
||
const items = tipuesearch["pages"]; | ||
const documents = tipuesearch["pages"]; | ||
let counter = 0; | ||
|
||
for (item in documents) { | ||
documents[item]["id"] = counter; | ||
counter = counter + 1; | ||
} | ||
|
||
idx = lunr(function() { | ||
this.ref("id"); | ||
this.field("title"); | ||
this.field("url"); | ||
this.field("text", { boost: 10 }); | ||
this.field("tags"); | ||
|
||
items.forEach(function(doc) { | ||
this.add(doc); | ||
}, this); | ||
}); | ||
|
||
if (term && idx && documents) { | ||
const resultHeadingRoot = document.getElementById( | ||
"lunr-search-result-heading" | ||
); | ||
const resultIntro = ` | ||
<h1>Search Results for <code>${term}</code></h1> | ||
`; | ||
|
||
resultHeadingRoot.insertAdjacentHTML("beforeend", resultIntro); | ||
|
||
const resultRoot = document.getElementById("lunr-search-result"); | ||
//put results on the screen. | ||
var results = idx.search(term); | ||
if (results.length > 0) { | ||
//if results | ||
for (var i = 0; i < results.length; i++) { | ||
var ref = results[i]["ref"]; | ||
var url = documents[ref]["url"]; | ||
var title = documents[ref]["title"]; | ||
var body = documents[ref]["text"].substring(0, 280) + "..."; | ||
|
||
const resultItem = ` | ||
<div class="lunr-search-result-item"> | ||
<h4> | ||
<a href=${url}> | ||
${title} | ||
</a> | ||
</h4> | ||
</a> | ||
<p class="lunr-search-result-item-body">${body} | ||
</p> | ||
</div> | ||
`; | ||
|
||
resultRoot.insertAdjacentHTML("beforeend", resultItem); | ||
} | ||
} else { | ||
const resultFailure = `<p class="lunr-result-fail">No results found for <span class="lunr-search-term">${term}</span></p>`; | ||
|
||
resultRoot.insertAdjacentHTML("beforeend", resultFailure); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function getQueryVariable(variable) { | ||
var query = window.location.search.substring(1); | ||
var vars = query.split("&"); | ||
|
||
for (var i = 0; i < vars.length; i++) { | ||
var pair = vars[i].split("="); | ||
|
||
if (pair[0] === variable) { | ||
return decodeURIComponent(pair[1].replace(/\+/g, "%20")); | ||
} | ||
} | ||
} | ||
|
||
var searchTerm = getQueryVariable("q"); | ||
if (searchTerm) { | ||
lunr_search(searchTerm); | ||
} |
Oops, something went wrong.