This commit is contained in:
parent
bb23d03b35
commit
fe3c643c84
|
@ -20,73 +20,75 @@
|
||||||
{{ partial "body/photoswipe" . }}
|
{{ partial "body/photoswipe" . }}
|
||||||
|
|
||||||
{{ $masonry := resources.Get `js/masonry.pkgd.min.js` | resources.Fingerprint }}
|
{{ $masonry := resources.Get `js/masonry.pkgd.min.js` | resources.Fingerprint }}
|
||||||
<script src="{{ $masonry.RelPermalink }}"></script>
|
<script defer src="{{ $masonry.RelPermalink }}"></script>
|
||||||
{{ $imagesloaded := resources.Get `js/imagesloaded.pkgd.min.js` | resources.Fingerprint }}
|
{{ $imagesloaded := resources.Get `js/imagesloaded.pkgd.min.js` | resources.Fingerprint }}
|
||||||
<script src="{{ $imagesloaded.RelPermalink }}"></script>
|
<script defer src="{{ $imagesloaded.RelPermalink }}"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var $grid = $('.grid').masonry({
|
$(document).ready(function () {
|
||||||
itemSelector: '.grid-item',
|
var $grid = $('.grid').masonry({
|
||||||
columnWidth: '.grid-sizer',
|
itemSelector: '.grid-item',
|
||||||
percentPosition: true,
|
columnWidth: '.grid-sizer',
|
||||||
});
|
percentPosition: true,
|
||||||
$grid.imagesLoaded().progress(function () {
|
});
|
||||||
$grid.masonry();
|
$grid.imagesLoaded().progress(function () {
|
||||||
});
|
$grid.masonry();
|
||||||
|
});
|
||||||
|
|
||||||
enquire.register("screen and (max-width:500px)", {
|
enquire.register("screen and (max-width:500px)", {
|
||||||
match: function () {
|
match: function () {
|
||||||
$('.grid-item').addClass('full');
|
$('.grid-item').addClass('full');
|
||||||
$('.grid-sizer').addClass('full');
|
$('.grid-sizer').addClass('full');
|
||||||
$('.grid-item').removeClass('half');
|
$('.grid-item').removeClass('half');
|
||||||
$('.grid-sizer').removeClass('half');
|
$('.grid-sizer').removeClass('half');
|
||||||
},
|
},
|
||||||
unmatch: function () {
|
unmatch: function () {
|
||||||
$('.grid-item').addClass('half');
|
$('.grid-item').addClass('half');
|
||||||
$('.grid-sizer').addClass('half');
|
$('.grid-sizer').addClass('half');
|
||||||
$('.grid-item').removeClass('full');
|
$('.grid-item').removeClass('full');
|
||||||
$('.grid-sizer').removeClass('full');
|
$('.grid-sizer').removeClass('full');
|
||||||
},
|
},
|
||||||
}).register("screen and (max-width:700px)", {
|
}).register("screen and (max-width:700px)", {
|
||||||
match: function () {
|
match: function () {
|
||||||
$('.grid-item').addClass('half');
|
$('.grid-item').addClass('half');
|
||||||
$('.grid-sizer').addClass('half');
|
$('.grid-sizer').addClass('half');
|
||||||
$('.grid-item').removeClass('third');
|
$('.grid-item').removeClass('third');
|
||||||
$('.grid-sizer').removeClass('third');
|
$('.grid-sizer').removeClass('third');
|
||||||
},
|
},
|
||||||
unmatch: function () {
|
unmatch: function () {
|
||||||
$('.grid-item').addClass('third');
|
$('.grid-item').addClass('third');
|
||||||
$('.grid-sizer').addClass('third');
|
$('.grid-sizer').addClass('third');
|
||||||
$('.grid-item').removeClass('half');
|
$('.grid-item').removeClass('half');
|
||||||
$('.grid-sizer').removeClass('half');
|
$('.grid-sizer').removeClass('half');
|
||||||
},
|
},
|
||||||
}).register("screen and (max-width:900px)", {
|
}).register("screen and (max-width:900px)", {
|
||||||
match: function () {
|
match: function () {
|
||||||
$('.grid-item').addClass('third');
|
$('.grid-item').addClass('third');
|
||||||
$('.grid-sizer').addClass('third');
|
$('.grid-sizer').addClass('third');
|
||||||
$('.grid-item').removeClass('quarter');
|
$('.grid-item').removeClass('quarter');
|
||||||
$('.grid-sizer').removeClass('quarter');
|
$('.grid-sizer').removeClass('quarter');
|
||||||
},
|
},
|
||||||
unmatch: function () {
|
unmatch: function () {
|
||||||
$('.grid-item').addClass('quarter');
|
$('.grid-item').addClass('quarter');
|
||||||
$('.grid-sizer').addClass('quarter');
|
$('.grid-sizer').addClass('quarter');
|
||||||
$('.grid-item').removeClass('third');
|
$('.grid-item').removeClass('third');
|
||||||
$('.grid-sizer').removeClass('third');
|
$('.grid-sizer').removeClass('third');
|
||||||
},
|
},
|
||||||
}).register("screen and (max-width:1200px)", {
|
}).register("screen and (max-width:1200px)", {
|
||||||
match: function () {
|
match: function () {
|
||||||
$('.grid-item').addClass('quarter');
|
$('.grid-item').addClass('quarter');
|
||||||
$('.grid-sizer').addClass('quarter');
|
$('.grid-sizer').addClass('quarter');
|
||||||
$('.grid-item').removeClass('fifth');
|
$('.grid-item').removeClass('fifth');
|
||||||
$('.grid-sizer').removeClass('fifth');
|
$('.grid-sizer').removeClass('fifth');
|
||||||
},
|
},
|
||||||
unmatch: function () {
|
unmatch: function () {
|
||||||
$('.grid-item').addClass('fifth');
|
$('.grid-item').addClass('fifth');
|
||||||
$('.grid-sizer').addClass('fifth');
|
$('.grid-sizer').addClass('fifth');
|
||||||
$('.grid-item').removeClass('quarter');
|
$('.grid-item').removeClass('quarter');
|
||||||
$('.grid-sizer').removeClass('quarter');
|
$('.grid-sizer').removeClass('quarter');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
|
@ -1,12 +1,14 @@
|
||||||
{{ if $.Param "enableCustomScrollbar" }}
|
{{ if $.Param "enableCustomScrollbar" }}
|
||||||
|
|
||||||
{{ $customscrollbar := resources.Get `js/perfect-scrollbar.jquery.min.js` | resources.Fingerprint }}
|
{{ $customscrollbar := resources.Get `js/perfect-scrollbar.jquery.min.js` | resources.Fingerprint }}
|
||||||
<script src="{{ $customscrollbar.RelPermalink }}"></script>
|
<script defer src="{{ $customscrollbar.RelPermalink }}"></script>
|
||||||
{{ $customScrollbarStyle := resources.Get "css/perfect-scrollbar.min.css" }}
|
{{ $customScrollbarStyle := resources.Get "css/perfect-scrollbar.min.css" }}
|
||||||
<script src="{{ $customScrollbarStyle.RelPermalink }}"></script>
|
<script defer src="{{ $customScrollbarStyle.RelPermalink }}"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var pre = $('pre');
|
$(document).ready(function () {
|
||||||
pre.perfectScrollbar();
|
var pre = $('pre');
|
||||||
|
pre.perfectScrollbar();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
|
@ -1,7 +1,7 @@
|
||||||
{{ $jquery := resources.Get "js/jquery.min.js" | resources.Fingerprint }}
|
{{ $jquery := resources.Get "js/jquery.min.js" | resources.Fingerprint }}
|
||||||
<script src="{{ $jquery.RelPermalink }}"></script>
|
<script async src="{{ $jquery.RelPermalink }}"></script>
|
||||||
{{ $clipboard := resources.Get "js/clipboard.min.js" | resources.Fingerprint }}
|
{{ $clipboard := resources.Get "js/clipboard.min.js" | resources.Fingerprint }}
|
||||||
<script src="{{ $clipboard.RelPermalink }}"></script>
|
<script defer src="{{ $clipboard.RelPermalink }}"></script>
|
||||||
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
|
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
|
||||||
<script defer src="{{ $enquire.RelPermalink }}"></script>
|
<script defer src="{{ $enquire.RelPermalink }}"></script>
|
||||||
{{ $prism := resources.Get "js/prism.min.js" | minify | resources.Fingerprint }}
|
{{ $prism := resources.Get "js/prism.min.js" | minify | resources.Fingerprint }}
|
||||||
|
|
|
@ -8,101 +8,103 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ $toc := resources.Get `js/jquery.toc.min.js` | resources.Fingerprint }}
|
{{ $toc := resources.Get `js/jquery.toc.min.js` | resources.Fingerprint }}
|
||||||
<script src="{{ $toc.RelPermalink }}"></script>
|
<script defer src="{{ $toc.RelPermalink }}"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var navbar = $('.navbar');
|
$(document).ready(function () {
|
||||||
|
var navbar = $('.navbar');
|
||||||
|
|
||||||
$("#toc").toc({ content: ".single__contents", headings: "h1,h2,h3,h4" });
|
$("#toc").toc({ content: ".single__contents", headings: "h1,h2,h3,h4" });
|
||||||
$('#toc > li').each(function () {
|
$('#toc > li').each(function () {
|
||||||
$(this).find('ul').css('display', 'none');
|
$(this).find('ul').css('display', 'none');
|
||||||
});
|
|
||||||
$('#toc a').each(function () {
|
|
||||||
$(this).click(function () {
|
|
||||||
navbar.removeClass('navbar--show');
|
|
||||||
navbar.removeClass('navbar--hide');
|
|
||||||
navbar.addClass('navbar--hide');
|
|
||||||
|
|
||||||
$(".single__contents :header").each(function () {
|
|
||||||
$('.toc a').removeClass('active');
|
|
||||||
});
|
|
||||||
$(this).addClass('active');
|
|
||||||
|
|
||||||
$('#toc > li').each(function () {
|
|
||||||
$(this).find('ul').css('display', 'none');
|
|
||||||
});
|
|
||||||
$(this).next().css('display', 'block');
|
|
||||||
$(this).parents('ul').css('display', 'block');
|
|
||||||
});
|
});
|
||||||
});
|
$('#toc a').each(function () {
|
||||||
|
$(this).click(function () {
|
||||||
|
navbar.removeClass('navbar--show');
|
||||||
|
navbar.removeClass('navbar--hide');
|
||||||
|
navbar.addClass('navbar--hide');
|
||||||
|
|
||||||
// Add link button for every
|
$(".single__contents :header").each(function () {
|
||||||
var text, clip = new ClipboardJS('.anchor');
|
$('.toc a').removeClass('active');
|
||||||
var headers = $('.single__contents :header').not('h6').not('h5');
|
|
||||||
headers.append(function (index, html) {
|
|
||||||
var element = $(this);
|
|
||||||
var url = encodeURI(document.location.origin + document.location.pathname);
|
|
||||||
var link = url + "#" + element[0].id;
|
|
||||||
return " <span class='anchor hide' data-clipboard-text='" + link + "' style='position: relative;'>" +
|
|
||||||
"<span style='font-size: 1rem; position: absolute; right: -2rem; top: 50%; transform: translateY(-50%)'>🔗</span>" +
|
|
||||||
"</span>"
|
|
||||||
;
|
|
||||||
});
|
|
||||||
headers.on('mouseenter', function () {
|
|
||||||
$(this).find('.anchor').attr('class', 'anchor');
|
|
||||||
});
|
|
||||||
headers.on('mouseleave', function () {
|
|
||||||
$(this).find('.anchor').attr('class', 'anchor hide');
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".anchor").on('mouseleave', function (e) {
|
|
||||||
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
|
|
||||||
});
|
|
||||||
|
|
||||||
clip.on('success', function (e) {
|
|
||||||
e.clearSelection();
|
|
||||||
$(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
|
|
||||||
});
|
|
||||||
|
|
||||||
// clipboard
|
|
||||||
var clipInit = false;
|
|
||||||
$('code').each(function () {
|
|
||||||
var code = $(this),
|
|
||||||
text = code.text();
|
|
||||||
|
|
||||||
if (text.length > 30) {
|
|
||||||
if (!clipInit) {
|
|
||||||
var text, clip = new ClipboardJS('.copy-to-clipboard', {
|
|
||||||
text: function (trigger) {
|
|
||||||
text = $(trigger).prev('code').text();
|
|
||||||
return text.replace(/^\$\s/gm, '');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
$(this).addClass('active');
|
||||||
|
|
||||||
var inPre;
|
$('#toc > li').each(function () {
|
||||||
clip.on('success', function (e) {
|
$(this).find('ul').css('display', 'none');
|
||||||
e.clearSelection();
|
|
||||||
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
|
||||||
$(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
|
||||||
});
|
});
|
||||||
|
$(this).next().css('display', 'block');
|
||||||
|
$(this).parents('ul').css('display', 'block');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
clip.on('error', function (e) {
|
// Add link button for every
|
||||||
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
var text, clip = new ClipboardJS('.anchor');
|
||||||
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
var headers = $('.single__contents :header').not('h6').not('h5');
|
||||||
$(document).one('copy', function () {
|
headers.append(function (index, html) {
|
||||||
|
var element = $(this);
|
||||||
|
var url = encodeURI(document.location.origin + document.location.pathname);
|
||||||
|
var link = url + "#" + element[0].id;
|
||||||
|
return " <span class='anchor hide' data-clipboard-text='" + link + "' style='position: relative;'>" +
|
||||||
|
"<span style='font-size: 1rem; position: absolute; right: -2rem; top: 50%; transform: translateY(-50%)'>🔗</span>" +
|
||||||
|
"</span>"
|
||||||
|
;
|
||||||
|
});
|
||||||
|
headers.on('mouseenter', function () {
|
||||||
|
$(this).find('.anchor').attr('class', 'anchor');
|
||||||
|
});
|
||||||
|
headers.on('mouseleave', function () {
|
||||||
|
$(this).find('.anchor').attr('class', 'anchor hide');
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".anchor").on('mouseleave', function (e) {
|
||||||
|
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
|
||||||
|
});
|
||||||
|
|
||||||
|
clip.on('success', function (e) {
|
||||||
|
e.clearSelection();
|
||||||
|
$(e.trigger).attr('aria-label', 'Link copied to clipboard!').addClass('tooltipped tooltipped-s');
|
||||||
|
});
|
||||||
|
|
||||||
|
// clipboard
|
||||||
|
var clipInit = false;
|
||||||
|
$('code').each(function () {
|
||||||
|
var code = $(this),
|
||||||
|
text = code.text();
|
||||||
|
|
||||||
|
if (text.length > 30) {
|
||||||
|
if (!clipInit) {
|
||||||
|
var text, clip = new ClipboardJS('.copy-to-clipboard', {
|
||||||
|
text: function (trigger) {
|
||||||
|
text = $(trigger).prev('code').text();
|
||||||
|
return text.replace(/^\$\s/gm, '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var inPre;
|
||||||
|
clip.on('success', function (e) {
|
||||||
|
e.clearSelection();
|
||||||
|
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
||||||
$(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
$(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
clip.on('error', function (e) {
|
||||||
|
inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
||||||
|
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
||||||
|
$(document).one('copy', function () {
|
||||||
|
$(e.trigger).attr('aria-label', 'Copied to clipboard!').addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
clipInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
code.after('<span class="copy-to-clipboard" title="Copy to clipboard" />');
|
||||||
|
code.next('.copy-to-clipboard').on('mouseleave', function () {
|
||||||
|
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
|
||||||
});
|
});
|
||||||
|
|
||||||
clipInit = true;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
code.after('<span class="copy-to-clipboard" title="Copy to clipboard" />');
|
}
|
||||||
code.next('.copy-to-clipboard').on('mouseleave', function () {
|
|
||||||
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-s tooltipped-w');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
|
@ -1,38 +1,40 @@
|
||||||
{{ if $.Param "enableMark" }}
|
{{ if $.Param "enableMark" }}
|
||||||
{{ $mark := resources.Get "js/jquery.mark.min.js" | resources.Fingerprint }}
|
{{ $mark := resources.Get "js/jquery.mark.min.js" | resources.Fingerprint }}
|
||||||
<script src="{{ $mark.RelPermalink }}"></script>
|
<script defer src="{{ $mark.RelPermalink }}"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var mark = function () {
|
$(document).ready(function () {
|
||||||
var keyword = $("#search").val();
|
var mark = function () {
|
||||||
var options = {
|
var keyword = $("#search").val();
|
||||||
"element": "mark",
|
var options = {
|
||||||
"className": "",
|
"element": "mark",
|
||||||
"exclude": [],
|
"className": "",
|
||||||
"iframes": false,
|
"exclude": [],
|
||||||
"iframesTimeout": 5000,
|
"iframes": false,
|
||||||
"acrossElements": false,
|
"iframesTimeout": 5000,
|
||||||
"ignoreGroups": 0,
|
"acrossElements": false,
|
||||||
"each": function (node) {
|
"ignoreGroups": 0,
|
||||||
},
|
"each": function (node) {
|
||||||
"filter": function (textNode, foundTerm, totalCounter) {
|
},
|
||||||
return true;
|
"filter": function (textNode, foundTerm, totalCounter) {
|
||||||
},
|
return true;
|
||||||
"noMatch": function (term) {
|
},
|
||||||
},
|
"noMatch": function (term) {
|
||||||
"done": function (counter) {
|
},
|
||||||
},
|
"done": function (counter) {
|
||||||
"debug": false,
|
},
|
||||||
"log": window.console
|
"debug": false,
|
||||||
|
"log": window.console
|
||||||
|
};
|
||||||
|
|
||||||
|
$(".container").unmark({
|
||||||
|
done: function () {
|
||||||
|
$(".container").mark(keyword, options);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$(".container").unmark({
|
$("#search").on("input", mark);
|
||||||
done: function () {
|
}
|
||||||
$(".container").mark(keyword, options);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$("#search").on("input", mark);
|
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
{{ partial "sidebar/site-mark" . }}
|
{{ partial "sidebar/site-mark" . }}
|
||||||
{{ $lunr := resources.Get "js/lunr.min.js" | resources.Fingerprint }}
|
{{ $lunr := resources.Get "js/lunr.min.js" | resources.Fingerprint }}
|
||||||
<script src="{{ $lunr.RelPermalink }}"></script>
|
<script defer src="{{ $lunr.RelPermalink }}"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
{{ if .Site.IsMultiLingual }}
|
{{ if .Site.IsMultiLingual }}
|
||||||
|
@ -22,125 +22,126 @@
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
var baseurl = "{{.Site.BaseURL}}";
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
var lunrIndex = null;
|
||||||
|
var pagesIndex = null;
|
||||||
|
var searchResults = null;
|
||||||
|
var searchMenu = null;
|
||||||
|
|
||||||
var lunrIndex = null;
|
function endsWith(str, suffix) {
|
||||||
var pagesIndex = null;
|
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||||
var searchResults = null;
|
}
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
function initLunr() {
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
if (!endsWith(baseurl, "/")) {
|
||||||
}
|
baseurl = baseurl + '/';
|
||||||
|
};
|
||||||
|
|
||||||
function initLunr() {
|
$.getJSON(baseurl + "index.json")
|
||||||
if (!endsWith(baseurl, "/")) {
|
.done(function (index) {
|
||||||
baseurl = baseurl + '/';
|
pagesIndex = index;
|
||||||
};
|
lunrIndex = lunr(function () {
|
||||||
|
this.ref('uri');
|
||||||
|
this.field('title');
|
||||||
|
this.field('description');
|
||||||
|
//this.field('content');
|
||||||
|
//this.field('tags');
|
||||||
|
//this.field('series');
|
||||||
|
//this.field('categories');
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
var that = this;
|
||||||
.done(function (index) {
|
index.forEach(function (page) {
|
||||||
pagesIndex = index;
|
that.add(page);
|
||||||
lunrIndex = lunr(function () {
|
});
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
//this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.fail(function (jqxhr, textStatus, error) {
|
||||||
|
var err = textStatus + ", " + error;
|
||||||
|
console.error("Error getting Hugo index file:", err);
|
||||||
});
|
});
|
||||||
})
|
}
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
function search(query) {
|
||||||
return lunrIndex.search(query).map(function (result) {
|
return lunrIndex.search(query).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];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSearchResults(results) {
|
||||||
|
searchResults = document.getElementById('search-results');
|
||||||
|
searchMenu = document.getElementById('search-menu');
|
||||||
|
searchResults.setAttribute('class', 'dropdown is-active');
|
||||||
|
|
||||||
|
var content = document.createElement('div');
|
||||||
|
content.setAttribute('class', 'dropdown-content search-content');
|
||||||
|
|
||||||
|
if (results.length > 0) {
|
||||||
|
results.forEach(function (result) {
|
||||||
|
var item = document.createElement('a');
|
||||||
|
item.setAttribute('href', result.uri);
|
||||||
|
item.setAttribute('class', 'dropdown-item');
|
||||||
|
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">» ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
||||||
|
content.appendChild(item);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var item = document.createElement('span');
|
||||||
|
item.setAttribute('class', 'dropdown-item');
|
||||||
|
item.innerText = 'No results found';
|
||||||
|
content.appendChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (searchMenu.hasChildNodes()) {
|
||||||
|
searchMenu.removeChild(
|
||||||
|
searchMenu.lastChild
|
||||||
|
);
|
||||||
|
}
|
||||||
|
searchMenu.appendChild(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
initLunr();
|
||||||
|
|
||||||
|
$("#search").on('input', function (e) {
|
||||||
|
if (!e.target.value) {
|
||||||
|
$('#search-results').attr('class', 'dropdown');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var results = search(e.target.value);
|
||||||
|
renderSearchResults(results);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#search').on('blur', function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
$('#search-results').attr('class', 'dropdown');
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#search').on('click', function (e) {
|
||||||
|
if (!e.target.value) {
|
||||||
|
$('#search-results').attr('class', 'dropdown');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var results = search(e.target.value);
|
||||||
|
renderSearchResults(results);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#search').on('keydown', function (e) {
|
||||||
|
var items = $('#search-menu .dropdown-item');
|
||||||
|
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
||||||
|
|
||||||
|
items.removeClass('is-active');
|
||||||
|
if (e.key === 'ArrowDown') {
|
||||||
|
items.eq(activeIndex + 1).addClass('is-active');
|
||||||
|
} else if (e.key === 'ArrowUp') {
|
||||||
|
items.eq(activeIndex - 1).addClass('is-active');
|
||||||
|
} else if (e.key === 'Enter') {
|
||||||
|
var currentItemLink = items.eq(activeIndex).attr('href');
|
||||||
|
if (currentItemLink) {
|
||||||
|
location.href = currentItemLink;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">» ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
Loading…
Reference in New Issue