chulapa-jekyll 2.1.0 → 2.2.0
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/CHANGELOG.md +116 -0
- data/README.md +189 -204
- data/_data/version.yml +2 -2
- data/_includes/components/archive-documents.html +56 -0
- data/_includes/components/author.html +6 -1
- data/_includes/components/breadcrumbdatesocial.html +1 -1
- data/_includes/components/cactus.html +2 -1
- data/_includes/components/cloud-entry.html +26 -0
- data/_includes/components/cloud.html +66 -0
- data/_includes/components/collection-documents.html +17 -0
- data/_includes/components/footer-content.html +34 -0
- data/_includes/components/headers.html +5 -5
- data/_includes/components/indexcards.html +13 -10
- data/_includes/components/indexcategory-documents.html +11 -0
- data/_includes/components/navbar-classic.html +58 -0
- data/_includes/components/navbeforeafter.html +7 -4
- data/_includes/components/navigation-fallback.html +19 -0
- data/_includes/components/random.html +1 -103
- data/_includes/components/recommendations.html +97 -0
- data/_includes/components/related.html +1 -96
- data/_includes/components/scripts.html +9 -0
- data/_includes/components/sidetoc.html +5 -4
- data/_includes/components/simplelist.html +6 -6
- data/_includes/components/skin-attribution.html +169 -0
- data/_includes/components/theme-selector.html +14 -0
- data/_includes/footer.html +14 -217
- data/_includes/head.html +265 -257
- data/_includes/navbar.html +33 -77
- data/_includes/search/fusejs.html +3 -19
- data/_includes/search/google.html +3 -3
- data/_includes/search/lunr.html +3 -11
- data/_includes/search/simplesearch.html +6 -6
- data/_includes/snippets/bootstrapdemo.html +28 -10
- data/_includes/snippets/carousel.html +16 -12
- data/_includes/snippets/dark-skin-enabled.html +14 -0
- data/_includes/snippets/masonry.html +6 -4
- data/_includes/snippets/microformats-url.html +2 -0
- data/_includes/snippets/publisher.html +15 -18
- data/_includes/snippets/video.html +6 -6
- data/_includes/snippets/youtube.html +10 -4
- data/_includes/theme-styles.html +201 -0
- data/_includes/welcomments/comment_form.html +5 -4
- data/_includes/welcomments/comments.html +5 -5
- data/_layouts/archive.html +2 -75
- data/_layouts/cloudcategory.html +2 -101
- data/_layouts/cloudtag.html +2 -103
- data/_layouts/compress.html +1 -1
- data/_layouts/default.html +17 -6
- data/_layouts/indexcategory.html +2 -30
- data/_layouts/landingpage.html +6 -4
- data/_layouts/minimal.html +12 -8
- data/_layouts/search.html +6 -5
- data/_sass/bootstrap/_variables.scss +1 -1
- data/_sass/bootstrap/mixins/_badge.scss +1 -1
- data/_sass/chulapa/_autothemer.scss +31 -0
- data/_sass/chulapa/_buttons.scss +101 -0
- data/_sass/chulapa/_classes.scss +137 -9
- data/_sass/chulapa/_mixins.scss +42 -1
- data/_sass/chulapa/_theme-selector.scss +1 -0
- data/_sass/chulapa/skins/_deeply.scss +229 -0
- data/_sass/chulapa/skins/_electro.scss +30 -0
- data/_sass/chulapa/skins/_graymor.scss +39 -0
- data/_sass/chulapa/skins/_hootstrap.scss +34 -0
- data/_sass/chulapa/skins/_lymcha.scss +27 -0
- data/_sass/chulapa/skins/_mickie.scss +38 -0
- data/_sass/chulapa/skins/_minco.scss +45 -0
- data/_sass/chulapa/skins/_monotone.scss +15 -0
- data/_sass/chulapa/skins/_preptor.scss +30 -0
- data/_sass/chulapa/skins/_skeeblu.scss +34 -0
- data/_sass/chulapa/skins/_sunset.scss +33 -0
- data/_sass/chulapa/skins/_wandoo.scss +22 -0
- data/_sass/chulapa/skins/bootswatch/_cyborg.scss +543 -0
- data/_sass/chulapa/skins/bootswatch/_darkly.scss +452 -0
- data/_sass/chulapa/skins/bootswatch/_flatly.scss +415 -0
- data/_sass/chulapa/skins/bootswatch/_journal.scss +163 -0
- data/_sass/chulapa/skins/bootswatch/_lux.scss +342 -0
- data/_sass/chulapa/skins/bootswatch/_materia.scss +914 -0
- data/_sass/chulapa/skins/bootswatch/_minty.scss +342 -0
- data/_sass/chulapa/skins/bootswatch/_sketchy.scss +757 -0
- data/_sass/chulapa/skins/bootswatch/_slate.scss +746 -0
- data/_sass/chulapa/skins/bootswatch/_solar.scss +454 -0
- data/_sass/chulapa/skins/bootswatch/_united.scss +85 -0
- data/_sass/chulapa/skins/bootswatch/_yeti.scss +699 -0
- data/_sass/chulapa/skins/bootswatch/cyborg.patch +301 -0
- data/_sass/chulapa/skins/bootswatch/darkly.patch +493 -0
- data/_sass/chulapa/skins/bootswatch/flatly.patch +325 -0
- data/_sass/chulapa/skins/bootswatch/journal.patch +71 -0
- data/_sass/chulapa/skins/bootswatch/lux.patch +97 -0
- data/_sass/chulapa/skins/bootswatch/materia.patch +250 -0
- data/_sass/chulapa/skins/bootswatch/minty.patch +400 -0
- data/_sass/chulapa/skins/bootswatch/sketchy.patch +863 -0
- data/_sass/chulapa/skins/bootswatch/slate.patch +537 -0
- data/_sass/chulapa/skins/bootswatch/solar.patch +307 -0
- data/_sass/chulapa/skins/bootswatch/united.patch +91 -0
- data/_sass/chulapa/skins/bootswatch/yeti.patch +552 -0
- data/_sass/chulapa-master.scss +10 -0
- data/_sass/skins/academia.scss +28 -0
- data/_sass/skins/auto.scss +23 -28
- data/_sass/skins/butterfly-dark.scss +22 -3
- data/_sass/skins/butterfly-dim.scss +32 -5
- data/_sass/skins/butterfly.scss +35 -3
- data/_sass/skins/cerulean.scss +120 -0
- data/_sass/skins/chulapa.scss +23 -3
- data/_sass/skins/cyborg.scss +3 -512
- data/_sass/skins/darkly.scss +3 -424
- data/_sass/skins/deeply.scss +10 -279
- data/_sass/skins/electro.scss +4 -25
- data/_sass/skins/flatly.scss +3 -386
- data/_sass/skins/focal.scss +33 -2
- data/_sass/skins/gitdev-dark.scss +19 -8
- data/_sass/skins/gitdev.scss +2 -2
- data/_sass/skins/graymor.scss +7 -30
- data/_sass/skins/hootstrap.scss +5 -19
- data/_sass/skins/journal.scss +3 -131
- data/_sass/skins/listen.scss +35 -3
- data/_sass/skins/litera.scss +281 -0
- data/_sass/skins/lux.scss +3 -310
- data/_sass/skins/lymcha.scss +4 -17
- data/_sass/skins/materia.scss +3 -889
- data/_sass/skins/media.scss +11 -1
- data/_sass/skins/mickie.scss +7 -26
- data/_sass/skins/minco.scss +10 -29
- data/_sass/skins/minty.scss +3 -309
- data/_sass/skins/monotone.scss +6 -24
- data/_sass/skins/navi.scss +29 -1
- data/_sass/skins/none.scss +24 -2
- data/_sass/skins/pear.scss +34 -1
- data/_sass/skins/preptor.scss +6 -16
- data/_sass/skins/pulse.scss +158 -0
- data/_sass/skins/skeeblu.scss +6 -17
- data/_sass/skins/sketchy.scss +3 -735
- data/_sass/skins/slate.scss +3 -719
- data/_sass/skins/solar.scss +3 -425
- data/_sass/skins/sunset.scss +6 -26
- data/_sass/skins/towards.scss +26 -1
- data/_sass/skins/twitter-dim.scss +43 -5
- data/_sass/skins/twitter-lights-out.scss +25 -3
- data/_sass/skins/twitter.scss +32 -3
- data/_sass/skins/united.scss +3 -57
- data/_sass/skins/universal.scss +17 -0
- data/_sass/skins/wandoo.scss +6 -12
- data/_sass/skins/yeti.scss +3 -673
- data/_sass/vendor/bootswatch/LICENSE +21 -0
- data/_sass/vendor/bootswatch/LICENSE-4.5.0 +21 -0
- data/_sass/vendor/bootswatch/README.md +57 -0
- data/_sass/vendor/bootswatch/cerulean/_bootswatch.scss +102 -0
- data/_sass/vendor/bootswatch/cerulean/_variables.scss +57 -0
- data/_sass/vendor/bootswatch/cyborg/_bootswatch.scss +330 -0
- data/_sass/vendor/bootswatch/cyborg/_variables.scss +169 -0
- data/_sass/vendor/bootswatch/darkly/_bootswatch.scss +247 -0
- data/_sass/vendor/bootswatch/darkly/_variables.scss +164 -0
- data/_sass/vendor/bootswatch/flatly/_bootswatch.scss +274 -0
- data/_sass/vendor/bootswatch/flatly/_variables.scss +106 -0
- data/_sass/vendor/bootswatch/journal/_bootswatch.scss +62 -0
- data/_sass/vendor/bootswatch/journal/_variables.scss +60 -0
- data/_sass/vendor/bootswatch/litera/_bootswatch.scss +268 -0
- data/_sass/vendor/bootswatch/litera/_variables.scss +96 -0
- data/_sass/vendor/bootswatch/lux/_bootswatch.scss +191 -0
- data/_sass/vendor/bootswatch/lux/_variables.scss +103 -0
- data/_sass/vendor/bootswatch/materia/_bootswatch.scss +747 -0
- data/_sass/vendor/bootswatch/materia/_variables.scss +129 -0
- data/_sass/vendor/bootswatch/minty/_bootswatch.scss +380 -0
- data/_sass/vendor/bootswatch/minty/_variables.scss +94 -0
- data/_sass/vendor/bootswatch/pulse/_bootswatch.scss +145 -0
- data/_sass/vendor/bootswatch/pulse/_variables.scss +96 -0
- data/_sass/vendor/bootswatch/sketchy/_bootswatch.scss +492 -0
- data/_sass/vendor/bootswatch/sketchy/_variables.scss +172 -0
- data/_sass/vendor/bootswatch/slate/_bootswatch.scss +531 -0
- data/_sass/vendor/bootswatch/slate/_variables.scss +163 -0
- data/_sass/vendor/bootswatch/solar/_bootswatch.scss +243 -0
- data/_sass/vendor/bootswatch/solar/_variables.scss +171 -0
- data/_sass/vendor/bootswatch/source.json +86 -0
- data/_sass/vendor/bootswatch/united/_bootswatch.scss +10 -0
- data/_sass/vendor/bootswatch/united/_variables.scss +54 -0
- data/_sass/vendor/bootswatch/yeti/_bootswatch.scss +586 -0
- data/_sass/vendor/bootswatch/yeti/_variables.scss +110 -0
- data/_sass/vendor/tophat/LICENSE +21 -0
- data/_sass/vendor/tophat/README.md +38 -0
- data/_sass/vendor/tophat/deeply/_styles.scss +6 -0
- data/_sass/vendor/tophat/deeply/_variables.scss +73 -0
- data/_sass/vendor/tophat/deeply/theme.scss +77 -0
- data/_sass/vendor/tophat/electro/_styles.scss +5 -0
- data/_sass/vendor/tophat/electro/_variables.scss +23 -0
- data/_sass/vendor/tophat/electro/theme.scss +28 -0
- data/_sass/vendor/tophat/graymor/_styles.scss +5 -0
- data/_sass/vendor/tophat/graymor/_variables.scss +18 -0
- data/_sass/vendor/tophat/graymor/theme.scss +24 -0
- data/_sass/vendor/tophat/hootstrap/_styles.scss +5 -0
- data/_sass/vendor/tophat/hootstrap/_variables.scss +14 -0
- data/_sass/vendor/tophat/hootstrap/theme.scss +18 -0
- data/_sass/vendor/tophat/lymcha/_styles.scss +5 -0
- data/_sass/vendor/tophat/lymcha/_variables.scss +13 -0
- data/_sass/vendor/tophat/lymcha/theme.scss +16 -0
- data/_sass/vendor/tophat/mickie/_styles.scss +5 -0
- data/_sass/vendor/tophat/mickie/_variables.scss +13 -0
- data/_sass/vendor/tophat/mickie/theme.scss +17 -0
- data/_sass/vendor/tophat/minco/_styles.scss +5 -0
- data/_sass/vendor/tophat/minco/_variables.scss +14 -0
- data/_sass/vendor/tophat/minco/theme.scss +18 -0
- data/_sass/vendor/tophat/monotone/_styles.scss +5 -0
- data/_sass/vendor/tophat/monotone/_variables.scss +14 -0
- data/_sass/vendor/tophat/monotone/theme.scss +18 -0
- data/_sass/vendor/tophat/preptor/_styles.scss +5 -0
- data/_sass/vendor/tophat/preptor/_variables.scss +14 -0
- data/_sass/vendor/tophat/preptor/theme.scss +18 -0
- data/_sass/vendor/tophat/skeeblu/_styles.scss +5 -0
- data/_sass/vendor/tophat/skeeblu/_variables.scss +17 -0
- data/_sass/vendor/tophat/skeeblu/theme.scss +22 -0
- data/_sass/vendor/tophat/source.json +57 -0
- data/_sass/vendor/tophat/sunset/_styles.scss +5 -0
- data/_sass/vendor/tophat/sunset/_variables.scss +13 -0
- data/_sass/vendor/tophat/sunset/theme.scss +16 -0
- data/_sass/vendor/tophat/wandoo/_styles.scss +5 -0
- data/_sass/vendor/tophat/wandoo/_variables.scss +18 -0
- data/_sass/vendor/tophat/wandoo/theme.scss +24 -0
- data/assets/css/dark/highlighter.scss +10 -0
- data/assets/css/dark/main.scss +43 -0
- data/assets/css/highlighter.scss +6 -1
- data/assets/css/main.scss +12 -3
- data/assets/css/search-fusejs.css +14 -0
- data/assets/css/search-lunr.css +7 -0
- data/assets/js/better404/better404.js +31 -38
- data/assets/js/ch_ytdefer/ch_ytdefer.js +27 -82
- data/assets/js/chulapa_carousel.js +115 -0
- data/assets/js/chulapa_mermaid.js +31 -0
- data/assets/js/chulapa_navigation.js +71 -0
- data/assets/js/chulapa_photoswipe.js +106 -0
- data/assets/js/chulapa_script.js +198 -76
- data/assets/js/chulapa_search.js +89 -0
- data/assets/js/clipboard/chulapa_clipboard.js +17 -108
- data/assets/js/cusdis/chulapa_cusdis.js +1 -1
- data/assets/js/fusejs/fusejs-search.js +5 -140
- data/assets/js/fusejs/fusejs-search.min.js +4 -4
- data/assets/js/lunr/lunr-search.js +7 -130
- data/assets/js/lunr/lunr-search.min.js +1 -1
- metadata +141 -2
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Shared presentation for local search engines; index positions are normalized here.
|
|
2
|
+
window.ChulapaSearch = (function () {
|
|
3
|
+
function highlight(results, className, termLength, positionsAreLengths) {
|
|
4
|
+
return results.map(({item, matches = []}) => {
|
|
5
|
+
const output = {...item};
|
|
6
|
+
for (const match of matches) {
|
|
7
|
+
const text = String(match.value);
|
|
8
|
+
let content = "", next = 0;
|
|
9
|
+
const ranges = match.indices.map(([start, end]) => [start, positionsAreLengths ? start + end : end + 1])
|
|
10
|
+
.sort((a, b) => a[0] - b[0]);
|
|
11
|
+
for (const [start, end] of ranges) {
|
|
12
|
+
if (start < next || end - start < Math.max(2, Math.floor(termLength / 2))) continue;
|
|
13
|
+
// Leave author-supplied HTML tags and encoded entities intact.
|
|
14
|
+
const before = text.slice(0, start);
|
|
15
|
+
if (before.lastIndexOf("<") > before.lastIndexOf(">") || /[<>]/.test(text.slice(start, end))) continue;
|
|
16
|
+
if (before.lastIndexOf("&") > before.lastIndexOf(";") && /^&[^;\s]*$/.test(before.slice(before.lastIndexOf("&")))) continue;
|
|
17
|
+
if (/&[^;\s]*$/.test(text.slice(start, end))) continue;
|
|
18
|
+
content += text.slice(next, start) + `<span class="${className}">` + text.slice(start, end) + "</span>";
|
|
19
|
+
next = end;
|
|
20
|
+
}
|
|
21
|
+
content += text.slice(next);
|
|
22
|
+
const keys = match.key.split(".");
|
|
23
|
+
const target = keys.slice(0, -1).reduce((value, key) => value[key], output);
|
|
24
|
+
target[keys[keys.length - 1]] = content;
|
|
25
|
+
}
|
|
26
|
+
return output;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function renderEntries(container, entries) {
|
|
30
|
+
const fragment = document.createDocumentFragment();
|
|
31
|
+
if (!entries.length) {
|
|
32
|
+
const empty = document.createElement("p");
|
|
33
|
+
empty.className = "h6 text-center";
|
|
34
|
+
empty.textContent = "No results found";
|
|
35
|
+
fragment.append(empty);
|
|
36
|
+
}
|
|
37
|
+
for (const item of entries) {
|
|
38
|
+
const article = document.createElement("article");
|
|
39
|
+
article.className = "my-2 text-left";
|
|
40
|
+
article.innerHTML = `<div class="row"><div class="col"><h2 class="h5 chulapa-links-hover-only" itemprop="headline"><a rel="permalink"></a></h2></div></div>
|
|
41
|
+
<div class="row mt-2"><div class="col"><p></p></div></div><hr>`;
|
|
42
|
+
const title = article.querySelector("h2 a");
|
|
43
|
+
title.href = item.url;
|
|
44
|
+
title.innerHTML = item.title;
|
|
45
|
+
article.querySelector("p").innerHTML = item.excerpt.trim();
|
|
46
|
+
if (item.img) {
|
|
47
|
+
const column = document.createElement("div");
|
|
48
|
+
column.className = "col-4 col-md-3";
|
|
49
|
+
const link = document.createElement("a");
|
|
50
|
+
link.href = item.url;
|
|
51
|
+
link.rel = "permalink";
|
|
52
|
+
// Highlight spans belong to the visible title, not its accessible name.
|
|
53
|
+
link.setAttribute("aria-label", title.textContent);
|
|
54
|
+
const image = document.createElement("div");
|
|
55
|
+
image.className = "rounded-lg chulapa-overlay-img chulapa-gradient chulapa-min-h-10";
|
|
56
|
+
image.style.backgroundImage = `url(${JSON.stringify(item.img)})`;
|
|
57
|
+
link.append(image);
|
|
58
|
+
column.append(link);
|
|
59
|
+
article.querySelector(".row").append(column);
|
|
60
|
+
}
|
|
61
|
+
fragment.append(article);
|
|
62
|
+
}
|
|
63
|
+
container.replaceChildren(fragment);
|
|
64
|
+
const status = document.getElementById("resultscount");
|
|
65
|
+
if (status) status.textContent = `${entries.length} ${entries.length === 1 ? "result" : "results"} found`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function bindInput(input, render) {
|
|
69
|
+
let timer;
|
|
70
|
+
function update() {
|
|
71
|
+
if (!input.value) {
|
|
72
|
+
const status = document.getElementById("resultscount");
|
|
73
|
+
if (status) status.textContent = "";
|
|
74
|
+
}
|
|
75
|
+
render();
|
|
76
|
+
}
|
|
77
|
+
input.addEventListener("input", () => {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
if (!input.value) update();
|
|
80
|
+
else timer = setTimeout(update, 150);
|
|
81
|
+
});
|
|
82
|
+
if (input.form) input.form.addEventListener("submit", event => {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
update();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return {highlight, renderEntries, bindInput};
|
|
89
|
+
})();
|
|
@@ -1,109 +1,18 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
function showTooltip(btn, message) {
|
|
8
|
-
btn.tooltip('hide')
|
|
9
|
-
.attr('data-original-title', message)
|
|
10
|
-
.tooltip('show');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function hideTooltip(btn) {
|
|
14
|
-
setTimeout(function() {
|
|
15
|
-
btn.tooltip('hide');
|
|
16
|
-
}, 1000);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function sleep(ms) {
|
|
20
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function setTooltip(btn, tooltip, style) {
|
|
24
|
-
btn.classList.remove('text-muted');
|
|
25
|
-
btn.classList.add(style);
|
|
26
|
-
btn.setAttribute('aria-label', tooltip);
|
|
27
|
-
await sleep(1000);
|
|
28
|
-
btn.classList.add('text-muted');
|
|
29
|
-
btn.setAttribute('aria-label', 'Copy code to clipboard');
|
|
30
|
-
btn.removeAttribute('data-original-title');
|
|
31
|
-
btn.classList.remove(style);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// End helpers tooltip
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Insert buttons
|
|
38
|
-
function ch_clipboard_setup() {
|
|
39
|
-
var d = document;
|
|
40
|
-
var els = d.querySelectorAll('pre');
|
|
41
|
-
for (var i = 0; i < els.length; i++) {
|
|
42
|
-
// Select all pre codes
|
|
43
|
-
var preBlock = els[i];
|
|
44
|
-
// Select first child
|
|
45
|
-
let codeBlock = preBlock.firstChild;
|
|
46
|
-
|
|
47
|
-
// If first child is code
|
|
48
|
-
if (codeBlock.tagName.toLowerCase() == 'code') {
|
|
49
|
-
// Add id to code block
|
|
50
|
-
codeBlock.setAttribute('id', 'clipboard_code' + i);
|
|
51
|
-
// Create button
|
|
52
|
-
var btn = d.createElement('button');
|
|
53
|
-
btn.classList.add('btn', 'text-muted', 'btn-sm', 'btn-chulapa-copy-code');
|
|
54
|
-
btn.innerHTML = "<i class='far fa-copy'></i>";
|
|
55
|
-
btn.id = 'clipboard_btn' + i;
|
|
56
|
-
btn.type = 'button';
|
|
57
|
-
btn.setAttribute('data-toggle', 'tooltip');
|
|
58
|
-
btn.setAttribute('data-placement', 'left');
|
|
59
|
-
btn.setAttribute('aria-label', 'Copy code to clipboard');
|
|
60
|
-
//Function to copy to clipboard
|
|
61
|
-
btn.onclick = ch_copy_cliboard(i);
|
|
62
|
-
preBlock.prepend(btn);
|
|
63
|
-
} else {
|
|
64
|
-
console.log('No code block for\n' + preBlock.innerHTML);
|
|
65
|
-
}
|
|
1
|
+
// Compatibility entry point: use the maintained clipboard implementation.
|
|
2
|
+
(function () {
|
|
3
|
+
var source = document.currentScript;
|
|
4
|
+
function setup() {
|
|
5
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", function () { ch_clipboard_setup(document); }, {once: true});
|
|
6
|
+
else ch_clipboard_setup(document);
|
|
66
7
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
navigator.clipboard.writeText('');
|
|
79
|
-
|
|
80
|
-
var btn = d.getElementById('clipboard_btn' + i);
|
|
81
|
-
var btnTrigger = $(btn);
|
|
82
|
-
|
|
83
|
-
// Set initial values
|
|
84
|
-
|
|
85
|
-
let style = 'text-success';
|
|
86
|
-
let msg = 'Copied on the clipboard:\n' + codeBlockStripped;
|
|
87
|
-
let tooltip = 'Copied!';
|
|
88
|
-
try {
|
|
89
|
-
navigator.clipboard.writeText(codeBlockStripped);
|
|
90
|
-
} catch {
|
|
91
|
-
// Modify on error
|
|
92
|
-
style = 'text-danger';
|
|
93
|
-
tooltip = 'Error!';
|
|
94
|
-
msg = 'Error when copying the code';
|
|
95
|
-
}
|
|
96
|
-
setTooltip(btn, tooltip, style);
|
|
97
|
-
showTooltip(btnTrigger, tooltip);
|
|
98
|
-
hideTooltip(btnTrigger);
|
|
99
|
-
console.log(msg);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// stripHtml safely
|
|
103
|
-
function stripHtml(html){
|
|
104
|
-
let tmp = document.createElement('DIV');
|
|
105
|
-
tmp.innerHTML = html;
|
|
106
|
-
return tmp.textContent || tmp.innerText || '';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
window.addEventListener('load', ch_clipboard_setup);
|
|
8
|
+
if (typeof ch_clipboard_setup === "function") { setup(); return; }
|
|
9
|
+
var url = new URL("../chulapa_script.js", source.src).href;
|
|
10
|
+
var script = Array.from(document.scripts).find(function (item) { return item.src === url; });
|
|
11
|
+
if (!script) {
|
|
12
|
+
script = document.createElement("script");
|
|
13
|
+
script.src = url;
|
|
14
|
+
script.setAttribute("data-clipboard-only", "true");
|
|
15
|
+
script.addEventListener("load", setup);
|
|
16
|
+
(document.body || document.head).append(script);
|
|
17
|
+
} else script.addEventListener("load", setup, {once: true});
|
|
18
|
+
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.CUSDIS={};let e;function t(t){return e||(e=document.createElement("iframe"),function(e,t){const s=window.matchMedia("(prefers-color-scheme: dark)"),d=d=>{try{const i=JSON.parse(d.data);if("cusdis"===i.from)switch(i.event){case"onload":"auto"===t.dataset.theme&&n("setTheme",s.matches?"dark":"light");break;case"resize":e.style.height=i.data+"px"}}catch(i){}};function i(e){const s=e.matches;"auto"===t.dataset.theme&&n("setTheme",s?"dark":"light")}window.addEventListener("message",d),s.addEventListener("change",i)}(e,t)),e.srcdoc=(e=>{const t=e.dataset.host||"https://cusdis.com",n=e.dataset.iframe||`${t}/js/iframe.umd.js`,cch=document.getElementById("maincss").href;return`<!DOCTYPE html>\n<html>\n <head>\n <link rel="stylesheet" href="${t}/js/style.css">\n <link rel="stylesheet" href="${cch}">\n <base target="_parent" />\n <link>\n <script>\n window.CUSDIS_LOCALE = ${JSON.stringify(window.CUSDIS_LOCALE)}\n window.__DATA__ = ${JSON.stringify(e.dataset)}\n <\/script>\n <style>\n :root {\n color-scheme: light;\n }\n </style>\n </head>\n <body id="ch-cusdis">\n <div id="root"></div>\n <script src="${n}" type="module">\n \n <\/script>\n </body>\n</html>`})(t),e.style.width="100%",e.style.border="0",e}function n(t,n){e&&e.contentWindow.postMessage(JSON.stringify({from:"cusdis",event:t,data:n}))}function s(e){if(e){e.innerHTML="";const n=t(e);e.appendChild(n)}}function d(){let e;window.cusdisElementId?e=document.querySelector(`#${window.cusdisElementId}`):document.querySelector("#cusdis_thread")?e=document.querySelector("#cusdis_thread"):document.querySelector("#cusdis")&&(console.warn("id `cusdis` is deprecated. Please use `cusdis_thread` instead"),e=document.querySelector("#cusdis")),!0===window.CUSDIS_PREVENT_INITIAL_RENDER||e&&s(e)}window.renderCusdis=s,window.CUSDIS.renderTo=s,window.CUSDIS.setTheme=function(e){n("setTheme",e)},window.CUSDIS.initial=d,d();
|
|
1
|
+
(function(){window.CUSDIS={};let e;function t(t){return e||(e=document.createElement("iframe"),function(e,t){const s=window.matchMedia("(prefers-color-scheme: dark)"),d=d=>{try{if(d.source!==e.contentWindow)return;const i=JSON.parse(d.data);if("cusdis"===i.from)switch(i.event){case"onload":"auto"===t.dataset.theme&&n("setTheme",s.matches?"dark":"light");break;case"resize":if(typeof i.data==="number"&&Number.isFinite(i.data)&&i.data>=0)e.style.height=i.data+"px"}}catch(i){}};function i(e){const s=e.matches;"auto"===t.dataset.theme&&n("setTheme",s?"dark":"light")}window.addEventListener("message",d),s.addEventListener("change",i)}(e,t)),e.srcdoc=(e=>{const t=e.dataset.host||"https://cusdis.com",n=e.dataset.iframe||`${t}/js/iframe.umd.js`,cch=document.getElementById("maincss").href;return`<!DOCTYPE html>\n<html>\n <head>\n <link rel="stylesheet" href="${t}/js/style.css">\n <link rel="stylesheet" href="${cch}">\n <base target="_parent" />\n <link>\n <script>\n window.CUSDIS_LOCALE = ${JSON.stringify(window.CUSDIS_LOCALE)}\n window.__DATA__ = ${JSON.stringify(e.dataset)}\n <\/script>\n <style>\n :root {\n color-scheme: light;\n }\n </style>\n </head>\n <body id="ch-cusdis">\n <div id="root"></div>\n <script src="${n}" type="module">\n \n <\/script>\n </body>\n</html>`})(t),e.style.width="100%",e.style.border="0",e}function n(t,n){e&&e.contentWindow.postMessage(JSON.stringify({from:"cusdis",event:t,data:n}))}function s(e){if(e){e.innerHTML="";const n=t(e);e.appendChild(n)}}function d(){let e;window.cusdisElementId?e=document.querySelector(`#${window.cusdisElementId}`):document.querySelector("#cusdis_thread")?e=document.querySelector("#cusdis_thread"):document.querySelector("#cusdis")&&(console.warn("id `cusdis` is deprecated. Please use `cusdis_thread` instead"),e=document.querySelector("#cusdis")),!0===window.CUSDIS_PREVENT_INITIAL_RENDER||e&&s(e)}window.renderCusdis=s,window.CUSDIS.renderTo=s,window.CUSDIS.setTheme=function(e){n("setTheme",e)},window.CUSDIS.initial=d,d();})();
|
|
@@ -7,87 +7,15 @@ layout: null
|
|
|
7
7
|
// Avoid highlighting single characters
|
|
8
8
|
// Mask highlighting happening in html tags (class or style)
|
|
9
9
|
|
|
10
|
-
const highlight = (
|
|
11
|
-
|
|
12
|
-
const pathValue = path.split('.');
|
|
13
|
-
let i;
|
|
14
|
-
|
|
15
|
-
for (i = 0; i < pathValue.length - 1; i++) {
|
|
16
|
-
obj = obj[pathValue[i]];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
obj[pathValue[i]] = value;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const generateHighlightedText = (inputText, regions, termLen) => {
|
|
23
|
-
let content = '';
|
|
24
|
-
let nextUnhighlightedRegionStartingIndex = 0;
|
|
25
|
-
|
|
26
|
-
// Sort regions to avoid breaking layout
|
|
27
|
-
regions = regions.sort((a, b) => a[0] - b[0]);
|
|
28
|
-
|
|
29
|
-
regions.forEach(region => {
|
|
30
|
-
// Was this region already included in content?
|
|
31
|
-
if (nextUnhighlightedRegionStartingIndex > region[0]) {
|
|
32
|
-
return content;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Not highlight short matches to avoid visual cluttering
|
|
36
|
-
// min 2 chars
|
|
37
|
-
if (region[1] - region[0] < 2) {
|
|
38
|
-
return content;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// And based on search term length
|
|
42
|
-
if (region[1] - region[0] < parseInt(termLen / 2)) {
|
|
43
|
-
return content;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const lastRegionNextIndex = region[1] + 1;
|
|
47
|
-
|
|
48
|
-
// Try mask html in database
|
|
49
|
-
const theInput = inputText.substring(region[0]);
|
|
50
|
-
const indexIniTag = theInput.indexOf("<");
|
|
51
|
-
const indexCloseTag = theInput.indexOf(">");
|
|
52
|
-
|
|
53
|
-
if (indexCloseTag < indexIniTag || (indexIniTag == -1 && indexCloseTag > 0)) {
|
|
54
|
-
return content;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
content += [
|
|
58
|
-
inputText.substring(nextUnhighlightedRegionStartingIndex, region[0]),
|
|
59
|
-
`<span class="${highlightClassName}">`,
|
|
60
|
-
inputText.substring(region[0], lastRegionNextIndex),
|
|
61
|
-
'</span>',
|
|
62
|
-
].join('');
|
|
63
|
-
|
|
64
|
-
nextUnhighlightedRegionStartingIndex = lastRegionNextIndex;
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
content += inputText.substring(nextUnhighlightedRegionStartingIndex);
|
|
68
|
-
|
|
69
|
-
return content;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return fuseSearchResult
|
|
73
|
-
.filter(({ matches }) => matches && matches.length)
|
|
74
|
-
.map(({ item, matches }) => {
|
|
75
|
-
const highlightedItem = { ...item };
|
|
76
|
-
|
|
77
|
-
matches.forEach((match) => {
|
|
78
|
-
set(highlightedItem, match.key, generateHighlightedText(match.value, match.indices, termLen));
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return highlightedItem;
|
|
82
|
-
});
|
|
83
|
-
};
|
|
10
|
+
const highlight = (results, className, termLength) =>
|
|
11
|
+
ChulapaSearch.highlight(results.filter(result => result.matches && result.matches.length), className, termLength, false);
|
|
84
12
|
|
|
85
13
|
// Event listener to update as you write
|
|
86
14
|
// Based on https://stackoverflow.com/questions/75884233/how-to-set-up-fuse-js-like-vs-code
|
|
87
15
|
function init() {
|
|
88
16
|
const termsInput = document.getElementById('search');
|
|
89
17
|
const resultsContainer = document.getElementById('results');
|
|
90
|
-
|
|
18
|
+
if (!termsInput || !resultsContainer) return;
|
|
91
19
|
const options = {
|
|
92
20
|
keys: ['subtitle', 'content', 'categories', 'date',
|
|
93
21
|
{ name: 'title', weight: 1.15 },
|
|
@@ -108,60 +36,7 @@ function init() {
|
|
|
108
36
|
const fuse = new Fuse(store, options);
|
|
109
37
|
|
|
110
38
|
function renderEntries(entries) {
|
|
111
|
-
resultsContainer
|
|
112
|
-
const resl = entries.length;
|
|
113
|
-
if (resl === 0) {
|
|
114
|
-
const el = document.createElement('h6');
|
|
115
|
-
el.className = 'text-center';
|
|
116
|
-
el.textContent = "No results found";
|
|
117
|
-
resultsContainer.appendChild(el);
|
|
118
|
-
return;
|
|
119
|
-
} else {
|
|
120
|
-
entries.forEach(i => {
|
|
121
|
-
let searchitem;
|
|
122
|
-
if (i.img) {
|
|
123
|
-
searchitem = `
|
|
124
|
-
<article class="my-2 text-left">
|
|
125
|
-
<div class="row">
|
|
126
|
-
<div class="col">
|
|
127
|
-
<h5 class="chulapa-links-hover-only" itemprop="headline">
|
|
128
|
-
<a href="${i.url}" rel="permalink">${i.title}</a>
|
|
129
|
-
</h5>
|
|
130
|
-
</div>
|
|
131
|
-
<div class="col-4 col-md-3">
|
|
132
|
-
<a href="${i.url}" rel="permalink">
|
|
133
|
-
<div class="rounded-lg chulapa-overlay-img chulapa-gradient chulapa-min-h-10" style="background-image: url('${i.img}')"></div>
|
|
134
|
-
</a>
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
137
|
-
<div class="row mt-2">
|
|
138
|
-
<div class="col">
|
|
139
|
-
<p>${i.excerpt.trim()}</p>
|
|
140
|
-
</div>
|
|
141
|
-
</div>
|
|
142
|
-
<hr>
|
|
143
|
-
</article>`;
|
|
144
|
-
} else {
|
|
145
|
-
searchitem = `
|
|
146
|
-
<article class="my-2 text-left">
|
|
147
|
-
<div class="row">
|
|
148
|
-
<div class="col">
|
|
149
|
-
<h5 class="chulapa-links-hover-only" itemprop="headline">
|
|
150
|
-
<a href="${i.url}" rel="permalink">${i.title}</a>
|
|
151
|
-
</h5>
|
|
152
|
-
</div>
|
|
153
|
-
</div>
|
|
154
|
-
<div class="row mt-2">
|
|
155
|
-
<div class="col">
|
|
156
|
-
<p>${i.excerpt.trim()}</p>
|
|
157
|
-
</div>
|
|
158
|
-
</div>
|
|
159
|
-
<hr>
|
|
160
|
-
</article>`;
|
|
161
|
-
}
|
|
162
|
-
resultsContainer.innerHTML += searchitem;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
39
|
+
ChulapaSearch.renderEntries(resultsContainer, entries);
|
|
165
40
|
}
|
|
166
41
|
|
|
167
42
|
function handleInputChange() {
|
|
@@ -177,21 +52,11 @@ function init() {
|
|
|
177
52
|
const result = fuse.search(terms, { limit: 10 });
|
|
178
53
|
const resultFilter = result.filter((x) => x.score < 0.75);
|
|
179
54
|
|
|
180
|
-
// log results
|
|
181
|
-
const itLen = resultFilter.length;
|
|
182
|
-
if (itLen === 0) {
|
|
183
|
-
console.log(`No match for '${terms}'`);
|
|
184
|
-
} else {
|
|
185
|
-
resultFilter.forEach(i => {
|
|
186
|
-
console.log(`Searching string '${terms}' gives Score: ${parseInt(i.score * 1000000) / 1000000} for title: ${i.item.title}`);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
55
|
const res = highlight(resultFilter, "bg-warning text-dark", termLen); // array of items with highlighted fields
|
|
191
56
|
renderEntries(res);
|
|
192
57
|
}
|
|
193
58
|
|
|
194
|
-
|
|
59
|
+
ChulapaSearch.bindInput(termsInput, handleInputChange);
|
|
195
60
|
}
|
|
196
61
|
|
|
197
62
|
init();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
---
|
|
2
|
-
layout: null
|
|
3
|
-
---
|
|
4
|
-
const highlight=(
|
|
1
|
+
---
|
|
2
|
+
layout: null
|
|
3
|
+
---
|
|
4
|
+
const highlight=(t,n,i)=>ChulapaSearch.highlight(t.filter(r=>r.matches&&r.matches.length),n,i,!1);function init(){const t=document.getElementById("search"),n=document.getElementById("results");if(!t||!n)return;const i={keys:["subtitle","content","categories","date",{name:"title",weight:1.15},{name:"tags",weight:1.1},{name:"excerpt",weight:1.05}],isCaseSensitive:!1,ignoreDiacritics:!0,includeScore:!0,includeMatches:!0,minMatchCharLength:2,threshold:.35,shouldSort:!0,ignoreLocation:!0,ignoreFieldNorm:!0,useExtendedSearch:!0},r=new Fuse(store,i);function a(e){ChulapaSearch.renderEntries(n,e)}function c(){let e=t.value;const s=e.length;if(!e){n.textContent="";return}s===1&&(e=`^${e}`);const o=r.search(e,{limit:10}).filter(h=>h.score<.75),u=highlight(o,"bg-warning text-dark",s);a(u)}ChulapaSearch.bindInput(t,c)}init();
|
|
@@ -7,65 +7,8 @@ layout: null
|
|
|
7
7
|
// Mask highlighting happening in html tags (class or style)
|
|
8
8
|
// Adaptation of my version of fusejs-search.js
|
|
9
9
|
|
|
10
|
-
const highlight = (
|
|
11
|
-
|
|
12
|
-
const set = (obj, path, value) => {
|
|
13
|
-
const keys = path.split('.');
|
|
14
|
-
keys.slice(0, -1).reduce((acc, key) => acc[key], obj)[keys[keys.length - 1]] = value;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Generate highlighted text based on regions
|
|
18
|
-
const generateHighlightedText = (inputText, regions, termLen) => {
|
|
19
|
-
let content = '';
|
|
20
|
-
let nextUnhighlightedRegionStartingIndex = 0;
|
|
21
|
-
|
|
22
|
-
// Sort regions to avoid breaking layout
|
|
23
|
-
regions.sort((a, b) => a[0] - b[0]);
|
|
24
|
-
|
|
25
|
-
regions.forEach(region => {
|
|
26
|
-
// Convert [start, len] to [start, end]
|
|
27
|
-
const [start, len] = region;
|
|
28
|
-
const end = start + len;
|
|
29
|
-
|
|
30
|
-
// Skip regions that are already included in content
|
|
31
|
-
if (nextUnhighlightedRegionStartingIndex > start) return;
|
|
32
|
-
|
|
33
|
-
// Skip short matches to avoid visual cluttering
|
|
34
|
-
if (end - start < 2 || end - start < Math.floor(termLen / 2)) return;
|
|
35
|
-
|
|
36
|
-
// Check for HTML tags
|
|
37
|
-
const theInput = inputText.substring(start);
|
|
38
|
-
const indexIniTag = theInput.indexOf("<");
|
|
39
|
-
const indexCloseTag = theInput.indexOf(">");
|
|
40
|
-
|
|
41
|
-
if (indexCloseTag < indexIniTag || (indexIniTag === -1 && indexCloseTag > 0)) return;
|
|
42
|
-
|
|
43
|
-
// Append unhighlighted and highlighted text
|
|
44
|
-
content += inputText.substring(nextUnhighlightedRegionStartingIndex, start);
|
|
45
|
-
content += `<span class="${highlightClassName}">`;
|
|
46
|
-
content += inputText.substring(start, end);
|
|
47
|
-
content += '</span>';
|
|
48
|
-
|
|
49
|
-
nextUnhighlightedRegionStartingIndex = end;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Append remaining unhighlighted text
|
|
53
|
-
content += inputText.substring(nextUnhighlightedRegionStartingIndex);
|
|
54
|
-
|
|
55
|
-
return content;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Highlight search results
|
|
59
|
-
return lunrSearchResult.map(({ item, matches }) => {
|
|
60
|
-
const highlightedItem = { ...item };
|
|
61
|
-
|
|
62
|
-
matches.forEach(match => {
|
|
63
|
-
set(highlightedItem, match.key, generateHighlightedText(match.value, match.indices, termLen));
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return highlightedItem;
|
|
67
|
-
});
|
|
68
|
-
};
|
|
10
|
+
const highlight = (results, className, termLength) =>
|
|
11
|
+
ChulapaSearch.highlight(results, className, termLength, true);
|
|
69
12
|
|
|
70
13
|
// lunr to fusejs layout
|
|
71
14
|
const lunr2fuse = (result) => {
|
|
@@ -113,66 +56,13 @@ const lunr2fuse = (result) => {
|
|
|
113
56
|
function init() {
|
|
114
57
|
const termsInput = document.getElementById('search');
|
|
115
58
|
const resultsContainer = document.getElementById('results');
|
|
116
|
-
|
|
59
|
+
if (!termsInput || !resultsContainer) return;
|
|
117
60
|
|
|
118
61
|
function renderEntries(entries) {
|
|
119
|
-
resultsContainer
|
|
120
|
-
|
|
121
|
-
const resl = entries.length;
|
|
122
|
-
if (resl === 0) {
|
|
123
|
-
const el = document.createElement('h6');
|
|
124
|
-
el.className = 'text-center';
|
|
125
|
-
el.textContent = "No results found";
|
|
126
|
-
resultsContainer.appendChild(el);
|
|
127
|
-
return;
|
|
128
|
-
} else {
|
|
129
|
-
entries.forEach(i => {
|
|
130
|
-
let searchitem;
|
|
131
|
-
if (i.img) {
|
|
132
|
-
searchitem = `
|
|
133
|
-
<article class="my-2 text-left">
|
|
134
|
-
<div class="row">
|
|
135
|
-
<div class="col">
|
|
136
|
-
<h5 class="chulapa-links-hover-only" itemprop="headline">
|
|
137
|
-
<a href="${i.url}" rel="permalink">${i.title}</a>
|
|
138
|
-
</h5>
|
|
139
|
-
</div>
|
|
140
|
-
<div class="col-4 col-md-3">
|
|
141
|
-
<a href="${i.url}" rel="permalink">
|
|
142
|
-
<div class="rounded-lg chulapa-overlay-img chulapa-gradient chulapa-min-h-10" style="background-image: url('${i.img}')"></div>
|
|
143
|
-
</a>
|
|
144
|
-
</div>
|
|
145
|
-
</div>
|
|
146
|
-
<div class="row mt-2">
|
|
147
|
-
<div class="col">
|
|
148
|
-
<p>${i.excerpt.trim()}</p>
|
|
149
|
-
</div>
|
|
150
|
-
</div>
|
|
151
|
-
<hr>
|
|
152
|
-
</article>`;
|
|
153
|
-
} else {
|
|
154
|
-
searchitem = `
|
|
155
|
-
<article class="my-2 text-left">
|
|
156
|
-
<div class="row">
|
|
157
|
-
<div class="col">
|
|
158
|
-
<h5 class="chulapa-links-hover-only" itemprop="headline">
|
|
159
|
-
<a href="${i.url}" rel="permalink">${i.title}</a>
|
|
160
|
-
</h5>
|
|
161
|
-
</div>
|
|
162
|
-
</div>
|
|
163
|
-
<div class="row mt-2">
|
|
164
|
-
<div class="col">
|
|
165
|
-
<p>${i.excerpt.trim()}</p>
|
|
166
|
-
</div>
|
|
167
|
-
</div>
|
|
168
|
-
<hr>
|
|
169
|
-
</article>`;
|
|
170
|
-
}
|
|
171
|
-
resultsContainer.innerHTML += searchitem;
|
|
172
|
-
});
|
|
173
|
-
}
|
|
62
|
+
ChulapaSearch.renderEntries(resultsContainer, entries);
|
|
174
63
|
}
|
|
175
64
|
|
|
65
|
+
let idx;
|
|
176
66
|
function handleInputChange() {
|
|
177
67
|
let terms = termsInput.value;
|
|
178
68
|
const termLen = terms.length;
|
|
@@ -180,12 +70,9 @@ function init() {
|
|
|
180
70
|
resultsContainer.textContent = '';
|
|
181
71
|
return;
|
|
182
72
|
}
|
|
183
|
-
if (termLen === 1) {
|
|
184
|
-
terms = `^${terms}`;
|
|
185
|
-
}
|
|
186
73
|
|
|
187
74
|
// Config search
|
|
188
|
-
|
|
75
|
+
if (!idx) idx = lunr(function () {
|
|
189
76
|
this.field('title');
|
|
190
77
|
this.field('subtitle');
|
|
191
78
|
this.field('excerpt');
|
|
@@ -237,21 +124,11 @@ function init() {
|
|
|
237
124
|
const lunres = lunr2fuse(result);
|
|
238
125
|
|
|
239
126
|
const resultFilter = lunres.filter((x) => x.score > 0.5);
|
|
240
|
-
// Log results
|
|
241
|
-
const itLen = resultFilter.length;
|
|
242
|
-
if (itLen === 0) {
|
|
243
|
-
console.log(`No match for '${terms}'`);
|
|
244
|
-
} else {
|
|
245
|
-
resultFilter.forEach(i => {
|
|
246
|
-
console.log(`Searching string '${terms}' gives Score: ${parseInt(i.score * 1000) / 1000} for title: ${i.item.title}`);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
127
|
const res = highlight(resultFilter, "bg-warning text-dark", termLen); // Array of items with highlighted fields
|
|
251
128
|
renderEntries(res);
|
|
252
129
|
}
|
|
253
130
|
|
|
254
|
-
|
|
131
|
+
ChulapaSearch.bindInput(termsInput, handleInputChange);
|
|
255
132
|
}
|
|
256
133
|
|
|
257
134
|
init();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: null
|
|
3
3
|
---
|
|
4
|
-
const highlight=(
|
|
4
|
+
const highlight=(n,e,i)=>ChulapaSearch.highlight(n,e,i,!0),lunr2fuse=n=>(n.forEach(e=>{e.item=store[e.ref],e.refIndex=e.ref;const i={};Object.values(e.matchData.metadata).forEach(s=>{Object.entries(s).forEach(([t,o])=>{i[t]||(i[t]=[]),Array.isArray(o.position)&&i[t].push(...o.position.filter(c=>c!==null))})}),Object.keys(i).forEach(s=>{i[s][0]===void 0&&delete i[s]});const a=Object.entries(i).filter(([,s])=>s.length>0).map(([s,t])=>({indices:t,key:s}));a.forEach(s=>{s.value=e.item[s.key]}),e.matches=a,delete e.ref,delete e.matchData}),n);function init(){const n=document.getElementById("search"),e=document.getElementById("results");if(!n||!e)return;function i(t){ChulapaSearch.renderEntries(e,t)}let a;function s(){let t=n.value;const o=t.length;if(!t){e.textContent="";return}a||(a=lunr(function(){this.field("title"),this.field("subtitle"),this.field("excerpt"),this.field("content"),this.field("categories"),this.field("date"),this.field("tags"),this.ref("id"),this.pipeline.remove(lunr.trimmer),this.metadataWhitelist=["position"];for(const r in store)this.add({title:store[r].title,subtitle:store[r].subtitle,excerpt:store[r].excerpt,content:store[r].content,categories:store[r].categories,date:store[r].date,tags:store[r].tags,id:r})})),t=t.toLowerCase();const c=a.query(r=>{t.split(lunr.tokenizer.separator).forEach(l=>{r.term(l,{boost:100}),t.lastIndexOf(" ")!==t.length-1&&r.term(l,{usePipeline:!1,wildcard:lunr.Query.wildcard.TRAILING,boost:10}),l!==""&&r.term(l,{usePipeline:!1,editDistance:1,boost:1})})}),d=lunr2fuse(c).filter(r=>r.score>.5),h=highlight(d,"bg-warning text-dark",o);i(h)}ChulapaSearch.bindInput(n,s)}init();
|