hexo-theme-redefine-x 2.8.5
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.
- package/.github/ISSUE_TEMPLATE/bug-chinese.yml +115 -0
- package/.github/ISSUE_TEMPLATE/bug-english.yml +106 -0
- package/.github/ISSUE_TEMPLATE/enhancement-chinese.yml +55 -0
- package/.github/ISSUE_TEMPLATE/enhancement-english.yml +55 -0
- package/.github/workflows/build-and-commit.yml +49 -0
- package/.github/workflows/npm-publish.yml +34 -0
- package/.github/workflows/stale-issues.yml +20 -0
- package/CHANGELOG_REDEFINE_X.md +236 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +51 -0
- package/DONATION.md +82 -0
- package/LICENSE +674 -0
- package/README.md +135 -0
- package/README_zh-CN.md +138 -0
- package/README_zh-TW.md +137 -0
- package/TODO.md +215 -0
- package/_config.yml +489 -0
- package/languages/en.yml +93 -0
- package/languages/es.yml +92 -0
- package/languages/fr.yml +92 -0
- package/languages/ja.yml +92 -0
- package/languages/zh-CN.yml +95 -0
- package/languages/zh-TW.yml +94 -0
- package/layout/404.ejs +1 -0
- package/layout/archive.ejs +1 -0
- package/layout/category.ejs +1 -0
- package/layout/components/comments/comment.ejs +22 -0
- package/layout/components/comments/giscus.ejs +42 -0
- package/layout/components/comments/gitalk.ejs +47 -0
- package/layout/components/comments/twikoo.ejs +50 -0
- package/layout/components/comments/waline.ejs +34 -0
- package/layout/components/footer/footer.ejs +99 -0
- package/layout/components/header/head.ejs +222 -0
- package/layout/components/header/navbar.ejs +163 -0
- package/layout/components/header/preloader.ejs +148 -0
- package/layout/components/header/progress-bar.ejs +12 -0
- package/layout/components/plugins/aplayer.ejs +3 -0
- package/layout/components/scripts.ejs +90 -0
- package/layout/components/sidebar/author.ejs +6 -0
- package/layout/components/sidebar/avatar.ejs +3 -0
- package/layout/components/sidebar/statistics.ejs +14 -0
- package/layout/components/swup.ejs +27 -0
- package/layout/index.ejs +1 -0
- package/layout/layout.ejs +13 -0
- package/layout/page.ejs +57 -0
- package/layout/pages/archive/archive.ejs +3 -0
- package/layout/pages/bookmarks/bookmarks.ejs +68 -0
- package/layout/pages/category/categories.ejs +11 -0
- package/layout/pages/category/category-detail.ejs +6 -0
- package/layout/pages/friends/friends-link.ejs +59 -0
- package/layout/pages/home/home-article.ejs +52 -0
- package/layout/pages/home/home-background.ejs +33 -0
- package/layout/pages/home/home-banner.ejs +234 -0
- package/layout/pages/home/home-content.ejs +62 -0
- package/layout/pages/home/home-sidebar.ejs +78 -0
- package/layout/pages/masonry/masonry.ejs +28 -0
- package/layout/pages/notfound/notfound.ejs +8 -0
- package/layout/pages/page-template.ejs +23 -0
- package/layout/pages/post/article-content.ejs +153 -0
- package/layout/pages/post/article-copyright.ejs +69 -0
- package/layout/pages/post/article-info.ejs +78 -0
- package/layout/pages/post/post-tools.ejs +17 -0
- package/layout/pages/post/toc.ejs +15 -0
- package/layout/pages/shuoshuo/essays.ejs +23 -0
- package/layout/pages/tag/tag-detail.ejs +6 -0
- package/layout/pages/tag/tags.ejs +24 -0
- package/layout/post.ejs +1 -0
- package/layout/tag.ejs +1 -0
- package/layout/tags.ejs +1 -0
- package/layout/utils/image-viewer.ejs +3 -0
- package/layout/utils/local-search.ejs +20 -0
- package/layout/utils/paginator.ejs +8 -0
- package/layout/utils/posts-list.ejs +28 -0
- package/layout/utils/side-tools.ejs +51 -0
- package/package.json +45 -0
- package/scripts/config-export.js +66 -0
- package/scripts/data-handle.js +37 -0
- package/scripts/events/404.js +16 -0
- package/scripts/events/welcome.js +141 -0
- package/scripts/filters/delete-mask-handle.js +27 -0
- package/scripts/filters/encrypt.js +202 -0
- package/scripts/filters/img-handle.js +9 -0
- package/scripts/filters/lazyload-handle.js +350 -0
- package/scripts/filters/lib/hbe.default.js +15 -0
- package/scripts/filters/link-handle.js +42 -0
- package/scripts/filters/stylus-handle.js +9 -0
- package/scripts/filters/table-handle.js +11 -0
- package/scripts/helpers/meta-helpers.js +38 -0
- package/scripts/helpers/page-helpers.js +153 -0
- package/scripts/helpers/recommendation-helpers.js +367 -0
- package/scripts/helpers/theme-helpers.js +251 -0
- package/scripts/helpers/waline-helpers.js +33 -0
- package/scripts/modules/btn.js +85 -0
- package/scripts/modules/btns.js +71 -0
- package/scripts/modules/folding.js +34 -0
- package/scripts/modules/note-large.js +72 -0
- package/scripts/modules/note.js +64 -0
- package/scripts/modules/tabs.js +99 -0
- package/source/assets/hbe.style.css +220 -0
- package/source/assets/odometer-theme-minimal.css +81 -0
- package/source/css/build/tailwind.css +2 -0
- package/source/css/common/animated.styl +71 -0
- package/source/css/common/basic.styl +239 -0
- package/source/css/common/codeblock/code-block.styl +158 -0
- package/source/css/common/codeblock/code-theme.styl +82 -0
- package/source/css/common/codeblock/highlight.styl +189 -0
- package/source/css/common/codeblock/hljs-themes/dark/a11y-dark.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/agate.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/atom-one-dark.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/github-dark.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/monokai-sublime.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/night-owl.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/nord.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/tokyo-night-dark.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/dark/vs2015.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/light/atom-one-light.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/light/default.styl +18 -0
- package/source/css/common/codeblock/hljs-themes/light/github.styl +18 -0
- package/source/css/common/colors.styl +112 -0
- package/source/css/common/markdown.styl +337 -0
- package/source/css/common/redefine-theme.styl +65 -0
- package/source/css/common/theme.styl +72 -0
- package/source/css/common/variables.styl +145 -0
- package/source/css/layout/_modules/aplayer.styl +799 -0
- package/source/css/layout/_modules/buttons.styl +42 -0
- package/source/css/layout/_modules/folding.styl +180 -0
- package/source/css/layout/_modules/notes.styl +181 -0
- package/source/css/layout/_modules/tabs.styl +105 -0
- package/source/css/layout/_partials/404.styl +14 -0
- package/source/css/layout/_partials/archive-list.styl +49 -0
- package/source/css/layout/_partials/article-copyright-info.styl +27 -0
- package/source/css/layout/_partials/article-meta-info.styl +62 -0
- package/source/css/layout/_partials/comments/comment.styl +11 -0
- package/source/css/layout/_partials/comments/gitalk.styl +529 -0
- package/source/css/layout/_partials/comments/twikoo.styl +62 -0
- package/source/css/layout/_partials/comments/waline.styl +1151 -0
- package/source/css/layout/_partials/footer.styl +59 -0
- package/source/css/layout/_partials/home-banner.styl +48 -0
- package/source/css/layout/_partials/image-viewer.styl +37 -0
- package/source/css/layout/_partials/local-search.styl +137 -0
- package/source/css/layout/_partials/navbar.styl +309 -0
- package/source/css/layout/_partials/page-template.styl +147 -0
- package/source/css/layout/_partials/paginator.styl +65 -0
- package/source/css/layout/_partials/post-tools.styl +43 -0
- package/source/css/layout/_partials/progress-bar.styl +33 -0
- package/source/css/layout/_partials/side-tools.styl +87 -0
- package/source/css/layout/_partials/tagcloud.styl +136 -0
- package/source/css/layout/_partials/toc.styl +105 -0
- package/source/css/layout/animations.styl +42 -0
- package/source/css/layout/archive-content.styl +8 -0
- package/source/css/layout/article-content.styl +257 -0
- package/source/css/layout/bookmarks.styl +8 -0
- package/source/css/layout/category-content.styl +21 -0
- package/source/css/layout/category-list.styl +119 -0
- package/source/css/layout/home-content.styl +114 -0
- package/source/css/layout/home-sidebar.styl +126 -0
- package/source/css/layout/page.styl +144 -0
- package/source/css/layout/tag-content.styl +30 -0
- package/source/css/style.styl +26 -0
- package/source/css/tailwind.source.css +236 -0
- package/source/fontawesome/all.min.css +6 -0
- package/source/fontawesome/brands.min.css +6 -0
- package/source/fontawesome/duotone.min.css +6 -0
- package/source/fontawesome/fontawesome.min.css +6 -0
- package/source/fontawesome/light.min.css +6 -0
- package/source/fontawesome/regular.min.css +6 -0
- package/source/fontawesome/sharp-solid.min.css +6 -0
- package/source/fontawesome/solid.min.css +6 -0
- package/source/fontawesome/svg-with-js.min.css +6 -0
- package/source/fontawesome/thin.min.css +6 -0
- package/source/fontawesome/v4-font-face.min.css +6 -0
- package/source/fontawesome/v4-shims.min.css +6 -0
- package/source/fontawesome/v5-font-face.min.css +6 -0
- package/source/fonts/Chillax/Chillax-Variable.eot +0 -0
- package/source/fonts/Chillax/Chillax-Variable.ttf +0 -0
- package/source/fonts/Chillax/Chillax-Variable.woff +0 -0
- package/source/fonts/Chillax/Chillax-Variable.woff2 +0 -0
- package/source/fonts/Chillax/chillax.css +39 -0
- package/source/fonts/Geist/GeistVF.ttf +0 -0
- package/source/fonts/Geist/GeistVF.woff +0 -0
- package/source/fonts/Geist/GeistVF.woff2 +0 -0
- package/source/fonts/Geist/geist.css +16 -0
- package/source/fonts/GeistMono/GeistMonoVF.ttf +0 -0
- package/source/fonts/GeistMono/GeistMonoVF.woff +0 -0
- package/source/fonts/GeistMono/GeistMonoVF.woff2 +0 -0
- package/source/fonts/GeistMono/geist-mono.css +16 -0
- package/source/images/bookmark-placeholder.svg +9 -0
- package/source/images/loading.svg +5 -0
- package/source/images/redefine-avatar.svg +1 -0
- package/source/images/redefine-favicon.svg +1 -0
- package/source/images/redefine-logo.svg +1 -0
- package/source/images/redefine-logo.webp +0 -0
- package/source/images/redefine-og.webp +0 -0
- package/source/images/wallhaven-wqery6-dark.webp +0 -0
- package/source/images/wallhaven-wqery6-light.webp +0 -0
- package/source/js/build/layouts/bookmarkNav.js +2 -0
- package/source/js/build/layouts/bookmarkNav.js.map +1 -0
- package/source/js/build/layouts/categoryList.js +2 -0
- package/source/js/build/layouts/categoryList.js.map +1 -0
- package/source/js/build/layouts/essays.js +2 -0
- package/source/js/build/layouts/essays.js.map +1 -0
- package/source/js/build/layouts/lazyload.js +2 -0
- package/source/js/build/layouts/lazyload.js.map +1 -0
- package/source/js/build/layouts/navbarShrink.js +2 -0
- package/source/js/build/layouts/navbarShrink.js.map +1 -0
- package/source/js/build/layouts/toc.js +2 -0
- package/source/js/build/layouts/toc.js.map +1 -0
- package/source/js/build/libs/APlayer.min.js +2 -0
- package/source/js/build/libs/Swup.min.js +2 -0
- package/source/js/build/libs/SwupPreloadPlugin.min.js +1 -0
- package/source/js/build/libs/SwupProgressPlugin.min.js +1 -0
- package/source/js/build/libs/SwupScriptsPlugin.min.js +1 -0
- package/source/js/build/libs/SwupScrollPlugin.min.js +1 -0
- package/source/js/build/libs/SwupSlideTheme.min.js +1 -0
- package/source/js/build/libs/Typed.min.js +10 -0
- package/source/js/build/libs/anime.min.js +8 -0
- package/source/js/build/libs/mermaid.min.js +2314 -0
- package/source/js/build/libs/minimasonry.min.js +1 -0
- package/source/js/build/libs/moment-with-locales.min.js +2 -0
- package/source/js/build/libs/moment.min.js +2 -0
- package/source/js/build/libs/odometer.min.js +2 -0
- package/source/js/build/libs/pangu.min.js +9 -0
- package/source/js/build/libs/pjax.min.js +1 -0
- package/source/js/build/libs/waline.js +84 -0
- package/source/js/build/main.js +2 -0
- package/source/js/build/main.js.map +1 -0
- package/source/js/build/plugins/aplayer.js +2 -0
- package/source/js/build/plugins/aplayer.js.map +1 -0
- package/source/js/build/plugins/hbe.js +2 -0
- package/source/js/build/plugins/hbe.js.map +1 -0
- package/source/js/build/plugins/masonry.js +2 -0
- package/source/js/build/plugins/masonry.js.map +1 -0
- package/source/js/build/plugins/mermaid.js +2 -0
- package/source/js/build/plugins/mermaid.js.map +1 -0
- package/source/js/build/plugins/pangu.js +2 -0
- package/source/js/build/plugins/pangu.js.map +1 -0
- package/source/js/build/plugins/tabs.js +2 -0
- package/source/js/build/plugins/tabs.js.map +1 -0
- package/source/js/build/plugins/typed.js +2 -0
- package/source/js/build/plugins/typed.js.map +1 -0
- package/source/js/build/tools/codeBlock.js +2 -0
- package/source/js/build/tools/codeBlock.js.map +1 -0
- package/source/js/build/tools/imageViewer.js +2 -0
- package/source/js/build/tools/imageViewer.js.map +1 -0
- package/source/js/build/tools/lightDarkSwitch.js +2 -0
- package/source/js/build/tools/lightDarkSwitch.js.map +1 -0
- package/source/js/build/tools/localSearch.js +2 -0
- package/source/js/build/tools/localSearch.js.map +1 -0
- package/source/js/build/tools/runtime.js +2 -0
- package/source/js/build/tools/runtime.js.map +1 -0
- package/source/js/build/tools/scrollTopBottom.js +2 -0
- package/source/js/build/tools/scrollTopBottom.js.map +1 -0
- package/source/js/build/tools/tocToggle.js +2 -0
- package/source/js/build/tools/tocToggle.js.map +1 -0
- package/source/js/build/utils.js +2 -0
- package/source/js/build/utils.js.map +1 -0
- package/source/js/build.js +148 -0
- package/source/js/layouts/bookmarkNav.js +65 -0
- package/source/js/layouts/categoryList.js +53 -0
- package/source/js/layouts/essays.js +25 -0
- package/source/js/layouts/lazyload.js +199 -0
- package/source/js/layouts/navbarShrink.js +135 -0
- package/source/js/layouts/toc.js +115 -0
- package/source/js/libs/APlayer.min.js +2 -0
- package/source/js/libs/APlayer.min.js.map +1 -0
- package/source/js/libs/Swup.min.js +2 -0
- package/source/js/libs/Swup.min.js.map +1 -0
- package/source/js/libs/SwupPreloadPlugin.min.js +1 -0
- package/source/js/libs/SwupPreloadPlugin.min.js.map +1 -0
- package/source/js/libs/SwupProgressPlugin.min.js +1 -0
- package/source/js/libs/SwupScriptsPlugin.min.js +1 -0
- package/source/js/libs/SwupScrollPlugin.min.js +1 -0
- package/source/js/libs/SwupScrollPlugin.min.js.map +1 -0
- package/source/js/libs/SwupSlideTheme.min.js +1 -0
- package/source/js/libs/Typed.min.js +10 -0
- package/source/js/libs/anime.min.js +8 -0
- package/source/js/libs/mermaid.min.js +2314 -0
- package/source/js/libs/mermaid.min.js.map +7 -0
- package/source/js/libs/minimasonry.min.js +1 -0
- package/source/js/libs/moment-with-locales.min.js +2 -0
- package/source/js/libs/moment.min.js +2 -0
- package/source/js/libs/odometer.min.js +2 -0
- package/source/js/libs/pangu.min.js +9 -0
- package/source/js/libs/pjax.min.js +1 -0
- package/source/js/libs/waline.js +84 -0
- package/source/js/libs/waline.js.map +1 -0
- package/source/js/main.js +95 -0
- package/source/js/plugins/aplayer.js +33 -0
- package/source/js/plugins/hbe.js +350 -0
- package/source/js/plugins/masonry.js +115 -0
- package/source/js/plugins/mermaid.js +7 -0
- package/source/js/plugins/pangu.js +12 -0
- package/source/js/plugins/tabs.js +29 -0
- package/source/js/plugins/typed.js +62 -0
- package/source/js/tools/codeBlock.js +48 -0
- package/source/js/tools/imageViewer.js +194 -0
- package/source/js/tools/lightDarkSwitch.js +165 -0
- package/source/js/tools/localSearch.js +327 -0
- package/source/js/tools/runtime.js +28 -0
- package/source/js/tools/scrollTopBottom.js +34 -0
- package/source/js/tools/tocToggle.js +58 -0
- package/source/js/utils.js +383 -0
- package/source/webfonts/fa-brands-400.ttf +0 -0
- package/source/webfonts/fa-brands-400.woff2 +0 -0
- package/source/webfonts/fa-duotone-900.ttf +0 -0
- package/source/webfonts/fa-duotone-900.woff2 +0 -0
- package/source/webfonts/fa-light-300.ttf +0 -0
- package/source/webfonts/fa-light-300.woff2 +0 -0
- package/source/webfonts/fa-regular-400.ttf +0 -0
- package/source/webfonts/fa-regular-400.woff2 +0 -0
- package/source/webfonts/fa-sharp-solid-900.ttf +0 -0
- package/source/webfonts/fa-sharp-solid-900.woff2 +0 -0
- package/source/webfonts/fa-solid-900.ttf +0 -0
- package/source/webfonts/fa-solid-900.woff2 +0 -0
- package/source/webfonts/fa-thin-100.ttf +0 -0
- package/source/webfonts/fa-thin-100.woff2 +0 -0
- package/source/webfonts/fa-v4compatibility.ttf +0 -0
- package/source/webfonts/fa-v4compatibility.woff2 +0 -0
- package/vercel.json +7 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
export default function initLocalSearch() {
|
|
2
|
+
// Search DB path
|
|
3
|
+
let searchPath = config.path;
|
|
4
|
+
if (!searchPath) {
|
|
5
|
+
// Search DB path
|
|
6
|
+
console.warn("`hexo-generator-searchdb` plugin is not installed!");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Popup Window
|
|
11
|
+
let isfetched = false;
|
|
12
|
+
let datas;
|
|
13
|
+
let isXml = true;
|
|
14
|
+
if (searchPath.length === 0) {
|
|
15
|
+
searchPath = "search.xml";
|
|
16
|
+
} else if (searchPath.endsWith("json")) {
|
|
17
|
+
isXml = false;
|
|
18
|
+
}
|
|
19
|
+
const searchInputDom = document.querySelector(".search-input");
|
|
20
|
+
const resultContent = document.getElementById("search-result");
|
|
21
|
+
|
|
22
|
+
const getIndexByWord = (word, text, caseSensitive) => {
|
|
23
|
+
let wordLen = word.length;
|
|
24
|
+
if (wordLen === 0) return [];
|
|
25
|
+
let startPosition = 0;
|
|
26
|
+
let position = [];
|
|
27
|
+
let index = [];
|
|
28
|
+
if (!caseSensitive) {
|
|
29
|
+
text = text.toLowerCase();
|
|
30
|
+
word = word.toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
while ((position = text.indexOf(word, startPosition)) > -1) {
|
|
33
|
+
index.push({ position, word });
|
|
34
|
+
startPosition = position + wordLen;
|
|
35
|
+
}
|
|
36
|
+
return index;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Merge hits into slices
|
|
40
|
+
const mergeIntoSlice = (start, end, index, searchText) => {
|
|
41
|
+
let currentItem = index[index.length - 1];
|
|
42
|
+
let { position, word } = currentItem;
|
|
43
|
+
let hits = [];
|
|
44
|
+
let searchTextCountInSlice = 0;
|
|
45
|
+
|
|
46
|
+
// Merge hits into the slice
|
|
47
|
+
while (position + word.length <= end && index.length !== 0) {
|
|
48
|
+
if (word === searchText) {
|
|
49
|
+
searchTextCountInSlice++;
|
|
50
|
+
}
|
|
51
|
+
hits.push({
|
|
52
|
+
position,
|
|
53
|
+
length: word.length,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const wordEnd = position + word.length;
|
|
57
|
+
|
|
58
|
+
// Move to the next position of the hit
|
|
59
|
+
index.pop();
|
|
60
|
+
for (let i = index.length - 1; i >= 0; i--) {
|
|
61
|
+
currentItem = index[i];
|
|
62
|
+
position = currentItem.position;
|
|
63
|
+
word = currentItem.word;
|
|
64
|
+
if (wordEnd <= position) {
|
|
65
|
+
break;
|
|
66
|
+
} else {
|
|
67
|
+
index.pop();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
hits,
|
|
74
|
+
start,
|
|
75
|
+
end,
|
|
76
|
+
searchTextCount: searchTextCountInSlice,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Highlight title and content
|
|
81
|
+
const highlightKeyword = (text, slice) => {
|
|
82
|
+
let result = "";
|
|
83
|
+
let prevEnd = slice.start;
|
|
84
|
+
slice.hits.forEach((hit) => {
|
|
85
|
+
result += text.substring(prevEnd, hit.position);
|
|
86
|
+
let end = hit.position + hit.length;
|
|
87
|
+
result += `<b class="search-keyword">${text.substring(
|
|
88
|
+
hit.position,
|
|
89
|
+
end,
|
|
90
|
+
)}</b>`;
|
|
91
|
+
prevEnd = end;
|
|
92
|
+
});
|
|
93
|
+
result += text.substring(prevEnd, slice.end);
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const inputEventFunction = () => {
|
|
98
|
+
if (!isfetched) return;
|
|
99
|
+
let searchText = searchInputDom.value.trim().toLowerCase();
|
|
100
|
+
let keywords = searchText.split(/[-\s]+/);
|
|
101
|
+
if (keywords.length > 1) {
|
|
102
|
+
keywords.push(searchText);
|
|
103
|
+
}
|
|
104
|
+
let resultItems = [];
|
|
105
|
+
if (searchText.length > 0) {
|
|
106
|
+
// Perform local searching
|
|
107
|
+
datas.forEach(({ title, content, url }) => {
|
|
108
|
+
let titleInLowerCase = title.toLowerCase();
|
|
109
|
+
let contentInLowerCase = content.toLowerCase();
|
|
110
|
+
let indexOfTitle = [];
|
|
111
|
+
let indexOfContent = [];
|
|
112
|
+
let searchTextCount = 0;
|
|
113
|
+
keywords.forEach((keyword) => {
|
|
114
|
+
indexOfTitle = indexOfTitle.concat(
|
|
115
|
+
getIndexByWord(keyword, titleInLowerCase, false),
|
|
116
|
+
);
|
|
117
|
+
indexOfContent = indexOfContent.concat(
|
|
118
|
+
getIndexByWord(keyword, contentInLowerCase, false),
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Show search results
|
|
123
|
+
if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
|
|
124
|
+
let hitCount = indexOfTitle.length + indexOfContent.length;
|
|
125
|
+
// Sort index by position of keyword
|
|
126
|
+
[indexOfTitle, indexOfContent].forEach((index) => {
|
|
127
|
+
index.sort((itemLeft, itemRight) => {
|
|
128
|
+
if (itemRight.position !== itemLeft.position) {
|
|
129
|
+
return itemRight.position - itemLeft.position;
|
|
130
|
+
}
|
|
131
|
+
return itemLeft.word.length - itemRight.word.length;
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
let slicesOfTitle = [];
|
|
136
|
+
if (indexOfTitle.length !== 0) {
|
|
137
|
+
let tmp = mergeIntoSlice(0, title.length, indexOfTitle, searchText);
|
|
138
|
+
searchTextCount += tmp.searchTextCountInSlice;
|
|
139
|
+
slicesOfTitle.push(tmp);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let slicesOfContent = [];
|
|
143
|
+
while (indexOfContent.length !== 0) {
|
|
144
|
+
let item = indexOfContent[indexOfContent.length - 1];
|
|
145
|
+
let { position, word } = item;
|
|
146
|
+
// Cut out 100 characters
|
|
147
|
+
let start = position - 20;
|
|
148
|
+
let end = position + 80;
|
|
149
|
+
if (start < 0) {
|
|
150
|
+
start = 0;
|
|
151
|
+
}
|
|
152
|
+
if (end < position + word.length) {
|
|
153
|
+
end = position + word.length;
|
|
154
|
+
}
|
|
155
|
+
if (end > content.length) {
|
|
156
|
+
end = content.length;
|
|
157
|
+
}
|
|
158
|
+
let tmp = mergeIntoSlice(start, end, indexOfContent, searchText);
|
|
159
|
+
searchTextCount += tmp.searchTextCountInSlice;
|
|
160
|
+
slicesOfContent.push(tmp);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Sort slices in content by search text's count and hits' count
|
|
164
|
+
slicesOfContent.sort((sliceLeft, sliceRight) => {
|
|
165
|
+
if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
|
|
166
|
+
return sliceRight.searchTextCount - sliceLeft.searchTextCount;
|
|
167
|
+
} else if (sliceLeft.hits.length !== sliceRight.hits.length) {
|
|
168
|
+
return sliceRight.hits.length - sliceLeft.hits.length;
|
|
169
|
+
}
|
|
170
|
+
return sliceLeft.start - sliceRight.start;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Select top N slices in content
|
|
174
|
+
let upperBound = parseInt(
|
|
175
|
+
theme.navbar.search.top_n_per_article
|
|
176
|
+
? theme.navbar.search.top_n_per_article
|
|
177
|
+
: 1,
|
|
178
|
+
10,
|
|
179
|
+
);
|
|
180
|
+
if (upperBound >= 0) {
|
|
181
|
+
slicesOfContent = slicesOfContent.slice(0, upperBound);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let resultItem = "";
|
|
185
|
+
|
|
186
|
+
if (slicesOfTitle.length !== 0) {
|
|
187
|
+
resultItem += `<li><a href="${url}" class="search-result-title">${highlightKeyword(
|
|
188
|
+
title,
|
|
189
|
+
slicesOfTitle[0],
|
|
190
|
+
)}</a>`;
|
|
191
|
+
} else {
|
|
192
|
+
resultItem += `<li><a href="${url}" class="search-result-title">${title}</a>`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
slicesOfContent.forEach((slice) => {
|
|
196
|
+
resultItem += `<a href="${url}"><p class="search-result">${highlightKeyword(
|
|
197
|
+
content,
|
|
198
|
+
slice,
|
|
199
|
+
)}...</p></a>`;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
resultItem += "</li>";
|
|
203
|
+
resultItems.push({
|
|
204
|
+
item: resultItem,
|
|
205
|
+
id: resultItems.length,
|
|
206
|
+
hitCount,
|
|
207
|
+
searchTextCount,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (keywords.length === 1 && keywords[0] === "") {
|
|
213
|
+
resultContent.innerHTML =
|
|
214
|
+
'<div id="no-result"><i class="fa-solid fa-magnifying-glass fa-5x"></i></div>';
|
|
215
|
+
} else if (resultItems.length === 0) {
|
|
216
|
+
resultContent.innerHTML =
|
|
217
|
+
'<div id="no-result"><i class="fa-solid fa-box-open fa-5x"></i></div>';
|
|
218
|
+
} else {
|
|
219
|
+
resultItems.sort((resultLeft, resultRight) => {
|
|
220
|
+
if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
|
|
221
|
+
return resultRight.searchTextCount - resultLeft.searchTextCount;
|
|
222
|
+
} else if (resultLeft.hitCount !== resultRight.hitCount) {
|
|
223
|
+
return resultRight.hitCount - resultLeft.hitCount;
|
|
224
|
+
}
|
|
225
|
+
return resultRight.id - resultLeft.id;
|
|
226
|
+
});
|
|
227
|
+
let searchResultList = '<ul class="search-result-list">';
|
|
228
|
+
resultItems.forEach((result) => {
|
|
229
|
+
searchResultList += result.item;
|
|
230
|
+
});
|
|
231
|
+
searchResultList += "</ul>";
|
|
232
|
+
resultContent.innerHTML = searchResultList;
|
|
233
|
+
window.pjax && window.pjax.refresh(resultContent);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const fetchData = () => {
|
|
238
|
+
fetch(config.root + searchPath)
|
|
239
|
+
.then((response) => response.text())
|
|
240
|
+
.then((res) => {
|
|
241
|
+
// Get the contents from search data
|
|
242
|
+
isfetched = true;
|
|
243
|
+
datas = isXml
|
|
244
|
+
? [
|
|
245
|
+
...new DOMParser()
|
|
246
|
+
.parseFromString(res, "text/xml")
|
|
247
|
+
.querySelectorAll("entry"),
|
|
248
|
+
].map((element) => {
|
|
249
|
+
return {
|
|
250
|
+
title: element.querySelector("title").textContent,
|
|
251
|
+
content: element.querySelector("content").textContent,
|
|
252
|
+
url: element.querySelector("url").textContent,
|
|
253
|
+
};
|
|
254
|
+
})
|
|
255
|
+
: JSON.parse(res);
|
|
256
|
+
// Only match articles with not empty titles
|
|
257
|
+
datas = datas
|
|
258
|
+
.filter((data) => data.title)
|
|
259
|
+
.map((data) => {
|
|
260
|
+
data.title = data.title.trim();
|
|
261
|
+
data.content = data.content
|
|
262
|
+
? data.content.trim().replace(/<[^>]+>/g, "")
|
|
263
|
+
: "";
|
|
264
|
+
data.url = decodeURIComponent(data.url).replace(/\/{2,}/g, "/");
|
|
265
|
+
return data;
|
|
266
|
+
});
|
|
267
|
+
// Remove loading animation
|
|
268
|
+
const noResultDom = document.querySelector("#no-result");
|
|
269
|
+
noResultDom &&
|
|
270
|
+
(noResultDom.innerHTML =
|
|
271
|
+
'<i class="fa-solid fa-magnifying-glass fa-5x"></i>');
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
if (theme.navbar.search.preload) {
|
|
276
|
+
fetchData();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (searchInputDom) {
|
|
280
|
+
searchInputDom.addEventListener("input", inputEventFunction);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Handle and trigger popup window
|
|
284
|
+
document.querySelectorAll(".search-popup-trigger").forEach((element) => {
|
|
285
|
+
element.addEventListener("click", () => {
|
|
286
|
+
document.body.style.overflow = "hidden";
|
|
287
|
+
document.querySelector(".search-pop-overlay").classList.add("active");
|
|
288
|
+
setTimeout(() => searchInputDom.focus(), 500);
|
|
289
|
+
if (!isfetched) fetchData();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// Monitor main search box
|
|
294
|
+
const onPopupClose = () => {
|
|
295
|
+
document.body.style.overflow = "";
|
|
296
|
+
document.querySelector(".search-pop-overlay").classList.remove("active");
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
document
|
|
300
|
+
.querySelector(".search-pop-overlay")
|
|
301
|
+
.addEventListener("click", (event) => {
|
|
302
|
+
if (event.target === document.querySelector(".search-pop-overlay")) {
|
|
303
|
+
onPopupClose();
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
document
|
|
307
|
+
.querySelector(".search-input-field-pre")
|
|
308
|
+
.addEventListener("click", () => {
|
|
309
|
+
searchInputDom.value = "";
|
|
310
|
+
searchInputDom.focus();
|
|
311
|
+
inputEventFunction();
|
|
312
|
+
});
|
|
313
|
+
document
|
|
314
|
+
.querySelector(".popup-btn-close")
|
|
315
|
+
.addEventListener("click", onPopupClose);
|
|
316
|
+
try {
|
|
317
|
+
swup.hooks.on("page:view", (visit) => {
|
|
318
|
+
onPopupClose();
|
|
319
|
+
});
|
|
320
|
+
} catch (e) {}
|
|
321
|
+
|
|
322
|
+
window.addEventListener("keyup", (event) => {
|
|
323
|
+
if (event.key === "Escape") {
|
|
324
|
+
onPopupClose();
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const footerRuntime = () => {
|
|
2
|
+
const startTime = theme.footerStart;
|
|
3
|
+
window.setTimeout(footerRuntime, 1000); // passing function reference instead of string
|
|
4
|
+
|
|
5
|
+
const X = new Date(startTime);
|
|
6
|
+
const Y = new Date();
|
|
7
|
+
const T = Y.getTime() - X.getTime();
|
|
8
|
+
const M = 24 * 60 * 60 * 1000;
|
|
9
|
+
const a = T / M;
|
|
10
|
+
const A = Math.floor(a);
|
|
11
|
+
const b = (a - A) * 24;
|
|
12
|
+
const B = Math.floor(b);
|
|
13
|
+
const c = (b - B) * 60;
|
|
14
|
+
const C = Math.floor((b - B) * 60);
|
|
15
|
+
const D = Math.floor((c - C) * 60);
|
|
16
|
+
|
|
17
|
+
const runtime_days = document.getElementById("runtime_days");
|
|
18
|
+
const runtime_hours = document.getElementById("runtime_hours");
|
|
19
|
+
const runtime_minutes = document.getElementById("runtime_minutes");
|
|
20
|
+
const runtime_seconds = document.getElementById("runtime_seconds");
|
|
21
|
+
|
|
22
|
+
if (runtime_days) runtime_days.innerHTML = A;
|
|
23
|
+
if (runtime_hours) runtime_hours.innerHTML = B;
|
|
24
|
+
if (runtime_minutes) runtime_minutes.innerHTML = C;
|
|
25
|
+
if (runtime_seconds) runtime_seconds.innerHTML = D;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
window.addEventListener("DOMContentLoaded", footerRuntime);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const initScrollTopBottom = () => {
|
|
2
|
+
const backToTopButton_dom = document.querySelector(".tool-scroll-to-top");
|
|
3
|
+
const backToBottomButton_dom = document.querySelector(
|
|
4
|
+
".tool-scroll-to-bottom",
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
const backToTop = () => {
|
|
8
|
+
window.scrollTo({
|
|
9
|
+
top: 0, // scrolls to the top of the page
|
|
10
|
+
behavior: "smooth",
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const backToBottom = () => {
|
|
15
|
+
const docHeight = document.body.scrollHeight;
|
|
16
|
+
window.scrollTo({
|
|
17
|
+
top: docHeight, // scrolls to the bottom of the page
|
|
18
|
+
behavior: "smooth",
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const initBackToTop = () => {
|
|
23
|
+
backToTopButton_dom.addEventListener("click", backToTop);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const initBackToBottom = () => {
|
|
27
|
+
backToBottomButton_dom.addEventListener("click", backToBottom);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
initBackToTop();
|
|
31
|
+
initBackToBottom();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default initScrollTopBottom;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* main function */
|
|
2
|
+
|
|
3
|
+
import { main } from "../main.js";
|
|
4
|
+
|
|
5
|
+
export function initTocToggle() {
|
|
6
|
+
const TocToggle = {
|
|
7
|
+
toggleBar: document.querySelector(".page-aside-toggle"),
|
|
8
|
+
postPageContainerDom: document.querySelector(".post-page-container"),
|
|
9
|
+
toggleBarIcon: document.querySelector(".page-aside-toggle i"),
|
|
10
|
+
articleContentContainerDom: document.querySelector(
|
|
11
|
+
".article-content-container",
|
|
12
|
+
),
|
|
13
|
+
mainContentDom: document.querySelector(".main-content"),
|
|
14
|
+
|
|
15
|
+
isOpenPageAside: false,
|
|
16
|
+
|
|
17
|
+
initToggleBarButton() {
|
|
18
|
+
this.toggleBar &&
|
|
19
|
+
this.toggleBar.addEventListener("click", () => {
|
|
20
|
+
this.isOpenPageAside = !this.isOpenPageAside;
|
|
21
|
+
main.styleStatus.isOpenPageAside = this.isOpenPageAside;
|
|
22
|
+
main.setStyleStatus();
|
|
23
|
+
this.changePageLayoutWhenOpenToggle(this.isOpenPageAside);
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
toggleClassName(element, className, condition) {
|
|
28
|
+
if (element) {
|
|
29
|
+
element.classList.toggle(className, condition);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
changePageLayoutWhenOpenToggle(isOpen) {
|
|
33
|
+
this.toggleClassName(this.toggleBarIcon, "fas", isOpen);
|
|
34
|
+
this.toggleClassName(this.toggleBarIcon, "fa-indent", isOpen);
|
|
35
|
+
this.toggleClassName(this.toggleBarIcon, "fa-outdent", !isOpen);
|
|
36
|
+
this.toggleClassName(this.postPageContainerDom, "show-toc", isOpen);
|
|
37
|
+
this.toggleClassName(this.mainContentDom, "has-toc", isOpen);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
pageAsideHandleOfTOC(isOpen) {
|
|
41
|
+
this.toggleBar.style.display = "flex";
|
|
42
|
+
this.isOpenPageAside = isOpen;
|
|
43
|
+
this.changePageLayoutWhenOpenToggle(isOpen);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
TocToggle.initToggleBarButton();
|
|
48
|
+
return TocToggle;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Event listeners
|
|
52
|
+
try {
|
|
53
|
+
swup.hooks.on("page:view", () => {
|
|
54
|
+
initTocToggle();
|
|
55
|
+
});
|
|
56
|
+
} catch (e) {}
|
|
57
|
+
|
|
58
|
+
document.addEventListener("DOMContentLoaded", initTocToggle);
|