chulapa-jekyll 2.0.1 → 2.1.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 +148 -35
- data/README.md +96 -72
- data/_data/version.yml +2 -2
- data/_includes/components/breadcrumbdatesocial.html +15 -11
- data/_includes/components/headers.html +17 -10
- data/_includes/components/indexcards.html +2 -2
- data/_includes/components/navbeforeafter.html +2 -2
- data/_includes/components/random.html +103 -0
- data/_includes/components/related.html +82 -90
- data/_includes/components/simplelist.html +26 -0
- data/_includes/footer.html +53 -1
- data/_includes/head.html +237 -98
- data/_includes/search/fusejs.html +36 -0
- data/_includes/search/lunr.html +27 -7
- data/_includes/search/simplesearch.html +46 -0
- data/_includes/snippets/article-images.html +25 -0
- data/_includes/snippets/bootstrapdemo.html +1454 -1303
- data/_includes/snippets/breadcrumb-names.html +5 -0
- data/_includes/snippets/canonical-url.html +17 -0
- data/_includes/snippets/datetranslate.html +7 -1
- data/_includes/snippets/jsonld-string.html +16 -0
- data/_includes/snippets/og-locale.html +19 -0
- data/_includes/snippets/page-language.html +4 -0
- data/_includes/snippets/publisher.html +25 -0
- data/_includes/snippets/video-metadata.html +15 -0
- data/_includes/snippets/video.html +20 -17
- data/_includes/snippets/youtube.html +9 -4
- data/_includes/welcomments/template.html +1 -1
- data/_layouts/archive.html +1 -1
- data/_layouts/cloudcategory.html +4 -4
- data/_layouts/cloudtag.html +4 -4
- data/_layouts/default.html +4 -4
- data/_layouts/landingpage.html +8 -5
- data/_layouts/minimal.html +10 -4
- data/_layouts/search.html +12 -13
- data/_sass/chulapa/_classes.scss +68 -58
- data/_sass/chulapa/_reboot.scss +31 -0
- data/_sass/chulapa/_variables.scss +8 -1
- data/_sass/highlight/README.md +176 -14
- data/_sass/highlight/abap.scss +62 -0
- data/_sass/highlight/algol.scss +46 -0
- data/_sass/highlight/algol_nu.scss +46 -0
- data/_sass/highlight/arduino.scss +63 -0
- data/_sass/highlight/autumn.scss +69 -58
- data/_sass/highlight/base16.scss +90 -0
- data/_sass/highlight/borland.scss +55 -46
- data/_sass/highlight/bw.scss +70 -34
- data/_sass/highlight/cobalt2.scss +197 -0
- data/_sass/highlight/coffee.scss +82 -0
- data/_sass/highlight/colorful.scss +178 -61
- data/_sass/highlight/cran.scss +185 -169
- data/_sass/highlight/default.scss +72 -61
- data/_sass/highlight/dracula.scss +93 -169
- data/_sass/highlight/emacs.scss +72 -61
- data/_sass/highlight/friendly.scss +72 -61
- data/_sass/highlight/friendly_grayscale.scss +72 -0
- data/_sass/highlight/fruity.scss +82 -70
- data/_sass/highlight/github.dark.scss +83 -0
- data/_sass/highlight/github.scss +116 -61
- data/_sass/highlight/gruvbox.dark.scss +83 -0
- data/_sass/highlight/gruvbox.light.scss +68 -84
- data/_sass/highlight/gruvbox.scss +97 -0
- data/_sass/highlight/igor.scss +36 -0
- data/_sass/highlight/igorpro.scss +45 -0
- data/_sass/highlight/inkpot.scss +78 -0
- data/_sass/highlight/lightbulb.scss +82 -0
- data/_sass/highlight/lilypond.scss +58 -0
- data/_sass/highlight/lovelace.scss +74 -0
- data/_sass/highlight/magritte.scss +175 -0
- data/_sass/highlight/manni.scss +72 -61
- data/_sass/highlight/material.scss +81 -0
- data/_sass/highlight/molokai.scss +211 -0
- data/_sass/highlight/monokai.scss +217 -65
- data/_sass/highlight/monokai.sublime.scss +203 -0
- data/_sass/highlight/murphy.scss +72 -61
- data/_sass/highlight/native.scss +82 -70
- data/_sass/highlight/night-owl.scss +201 -0
- data/_sass/highlight/nord.darker.scss +82 -0
- data/_sass/highlight/nord.scss +82 -0
- data/_sass/highlight/oksolar.dark.scss +175 -0
- data/_sass/highlight/oksolar.light.scss +175 -0
- data/_sass/highlight/one.dark.scss +82 -0
- data/_sass/highlight/panda.scss +195 -0
- data/_sass/highlight/paraiso.dark.scss +76 -0
- data/_sass/highlight/paraiso.light.scss +76 -0
- data/_sass/highlight/pastie.scss +154 -60
- data/_sass/highlight/perldoc.scss +69 -58
- data/_sass/highlight/rainbow_dash.scss +65 -0
- data/_sass/highlight/rrt.scss +82 -0
- data/_sass/highlight/sas.scss +63 -0
- data/_sass/highlight/selenized.black.scss +175 -0
- data/_sass/highlight/selenized.dark.scss +175 -0
- data/_sass/highlight/selenized.light.scss +175 -0
- data/_sass/highlight/selenized.white.scss +175 -0
- data/_sass/highlight/skeletor.scss +190 -140
- data/_sass/highlight/solarized.dark.scss +82 -0
- data/_sass/highlight/solarized.light.scss +82 -0
- data/_sass/highlight/stackoverflow.dark.scss +175 -0
- data/_sass/highlight/stackoverflow.light.scss +175 -0
- data/_sass/highlight/staroffice.scss +82 -0
- data/_sass/highlight/stata.dark.scss +82 -0
- data/_sass/highlight/stata.light.scss +49 -0
- data/_sass/highlight/tango.scss +81 -69
- data/_sass/highlight/template.scss +290 -0
- data/_sass/highlight/thankful_eyes.scss +180 -173
- data/_sass/highlight/trac.scss +70 -59
- data/_sass/highlight/tulip.scss +171 -0
- data/_sass/highlight/vim.scss +82 -70
- data/_sass/highlight/vs.scss +41 -33
- data/_sass/highlight/xcode.scss +65 -0
- data/_sass/highlight/zenburn.scss +82 -136
- data/_sass/reset-algolia.scss +27 -17
- data/_sass/skins/academia.scss +19 -10
- data/_sass/skins/auto.scss +5 -2
- data/_sass/skins/butterfly-dark.scss +54 -0
- data/_sass/skins/butterfly-dim.scss +54 -0
- data/_sass/skins/butterfly.scss +33 -0
- data/_sass/skins/chulapa.scss +10 -3
- data/_sass/skins/cyborg.scss +512 -0
- data/_sass/skins/dark-bg.scss +83 -49
- data/_sass/skins/darkly.scss +424 -0
- data/_sass/skins/deeply.scss +262 -63
- data/_sass/skins/electro.scss +24 -17
- data/_sass/skins/flatly.scss +386 -0
- data/_sass/skins/focal.scss +24 -18
- data/_sass/skins/gitdev-dark.scss +12 -20
- data/_sass/skins/gitdev.scss +20 -17
- data/_sass/skins/graymor.scss +22 -14
- data/_sass/skins/hootstrap.scss +17 -10
- data/_sass/skins/journal.scss +74 -86
- data/_sass/skins/listen.scss +51 -0
- data/_sass/skins/lux.scss +171 -237
- data/_sass/skins/lymcha.scss +14 -9
- data/_sass/skins/materia.scss +889 -0
- data/_sass/skins/media.scss +29 -11
- data/_sass/skins/mickie.scss +27 -11
- data/_sass/skins/minco.scss +30 -10
- data/_sass/skins/minty.scss +226 -85
- data/_sass/skins/monotone.scss +15 -1
- data/_sass/skins/navi.scss +26 -0
- data/_sass/skins/pear.scss +16 -5
- data/_sass/skins/preptor.scss +13 -12
- data/_sass/skins/skeeblu.scss +11 -11
- data/_sass/skins/sketchy.scss +366 -377
- data/_sass/skins/slate.scss +719 -0
- data/_sass/skins/solar.scss +425 -0
- data/_sass/skins/sunset.scss +27 -12
- data/_sass/skins/towards.scss +19 -5
- data/_sass/skins/twitter-dim.scss +20 -11
- data/_sass/skins/twitter-lights-out.scss +22 -11
- data/_sass/skins/twitter.scss +22 -10
- data/_sass/skins/united.scss +57 -0
- data/_sass/skins/universal.scss +29 -27
- data/_sass/skins/wandoo.scss +12 -11
- data/_sass/skins/yeti.scss +673 -0
- data/assets/atom.xml +10 -6
- data/assets/js/better404/better404.js +75 -0
- data/assets/js/ch_ytdefer/ch_ytdefer.js +0 -1
- data/assets/js/chulapa_script.js +2 -2
- data/assets/js/fusejs/fusejs-search.js +197 -0
- data/assets/js/fusejs/fusejs-search.min.js +4 -0
- data/assets/js/fusejs/fusejs-store.js +43 -0
- data/assets/js/lunr/lunr-search.js +249 -114
- data/assets/js/lunr/lunr-search.min.js +4 -0
- data/assets/js/lunr/lunr-store.js +31 -23
- data/assets/js/simplesearch/simplesearch-store.json +45 -0
- data/assets/rss.xml +4 -3
- metadata +81 -8
- data/_sass/highlight/UNLICENSE.txt +0 -24
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: null
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
// You found an Easter egg!
|
|
6
|
+
// Get root
|
|
7
|
+
{% assign homeurl = '/' | absolute_url %}
|
|
8
|
+
// Vars
|
|
9
|
+
let homeUrl = "{{ homeurl }}";
|
|
10
|
+
// with no trailing '/'
|
|
11
|
+
homeUrl = homeUrl.replace(/\/+$/, "");
|
|
12
|
+
let currentUrl = window.location.href;
|
|
13
|
+
let sitemap = "{{- 'sitemap.xml' | absolute_url -}}"
|
|
14
|
+
// Based in https://ben.balter.com/2022/06/30/helpful-404s-for-jekyll-and-github-pages/
|
|
15
|
+
// A: Function definition...
|
|
16
|
+
// Own version of closest from 'fastest-levenshtein')
|
|
17
|
+
// Single levestein dist https://stackoverflow.com/questions/18516942
|
|
18
|
+
// Later implemented as js-levenshtein
|
|
19
|
+
const levenshteinDistance = (s, t) => {
|
|
20
|
+
if (!s.length) return t.length;
|
|
21
|
+
if (!t.length) return s.length;
|
|
22
|
+
const arr = [];
|
|
23
|
+
for (let i = 0; i <= t.length; i++) {
|
|
24
|
+
arr[i] = [i];
|
|
25
|
+
for (let j = 1; j <= s.length; j++) {
|
|
26
|
+
arr[i][j] =
|
|
27
|
+
i === 0 ?
|
|
28
|
+
j :
|
|
29
|
+
Math.min(
|
|
30
|
+
arr[i - 1][j] + 1,
|
|
31
|
+
arr[i][j - 1] + 1,
|
|
32
|
+
arr[i - 1][j - 1] + (s[j - 1] === t[i - 1] ? 0 : 1)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return arr[t.length][s.length];
|
|
37
|
+
};
|
|
38
|
+
// Iterator to get closest match
|
|
39
|
+
const closest = (str, urls) => {
|
|
40
|
+
var arrayLength = urls.length;
|
|
41
|
+
var closest = []; // store their names within a local array
|
|
42
|
+
// Iterate over the distance
|
|
43
|
+
for (var i = 0; i < arrayLength; i++) {
|
|
44
|
+
closest.push(levenshteinDistance(str, urls[i]));
|
|
45
|
+
}
|
|
46
|
+
let min = closest[0];
|
|
47
|
+
let url = urls[0];
|
|
48
|
+
for (var i = 0; i < arrayLength; i++) {
|
|
49
|
+
if (closest[i] > 0) {
|
|
50
|
+
if (closest[i] < min) {
|
|
51
|
+
min = closest[i];
|
|
52
|
+
url = urls[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return url;
|
|
57
|
+
};
|
|
58
|
+
// END A: Function definition...
|
|
59
|
+
// https://ben.balter.com/2022/06/30/helpful-404s-for-jekyll-and-github-pages/
|
|
60
|
+
const div = document.getElementById('four-oh-four-suggestion');
|
|
61
|
+
if (div) {
|
|
62
|
+
const xhr = new XMLHttpRequest();
|
|
63
|
+
xhr.onload = () => {
|
|
64
|
+
if (xhr.status === 200) {
|
|
65
|
+
const xml = xhr.responseXML;
|
|
66
|
+
const urls = Array.from(xml.querySelectorAll('urlset > url > loc')).map((el) => el.textContent);
|
|
67
|
+
const relurl = new URL(closest(currentUrl, urls));
|
|
68
|
+
div.innerHTML = `<a class="alert-link font-weight-bolder" href="${relurl.href}">${relurl.href.replace(homeUrl, "")}</a>`;
|
|
69
|
+
} else {
|
|
70
|
+
div.innerHTML = '<a href="/">/</a>';
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
xhr.open('GET', `${sitemap}`);
|
|
74
|
+
xhr.send();
|
|
75
|
+
}
|
data/assets/js/chulapa_script.js
CHANGED
|
@@ -2,8 +2,8 @@ var sT = document.getElementById("sidetoc");
|
|
|
2
2
|
var btn = document.getElementById("demo");
|
|
3
3
|
var body = document.getElementById("body");
|
|
4
4
|
var main = document.getElementById("maincontent");
|
|
5
|
-
var heads = main.querySelectorAll("h1, h2, h3, h4, h5 , h6");
|
|
6
|
-
var els = main.querySelectorAll("pre");
|
|
5
|
+
var heads = main ? main.querySelectorAll("h1, h2, h3, h4, h5 , h6") : [];
|
|
6
|
+
var els = main ? main.querySelectorAll("pre") : [];
|
|
7
7
|
|
|
8
8
|
// First load sidebar
|
|
9
9
|
// Create hidden overlay
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: null
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
// Based on https://gist.github.com/evenfrost/1ba123656ded32fb7a0cd4651efd4db0
|
|
6
|
+
// Sort regions to avoid breaking layout
|
|
7
|
+
// Avoid highlighting single characters
|
|
8
|
+
// Mask highlighting happening in html tags (class or style)
|
|
9
|
+
|
|
10
|
+
const highlight = (fuseSearchResult, highlightClassName, termLen) => {
|
|
11
|
+
const set = (obj, path, value) => {
|
|
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
|
+
};
|
|
84
|
+
|
|
85
|
+
// Event listener to update as you write
|
|
86
|
+
// Based on https://stackoverflow.com/questions/75884233/how-to-set-up-fuse-js-like-vs-code
|
|
87
|
+
function init() {
|
|
88
|
+
const termsInput = document.getElementById('search');
|
|
89
|
+
const resultsContainer = document.getElementById('results');
|
|
90
|
+
const resultCount = document.getElementById('resultscount');
|
|
91
|
+
const options = {
|
|
92
|
+
keys: ['subtitle', 'content', 'categories', 'date',
|
|
93
|
+
{ name: 'title', weight: 1.15 },
|
|
94
|
+
{ name: 'tags', weight: 1.1 },
|
|
95
|
+
{ name: 'excerpt', weight: 1.05 }
|
|
96
|
+
],
|
|
97
|
+
isCaseSensitive: false,
|
|
98
|
+
ignoreDiacritics: true,
|
|
99
|
+
includeScore: true,
|
|
100
|
+
includeMatches: true, // For search highlight
|
|
101
|
+
minMatchCharLength: 2,
|
|
102
|
+
threshold: 0.35,
|
|
103
|
+
shouldSort: true,
|
|
104
|
+
ignoreLocation: true,
|
|
105
|
+
ignoreFieldNorm: true,
|
|
106
|
+
useExtendedSearch: true,
|
|
107
|
+
};
|
|
108
|
+
const fuse = new Fuse(store, options);
|
|
109
|
+
|
|
110
|
+
function renderEntries(entries) {
|
|
111
|
+
resultsContainer.textContent = '';
|
|
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
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function handleInputChange() {
|
|
168
|
+
let terms = termsInput.value;
|
|
169
|
+
const termLen = terms.length;
|
|
170
|
+
if (!terms) {
|
|
171
|
+
resultsContainer.textContent = '';
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (termLen === 1) {
|
|
175
|
+
terms = `^${terms}`;
|
|
176
|
+
}
|
|
177
|
+
const result = fuse.search(terms, { limit: 10 });
|
|
178
|
+
const resultFilter = result.filter((x) => x.score < 0.75);
|
|
179
|
+
|
|
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
|
+
const res = highlight(resultFilter, "bg-warning text-dark", termLen); // array of items with highlighted fields
|
|
191
|
+
renderEntries(res);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
termsInput.addEventListener('input', handleInputChange);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
init();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: null
|
|
3
|
+
---
|
|
4
|
+
const highlight=(fuseSearchResult,highlightClassName,termLen)=>{const set=(obj,path,value)=>{const pathValue=path.split('.');let i;for(i=0;i<pathValue.length-1;i++){obj=obj[pathValue[i]]}obj[pathValue[i]]=value};const generateHighlightedText=(inputText,regions,termLen)=>{let content='';let nextUnhighlightedRegionStartingIndex=0;regions=regions.sort((a,b)=>a[0]-b[0]);regions.forEach(region=>{if(nextUnhighlightedRegionStartingIndex>region[0]){return content}if(region[1]-region[0]<2){return content}if(region[1]-region[0]<parseInt(termLen/2)){return content}const lastRegionNextIndex=region[1]+1;const theInput=inputText.substring(region[0]);const indexIniTag=theInput.indexOf("<");const indexCloseTag=theInput.indexOf(">");if(indexCloseTag<indexIniTag||(indexIniTag==-1&&indexCloseTag>0)){return content}content+=[inputText.substring(nextUnhighlightedRegionStartingIndex,region[0]),`<span class="${highlightClassName}">`,inputText.substring(region[0],lastRegionNextIndex),'</span>',].join('');nextUnhighlightedRegionStartingIndex=lastRegionNextIndex});content+=inputText.substring(nextUnhighlightedRegionStartingIndex);return content};return fuseSearchResult.filter(({matches})=>matches&&matches.length).map(({item,matches})=>{const highlightedItem={...item};matches.forEach((match)=>{set(highlightedItem,match.key,generateHighlightedText(match.value,match.indices,termLen))});return highlightedItem})};function init(){const termsInput=document.getElementById('search');const resultsContainer=document.getElementById('results');const resultCount=document.getElementById('resultscount');const options={keys:['subtitle','content','categories','date',{name:'title',weight:1.15},{name:'tags',weight:1.1},{name:'excerpt',weight:1.05}],isCaseSensitive:false,ignoreDiacritics:true,includeScore:true,includeMatches:true,minMatchCharLength:2,threshold:0.35,shouldSort:true,ignoreLocation:true,ignoreFieldNorm:true,useExtendedSearch:true};const fuse=new Fuse(store,options);function renderEntries(entries){resultsContainer.textContent='';const resl=entries.length;if(resl===0){const el=document.createElement('h6');el.className='text-center';el.textContent="No results found";resultsContainer.appendChild(el);return}else{entries.forEach(i=>{let searchitem;if(i.img){searchitem=`<article class="my-2 text-left"><div class="row"><div class="col"><h5 class="chulapa-links-hover-only" itemprop="headline"><a href="${i.url}" rel="permalink">${i.title}</a></h5></div><div class="col-4 col-md-3"><a href="${i.url}" rel="permalink"><div class="rounded-lg chulapa-overlay-img chulapa-gradient chulapa-min-h-10" style="background-image: url('${i.img}')"></div></a></div></div><div class="row mt-2"><div class="col"><p>${i.excerpt.trim()}</p></div></div><hr></article>`}else{searchitem=`<article class="my-2 text-left"><div class="row"><div class="col"><h5 class="chulapa-links-hover-only" itemprop="headline"><a href="${i.url}" rel="permalink">${i.title}</a></h5></div></div><div class="row mt-2"><div class="col"><p>${i.excerpt.trim()}</p></div></div><hr></article>`}resultsContainer.innerHTML+=searchitem})}}function handleInputChange(){let terms=termsInput.value;const termLen=terms.length;if(!terms){resultsContainer.textContent='';return}if(termLen===1){terms=`^${terms}`}const result=fuse.search(terms,{limit:10});const resultFilter=result.filter((x)=>x.score<0.75);const itLen=resultFilter.length;if(itLen===0){console.log(`No match for '${terms}'`)}else{resultFilter.forEach(i=>{console.log(`Searching string '${terms}' gives Score: ${parseInt(i.score*1000000)/1000000} for title: ${i.item.title}`)})}const res=highlight(resultFilter,"bg-warning text-dark",termLen);renderEntries(res)}termsInput.addEventListener('input',handleInputChange)}init();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: null
|
|
3
|
+
---
|
|
4
|
+
/*
|
|
5
|
+
Copyright (c) 2013-2020 Michael Rose and contributors
|
|
6
|
+
MIT License
|
|
7
|
+
From minimal-mistakes: https://github.com/mmistakes/minimal-mistakes/
|
|
8
|
+
*/
|
|
9
|
+
{%- if site.search.provider == "fusejs" -%}
|
|
10
|
+
{% assign maxwords = site.search.fusejs_maxwords | default: site.search.maxwords | default: "30" %}
|
|
11
|
+
var store = [
|
|
12
|
+
{%- assign indexfusejs = site.pages | concat: site.documents | where_exp: 'doc', 'doc.include_on_search != false' -%}
|
|
13
|
+
{%- for doc in indexfusejs -%}
|
|
14
|
+
{%- assign descfallback = doc.content |
|
|
15
|
+
markdownify | newline_to_br |
|
|
16
|
+
replace:"<br />", ",.," |
|
|
17
|
+
replace:"{{", ",.," |
|
|
18
|
+
replace:"{%", ",.," |
|
|
19
|
+
split: ",.," | first -%}
|
|
20
|
+
{%- assign ogdesc = doc.excerpt | markdownify | default: descfallback | strip_html | strip_newlines -%}
|
|
21
|
+
{
|
|
22
|
+
"title": {{ doc.title | markdownify | remove: '<p>' | remove: '</p>' | strip_newlines | strip | jsonify }},
|
|
23
|
+
"subtitle": {{ doc.subtitle | markdownify | remove: '<p>' | remove: '</p>' | strip_newlines | strip | jsonify }},
|
|
24
|
+
"excerpt": {{ ogdesc | markdownify | strip | jsonify }},
|
|
25
|
+
"content": {{ doc.content | markdownify | newline_to_br |
|
|
26
|
+
replace: "<br />", " " |
|
|
27
|
+
replace: "</p>", " " |
|
|
28
|
+
replace: "</h1>", " " |
|
|
29
|
+
replace: "</h2>", " " |
|
|
30
|
+
replace: "</h3>", " " |
|
|
31
|
+
replace: "</h4>", " " |
|
|
32
|
+
replace: "</h5>", " " |
|
|
33
|
+
replace: "</h6>", " " |
|
|
34
|
+
strip_html | strip_newlines | truncatewords: maxwords | strip | jsonify }},
|
|
35
|
+
"categories": {{ doc.categories | jsonify }},
|
|
36
|
+
"date": {{ doc.date | date: "%Y-%m-%d" | jsonify }},
|
|
37
|
+
"tags": {{ doc.tags | jsonify }},
|
|
38
|
+
"url": {{ doc.url | absolute_url | jsonify }},
|
|
39
|
+
"img": {{ doc.og_image | default: doc.header_img | absolute_url | jsonify }}
|
|
40
|
+
}{%- unless forloop.last -%},{%- endunless -%}
|
|
41
|
+
{%- endfor -%}
|
|
42
|
+
]
|
|
43
|
+
{%- endif -%}
|