Skip to content

Commit

Permalink
feat: search support use fuse.js and mark.js. close#12
Browse files Browse the repository at this point in the history
  • Loading branch information
tomowang committed Jan 28, 2024
1 parent 30c0c12 commit 02dd72b
Show file tree
Hide file tree
Showing 24 changed files with 477 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
public

.hugo_build.lock
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Check [https://hugo-theme-tailwind.tomo.dev/](https://hugo-theme-tailwind.tomo.d
* Responsive design
* Multilingual
* Default image process for lazy load and srcset
* Search (by using [fuse.js](https://fusejs.io/) and [mark.js](https://markjs.io/))

## Installation

Expand Down Expand Up @@ -96,6 +97,7 @@ Some of the configuration options are:
* `params.taxonomies.icons`: icons for taxonomies (categories, tags, series, etc.).
* `params.giscus`: giscus settings
* `params.social_media`: social media links shown in the footer
* `params.search`: search settings

For social media link data, you can refer entries in `params.social_media.items`
(You can add more or disable exsited entries in `params.social_media.items`).
Expand Down
112 changes: 105 additions & 7 deletions assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,6 @@ video {
margin-right: 0.5rem;
}

.mx-3 {
margin-left: 0.75rem;
margin-right: 0.75rem;
}

.my-4 {
margin-top: 1rem;
margin-bottom: 1rem;
Expand All @@ -1221,6 +1216,10 @@ video {
margin-left: 0.5rem;
}

.ml-3 {
margin-left: 0.75rem;
}

.mr-1 {
margin-right: 0.25rem;
}
Expand Down Expand Up @@ -1301,6 +1300,10 @@ video {
min-height: 100%;
}

.min-h-screen {
min-height: 100vh;
}

.w-12 {
width: 3rem;
}
Expand All @@ -1321,6 +1324,10 @@ video {
width: 100%;
}

.min-w-0 {
min-width: 0px;
}

.max-w-4xl {
max-width: 56rem;
}
Expand Down Expand Up @@ -1361,8 +1368,8 @@ video {
flex-wrap: wrap;
}

.place-items-center {
place-items: center;
.place-items-start {
place-items: start;
}

.items-center {
Expand Down Expand Up @@ -1435,14 +1442,32 @@ video {
border-radius: 0.375rem;
}

.rounded-none {
border-radius: 0px;
}

.rounded-sm {
border-radius: 0.125rem;
}

.rounded-e-lg {
border-start-end-radius: 0.5rem;
border-end-end-radius: 0.5rem;
}

.rounded-s-lg {
border-start-start-radius: 0.5rem;
border-end-start-radius: 0.5rem;
}

.border {
border-width: 1px;
}

.border-e-0 {
border-inline-end-width: 0px;
}

.border-l-0 {
border-left-width: 0px;
}
Expand All @@ -1452,6 +1477,11 @@ video {
border-color: rgb(6 95 70 / var(--tw-border-opacity));
}

.border-gray-300 {
--tw-border-opacity: 1;
border-color: rgb(209 213 219 / var(--tw-border-opacity));
}

.border-slate-300 {
--tw-border-opacity: 1;
border-color: rgb(203 213 225 / var(--tw-border-opacity));
Expand Down Expand Up @@ -1506,6 +1536,10 @@ video {
padding: 0.5rem;
}

.p-3 {
padding: 0.75rem;
}

.p-6 {
padding: 1.5rem;
}
Expand Down Expand Up @@ -1577,6 +1611,10 @@ video {
padding-left: 0.75rem;
}

.pl-6 {
padding-left: 1.5rem;
}

.pr-3 {
padding-right: 0.75rem;
}
Expand Down Expand Up @@ -1679,6 +1717,11 @@ video {
color: rgb(30 41 59 / var(--tw-text-opacity));
}

.text-slate-900 {
--tw-text-opacity: 1;
color: rgb(15 23 42 / var(--tw-text-opacity));
}

.text-white {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
Expand Down Expand Up @@ -2697,6 +2740,21 @@ video {
color: rgb(5 150 105 / var(--tw-text-opacity));
}

.focus\:border-blue-500:focus {
--tw-border-opacity: 1;
border-color: rgb(59 130 246 / var(--tw-border-opacity));
}

.focus\:outline-none:focus {
outline: 2px solid transparent;
outline-offset: 2px;
}

.focus\:ring-blue-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
}

.focus-visible\:outline:focus-visible {
outline-style: solid;
}
Expand Down Expand Up @@ -2726,6 +2784,11 @@ video {
border-color: rgb(148 163 184 / var(--tw-border-opacity));
}

:is(.dark .dark\:border-slate-600) {
--tw-border-opacity: 1;
border-color: rgb(71 85 105 / var(--tw-border-opacity));
}

:is(.dark .dark\:bg-gray-600) {
--tw-bg-opacity: 1;
background-color: rgb(75 85 99 / var(--tw-bg-opacity));
Expand All @@ -2741,6 +2804,16 @@ video {
background-color: rgb(31 41 55 / var(--tw-bg-opacity));
}

:is(.dark .dark\:bg-slate-600) {
--tw-bg-opacity: 1;
background-color: rgb(71 85 105 / var(--tw-bg-opacity));
}

:is(.dark .dark\:bg-slate-700) {
--tw-bg-opacity: 1;
background-color: rgb(51 65 85 / var(--tw-bg-opacity));
}

:is(.dark .dark\:text-indigo-300) {
--tw-text-opacity: 1;
color: rgb(165 180 252 / var(--tw-text-opacity));
Expand All @@ -2761,6 +2834,21 @@ video {
color: rgb(203 213 225 / var(--tw-text-opacity));
}

:is(.dark .dark\:text-slate-400) {
--tw-text-opacity: 1;
color: rgb(148 163 184 / var(--tw-text-opacity));
}

:is(.dark .dark\:placeholder-slate-400)::-moz-placeholder {
--tw-placeholder-opacity: 1;
color: rgb(148 163 184 / var(--tw-placeholder-opacity));
}

:is(.dark .dark\:placeholder-slate-400)::placeholder {
--tw-placeholder-opacity: 1;
color: rgb(148 163 184 / var(--tw-placeholder-opacity));
}

:is(.dark .dark\:shadow-slate-200\/5) {
--tw-shadow-color: rgb(226 232 240 / 0.05);
--tw-shadow: var(--tw-shadow-colored);
Expand All @@ -2774,6 +2862,16 @@ video {
--tw-ring-color: rgb(248 250 252 / 0.05);
}

:is(.dark .dark\:focus\:border-blue-500:focus) {
--tw-border-opacity: 1;
border-color: rgb(59 130 246 / var(--tw-border-opacity));
}

:is(.dark .dark\:focus\:ring-blue-500:focus) {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
}

@media (min-width: 640px) {
.sm\:text-5xl {
font-size: 3rem;
Expand Down
5 changes: 5 additions & 0 deletions assets/icons/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 144 additions & 0 deletions assets/js/doT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// doT.js
// 2011-2014, Laura Doktorova, https://github.com/olado/doT
// Licensed under the MIT license.

(function () {
"use strict";

var doT = {
name: "doT",
version: "1.1.1",
templateSettings: {
evaluate: /\{\{([\s\S]+?(\}?)+)\}\}/g,
interpolate: /\{\{=([\s\S]+?)\}\}/g,
encode: /\{\{!([\s\S]+?)\}\}/g,
use: /\{\{#([\s\S]+?)\}\}/g,
useParams: /(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
defineParams:/^\s*([\w$]+):([\s\S]+)/,
conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
varname: "it",
strip: true,
append: true,
selfcontained: false,
doNotSkipEncoded: false
},
template: undefined, //fn, compile template
compile: undefined, //fn, for express
log: true
}, _globals;

doT.encodeHTMLSource = function(doNotSkipEncoded) {
var encodeHTMLRules = { "&": "&#38;", "<": "&#60;", ">": "&#62;", '"': "&#34;", "'": "&#39;", "/": "&#47;" },
matchHTML = doNotSkipEncoded ? /[&<>"'\/]/g : /&(?!#?\w+;)|<|>|"|'|\//g;
return function(code) {
return code ? code.toString().replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : "";
};
};

_globals = (function(){ return this || (0,eval)("this"); }());

/* istanbul ignore else */
if (typeof module !== "undefined" && module.exports) {
module.exports = doT;
} else if (typeof define === "function" && define.amd) {
define(function(){return doT;});
} else {
_globals.doT = doT;
}

var startend = {
append: { start: "'+(", end: ")+'", startencode: "'+encodeHTML(" },
split: { start: "';out+=(", end: ");out+='", startencode: "';out+=encodeHTML(" }
}, skip = /$^/;

function resolveDefs(c, block, def) {
return ((typeof block === "string") ? block : block.toString())
.replace(c.define || skip, function(m, code, assign, value) {
if (code.indexOf("def.") === 0) {
code = code.substring(4);
}
if (!(code in def)) {
if (assign === ":") {
if (c.defineParams) value.replace(c.defineParams, function(m, param, v) {
def[code] = {arg: param, text: v};
});
if (!(code in def)) def[code]= value;
} else {
new Function("def", "def['"+code+"']=" + value)(def);
}
}
return "";
})
.replace(c.use || skip, function(m, code) {
if (c.useParams) code = code.replace(c.useParams, function(m, s, d, param) {
if (def[d] && def[d].arg && param) {
var rw = (d+":"+param).replace(/'|\\/g, "_");
def.__exp = def.__exp || {};
def.__exp[rw] = def[d].text.replace(new RegExp("(^|[^\\w$])" + def[d].arg + "([^\\w$])", "g"), "$1" + param + "$2");
return s + "def.__exp['"+rw+"']";
}
});
var v = new Function("def", "return " + code)(def);
return v ? resolveDefs(c, v, def) : v;
});
}

function unescape(code) {
return code.replace(/\\('|\\)/g, "$1").replace(/[\r\t\n]/g, " ");
}

doT.template = function(tmpl, c, def) {
c = c || doT.templateSettings;
var cse = c.append ? startend.append : startend.split, needhtmlencode, sid = 0, indv,
str = (c.use || c.define) ? resolveDefs(c, tmpl, def || {}) : tmpl;

str = ("var out='" + (c.strip ? str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g," ")
.replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,""): str)
.replace(/'|\\/g, "\\$&")
.replace(c.interpolate || skip, function(m, code) {
return cse.start + unescape(code) + cse.end;
})
.replace(c.encode || skip, function(m, code) {
needhtmlencode = true;
return cse.startencode + unescape(code) + cse.end;
})
.replace(c.conditional || skip, function(m, elsecase, code) {
return elsecase ?
(code ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='") :
(code ? "';if(" + unescape(code) + "){out+='" : "';}out+='");
})
.replace(c.iterate || skip, function(m, iterate, vname, iname) {
if (!iterate) return "';} } out+='";
sid+=1; indv=iname || "i"+sid; iterate=unescape(iterate);
return "';var arr"+sid+"="+iterate+";if(arr"+sid+"){var "+vname+","+indv+"=-1,l"+sid+"=arr"+sid+".length-1;while("+indv+"<l"+sid+"){"
+vname+"=arr"+sid+"["+indv+"+=1];out+='";
})
.replace(c.evaluate || skip, function(m, code) {
return "';" + unescape(code) + "out+='";
})
+ "';return out;")
.replace(/\n/g, "\\n").replace(/\t/g, '\\t').replace(/\r/g, "\\r")
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, "");
//.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');

if (needhtmlencode) {
if (!c.selfcontained && _globals && !_globals._encodeHTML) _globals._encodeHTML = doT.encodeHTMLSource(c.doNotSkipEncoded);
str = "var encodeHTML = typeof _encodeHTML !== 'undefined' ? _encodeHTML : ("
+ doT.encodeHTMLSource.toString() + "(" + (c.doNotSkipEncoded || '') + "));"
+ str;
}
try {
return new Function(c.varname, str);
} catch (e) {
/* istanbul ignore else */
if (typeof console !== "undefined") console.log("Could not create a template function: " + str);
throw e;
}
};

doT.compile = function(tmpl, def) {
return doT.template(tmpl, null, def);
};
}());
Loading

0 comments on commit 02dd72b

Please sign in to comment.