chore: add PaperMod theme files

This commit is contained in:
James committed 2026-11-14 19:45:55 +08:00
1 parent a3365e53a5
commit 58fda1b0b3
126 files changed
+6260 -1

No files matched your search

+194
View File
@@ -0,0 +1,194 @@
import * as params from '@params';
const resList = document.getElementById('searchResults');
const sInput = document.getElementById('searchInput');
const searchBox = document.getElementById('searchbox');
let fuse;
let currentElement = null;
let firstResult = null;
let lastResult = null;
const defaultFuseOptions = {
distance: 100,
threshold: 0.4,
ignoreLocation: true,
keys: ['title', 'permalink', 'summary', 'content']
};
const buildFuseOptions = () => {
if (!params.fuseOpts) {
return defaultFuseOptions;
}
return {
isCaseSensitive: params.fuseOpts.iscasesensitive ?? false,
includeScore: params.fuseOpts.includescore ?? false,
includeMatches: params.fuseOpts.includematches ?? false,
minMatchCharLength: params.fuseOpts.minmatchcharlength ?? 1,
shouldSort: params.fuseOpts.shouldsort ?? true,
findAllMatches: params.fuseOpts.findallmatches ?? false,
keys: params.fuseOpts.keys ?? defaultFuseOptions.keys,
location: params.fuseOpts.location ?? 0,
threshold: params.fuseOpts.threshold ?? defaultFuseOptions.threshold,
distance: params.fuseOpts.distance ?? defaultFuseOptions.distance,
ignoreLocation: params.fuseOpts.ignorelocation ?? defaultFuseOptions.ignoreLocation
};
};
const debounce = (fn, delay) => {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = window.setTimeout(() => fn(...args), delay);
};
};
const reset = () => {
currentElement = null;
firstResult = null;
lastResult = null;
resList.innerHTML = '';
sInput.value = '';
sInput.focus();
};
const setActiveResult = (element) => {
document.querySelectorAll('.focus').forEach((item) => item.classList.remove('focus'));
if (!element) {
return;
}
element.focus();
element.parentElement?.classList.add('focus');
currentElement = element;
};
const renderResults = (results) => {
if (!Array.isArray(results) || results.length === 0) {
resList.innerHTML = '';
firstResult = lastResult = currentElement = null;
return;
}
const fragment = document.createDocumentFragment();
for (const result of results) {
const li = document.createElement('li');
const titleText = document.createTextNode(result.item.title);
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('width', '24');
svg.setAttribute('height', '24');
svg.setAttribute('viewBox', '0 0 24 24');
svg.setAttribute('fill', 'none');
svg.setAttribute('stroke', 'currentColor');
svg.setAttribute('stroke-width', '2');
svg.setAttribute('stroke-linecap', 'round');
svg.setAttribute('stroke-linejoin', 'round');
svg.classList.add('feather', 'feather-chevrons-right');
svg.innerHTML = '<polyline points="13 17 18 12 13 7"></polyline><polyline points="6 17 11 12 6 7"></polyline>';
const link = document.createElement('a');
link.className = 'entry-link';
link.href = result.item.permalink;
link.setAttribute('aria-label', result.item.title);
li.appendChild(titleText);
li.appendChild(svg);
li.appendChild(link);
fragment.appendChild(li);
}
resList.innerHTML = '';
resList.appendChild(fragment);
firstResult = resList.firstElementChild;
lastResult = resList.lastElementChild;
};
const performSearch = () => {
if (!fuse) {
return;
}
const query = sInput.value.trim();
if (!query) {
renderResults([]);
return;
}
const searchOptions = params.fuseOpts?.limit ? { limit: params.fuseOpts.limit } : undefined;
const results = searchOptions ? fuse.search(query, searchOptions) : fuse.search(query);
renderResults(results);
};
const initSearch = async () => {
if (!sInput || !resList) {
return;
}
sInput.disabled = false;
sInput.focus();
try {
const response = await fetch('../index.json');
if (!response.ok) {
throw new Error(`Search index load failed: ${response.status}`);
}
const data = await response.json();
if (data) {
fuse = new Fuse(data, buildFuseOptions());
}
} catch (error) {
console.error(error);
}
};
window.addEventListener('load', initSearch);
sInput?.addEventListener('input', debounce(performSearch, 150));
sInput?.addEventListener('search', () => {
if (!sInput.value) {
reset();
}
});
document.addEventListener('keydown', (event) => {
const { key } = event;
const active = document.activeElement;
const isInSearchBox = searchBox?.contains(active);
if (key === 'Escape') {
reset();
return;
}
if (!firstResult || !isInSearchBox) {
return;
}
if (key === 'ArrowDown') {
event.preventDefault();
if (active === sInput) {
setActiveResult(firstResult.querySelector('.entry-link'));
} else if (active?.parentElement !== lastResult) {
setActiveResult(active?.parentElement?.nextElementSibling?.querySelector('.entry-link'));
}
} else if (key === 'ArrowUp') {
event.preventDefault();
if (active?.parentElement === firstResult) {
setActiveResult(sInput);
} else if (active !== sInput) {
setActiveResult(active?.parentElement?.previousElementSibling?.querySelector('.entry-link'));
}
} else if (key === 'ArrowRight') {
if (active?.matches?.('.entry-link')) {
active.click();
}
}
});
+9
View File
@@ -0,0 +1,9 @@
/**
* Fuse.js v7.0.0 - Lightweight fuzzy-search (http://fusejs.io)
*
* Copyright (c) 2023 Kiro Risk (http://kiro.me)
* All Rights Reserved. Apache Software License 2.0
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
var e,t;e=this,t=function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?e(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,h(r.key),r)}}function o(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e,t,n){return(t=h(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function h(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}function u(e){return Array.isArray?Array.isArray(e):"[object Array]"===m(e)}var l=1/0;function d(e){return null==e?"":function(e){if("string"==typeof e)return e;var t=e+"";return"0"==t&&1/e==-l?"-0":t}(e)}function f(e){return"string"==typeof e}function v(e){return"number"==typeof e}function g(e){return!0===e||!1===e||function(e){return function(e){return"object"===n(e)}(e)&&null!==e}(e)&&"[object Boolean]"==m(e)}function y(e){return null!=e}function p(e){return!e.trim().length}function m(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}var b=function(e){return"Missing ".concat(e," property in key")},k=function(e){return"Property 'weight' in key '".concat(e,"' must be a positive integer")},M=Object.prototype.hasOwnProperty,w=function(){function e(t){var n=this;r(this,e),this._keys=[],this._keyMap={};var i=0;t.forEach((function(e){var t=x(e);n._keys.push(t),n._keyMap[t.id]=t,i+=t.weight})),this._keys.forEach((function(e){e.weight/=i}))}return o(e,[{key:"get",value:function(e){return this._keyMap[e]}},{key:"keys",value:function(){return this._keys}},{key:"toJSON",value:function(){return JSON.stringify(this._keys)}}]),e}();function x(e){var t=null,n=null,r=null,i=1,o=null;if(f(e)||u(e))r=e,t=L(e),n=S(e);else{if(!M.call(e,"name"))throw new Error(b("name"));var a=e.name;if(r=a,M.call(e,"weight")&&(i=e.weight)<=0)throw new Error(k(a));t=L(a),n=S(a),o=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:o}}function L(e){return u(e)?e:e.split(".")}function S(e){return u(e)?e.join("."):e}var _={useExtendedSearch:!1,getFn:function(e,t){var n=[],r=!1;return function e(t,i,o){if(y(t))if(i[o]){var a=t[i[o]];if(!y(a))return;if(o===i.length-1&&(f(a)||v(a)||g(a)))n.push(d(a));else if(u(a)){r=!0;for(var c=0,s=a.length;c<s;c+=1)e(a[c],i,o+1)}else i.length&&e(a,i,o+1)}else n.push(t)}(e,f(t)?t.split("."):t,0),r?n:n[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},O=t(t(t(t({},{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:function(e,t){return e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1}}),{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1}),{location:0,threshold:.6,distance:100}),_),j=/[^ ]+/g,A=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.getFn,i=void 0===n?O.getFn:n,o=t.fieldNormWeight,a=void 0===o?O.fieldNormWeight:o;r(this,e),this.norm=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3,n=new Map,r=Math.pow(10,t);return{get:Line truncated
+6
View File
@@ -0,0 +1,6 @@
/*
PaperMod v8+
License: MIT https://github.com/adityatelange/hugo-PaperMod/blob/master/LICENSE
Copyright (c) 2020 nanxiaobei and adityatelange
Copyright (c) 2021-2026 adityatelange
*/