ozobi 2019-02-07 14:45:13 +01:00 committed by Matthew Taylor
parent 2463671e20
commit c5033d3ee6
9 changed files with 44 additions and 34 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -65,7 +65,7 @@ $(document).ready(function(){
jQuery(document).ready(function() { jQuery(document).ready(function() {
// Add link button for every // Add link button for every
var text, clip = new Clipboard('.anchor'); var text, clip = new ClipboardJS('.anchor');
$("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function(index, html){ $("h1~h2,h1~h3,h1~h4,h1~h5,h1~h6").append(function(index, html){
var element = $(this); var element = $(this);
var url = encodeURI(document.location.origin + document.location.pathname); var url = encodeURI(document.location.origin + document.location.pathname);

2
static/js/jquery-3.3.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -181,7 +181,7 @@ jQuery(document).ready(function() {
if (text.length > 5) { if (text.length > 5) {
if (!clipInit) { if (!clipInit) {
var text, clip = new Clipboard('.copy-to-clipboard', { var text, clip = new ClipboardJS('.copy-to-clipboard', {
text: function(trigger) { text: function(trigger) {
text = $(trigger).prev('code').text(); text = $(trigger).prev('code').text();
return text.replace(/^\$\s/gm, ''); return text.replace(/^\$\s/gm, '');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -13,30 +13,33 @@ function initLunr() {
// First retrieve the index file // First retrieve the index file
$.getJSON(baseurl +"index.json") $.getJSON(baseurl +"index.json")
.done(function(index) { .done(function(index) {
pagesIndex = index; pagesIndex = index;
// Set up lunrjs by declaring the fields we use // Set up lunrjs by declaring the fields we use
// Also provide their boost level for the ranking // Also provide their boost level for the ranking
lunrIndex = new lunr.Index lunrIndex = lunr(function() {
lunrIndex.ref("uri"); this.ref("uri");
lunrIndex.field('title', { this.field('title', {
boost: 15 boost: 15
}); });
lunrIndex.field('tags', { this.field('tags', {
boost: 10 boost: 10
}); });
lunrIndex.field("content", { this.field("content", {
boost: 5 boost: 5
}); });
// Feed lunr with each file and let lunr actually index them this.pipeline.remove(lunr.stemmer);
pagesIndex.forEach(function(page) { this.searchPipeline.remove(lunr.stemmer);
lunrIndex.add(page);
}); // Feed lunr with each file and let lunr actually index them
lunrIndex.pipeline.remove(lunrIndex.stemmer) pagesIndex.forEach(function(page) {
this.add(page);
}, this);
})
}) })
.fail(function(jqxhr, textStatus, error) { .fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error; var err = textStatus + ", " + error;
console.error("Error getting Hugo index flie:", err); console.error("Error getting Hugo index file:", err);
}); });
} }
@ -46,9 +49,9 @@ function initLunr() {
* @param {String} query * @param {String} query
* @return {Array} results * @return {Array} results
*/ */
function search(query) { function search(queryTerm) {
// Find the item in our index corresponding to the lunr one to have more info // Find the item in our index corresponding to the lunr one to have more info
return lunrIndex.search(query).map(function(result) { return lunrIndex.search(queryTerm+"^100"+" "+queryTerm+"*^10"+" "+"*"+queryTerm+"^10"+" "+queryTerm+"~2^1").map(function(result) {
return pagesIndex.filter(function(page) { return pagesIndex.filter(function(page) {
return page.uri === result.ref; return page.uri === result.ref;
})[0]; })[0];