hexo-theme-solitude 1.2.6 → 1.3.1
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/CONTRIBUTING.md +41 -0
- package/README.md +8 -8
- package/README_EN.md +6 -6
- package/_config.yml +502 -297
- package/languages/en-US.yml +105 -8
- package/languages/zh-CN.yml +98 -1
- package/layout/archive.pug +4 -5
- package/layout/category.pug +4 -5
- package/layout/includes/body/mode.pug +40 -0
- package/layout/includes/console.pug +15 -16
- package/layout/includes/footer.pug +26 -28
- package/layout/includes/head/config.pug +27 -8
- package/layout/includes/head/fest.pug +22 -0
- package/layout/includes/head/opengraph.pug +11 -0
- package/layout/includes/head.pug +1 -3
- package/layout/includes/header.pug +1 -1
- package/layout/includes/inject/body.pug +36 -13
- package/layout/includes/inject/head.pug +30 -20
- package/layout/includes/layout.pug +12 -8
- package/layout/includes/loading.pug +1 -64
- package/layout/includes/mixins/articleSort.pug +4 -4
- package/layout/includes/mixins/pagination.pug +1 -1
- package/layout/includes/nav.pug +10 -10
- package/layout/includes/page/about.pug +1 -0
- package/layout/includes/page/categories.pug +3 -3
- package/layout/includes/page/default.pug +1 -1
- package/layout/includes/page/echarts.pug +3 -3
- package/layout/includes/page/equipment.pug +0 -1
- package/layout/includes/page/links.pug +5 -26
- package/layout/includes/page/moments.pug +0 -1
- package/layout/includes/page/music.pug +19 -0
- package/layout/includes/page/not_configured.pug +18 -0
- package/layout/includes/page/rss.pug +20 -22
- package/layout/includes/page/says.pug +1 -2
- package/layout/includes/page/tags.pug +3 -3
- package/layout/includes/page/tlink.pug +0 -1
- package/layout/includes/sidebar.pug +7 -7
- package/layout/includes/widgets/aside/aside.pug +13 -1
- package/layout/includes/widgets/aside/asideArchive.pug +5 -3
- package/layout/includes/widgets/aside/asideCustom.pug +6 -0
- package/layout/includes/widgets/aside/asideHistory.pug +3 -3
- package/layout/includes/widgets/aside/asideInfoCard.pug +4 -6
- package/layout/includes/widgets/aside/asideNewestPost.pug +1 -1
- package/layout/includes/widgets/aside/asideSwitch.pug +0 -11
- package/layout/includes/widgets/aside/asideTag.pug +2 -2
- package/layout/includes/widgets/aside/asideToc.pug +1 -1
- package/layout/includes/widgets/aside/asideWebInfo.pug +6 -6
- package/layout/includes/widgets/aside/asideWelcome.pug +1 -1
- package/layout/includes/widgets/home/banner.pug +2 -2
- package/layout/includes/widgets/home/bbTimeList.pug +3 -3
- package/layout/includes/widgets/home/categoryBar.pug +3 -3
- package/layout/includes/widgets/home/categoryGroup.pug +2 -2
- package/layout/includes/widgets/home/hometop.pug +7 -7
- package/layout/includes/widgets/home/postList.pug +12 -8
- package/layout/includes/widgets/home/topGroup.pug +17 -13
- package/layout/includes/widgets/nav/left.pug +6 -6
- package/layout/includes/widgets/nav/menu.pug +4 -4
- package/layout/includes/widgets/nav/right.pug +14 -14
- package/layout/includes/widgets/page/about/authorinfo.pug +1 -1
- package/layout/includes/widgets/page/about/award.pug +11 -9
- package/layout/includes/widgets/page/about/contentinfo.pug +7 -7
- package/layout/includes/widgets/page/about/hobbies.pug +1 -1
- package/layout/includes/widgets/page/about/motto.pug +2 -2
- package/layout/includes/widgets/page/about/other.pug +10 -9
- package/layout/includes/widgets/page/about/personalities.pug +2 -2
- package/layout/includes/widgets/page/about/skillsinfo.pug +10 -12
- package/layout/includes/widgets/page/about/tenyear.pug +48 -0
- package/layout/includes/widgets/page/banner.pug +2 -2
- package/layout/includes/widgets/page/links/banner.pug +12 -14
- package/layout/includes/widgets/page/links/linksItem.pug +0 -1
- package/layout/includes/widgets/page/moments/angle.pug +7 -12
- package/layout/includes/widgets/page/moments/index.pug +7 -2
- package/layout/includes/widgets/post/award.pug +12 -8
- package/layout/includes/widgets/post/copyright.pug +16 -14
- package/layout/includes/widgets/post/postMeta.pug +36 -25
- package/layout/includes/widgets/post/postNav.pug +15 -15
- package/layout/includes/widgets/randomlink.pug +10 -5
- package/layout/includes/widgets/rightside/index.pug +9 -8
- package/layout/includes/widgets/third-party/ai/index.pug +12 -0
- package/layout/includes/widgets/third-party/comments/comment.pug +6 -1
- package/layout/includes/widgets/third-party/comments/twikoo.pug +5 -4
- package/layout/includes/widgets/third-party/comments/waline.pug +4 -5
- package/layout/includes/widgets/third-party/music.pug +1 -1
- package/layout/includes/widgets/third-party/pjax.pug +6 -1
- package/layout/includes/widgets/third-party/search/algolia-search.pug +4 -3
- package/layout/includes/widgets/third-party/search/index.pug +2 -2
- package/layout/includes/widgets/third-party/search/local-search.pug +3 -3
- package/layout/index.pug +5 -6
- package/layout/page.pug +34 -29
- package/layout/post.pug +3 -23
- package/layout/tag.pug +3 -3
- package/package.json +2 -2
- package/scripts/filter/checkThemeConfig.js +0 -5
- package/scripts/helper/cdn.js +12 -0
- package/scripts/helper/page.js +13 -0
- package/scripts/helper/related_post.js +0 -1
- package/scripts/tags/button.js +21 -0
- package/scripts/tags/card.js +9 -0
- package/scripts/tags/checkbox.js +51 -0
- package/scripts/tags/fold.js +0 -5
- package/scripts/tags/image.js +75 -0
- package/scripts/tags/inline-image.js +12 -0
- package/scripts/tags/label.js +10 -0
- package/scripts/tags/link.js +2 -0
- package/scripts/tags/media.js +29 -0
- package/scripts/tags/span.js +17 -0
- package/scripts/tags/timeline.js +2 -15
- package/scripts/tags/u.js +7 -0
- package/source/css/_global/animation.css +57 -0
- package/source/css/_global/index.styl +5 -20
- package/source/css/_global/var.styl +16 -1
- package/source/css/_layout/{base.styl → basic.styl} +24 -116
- package/source/css/_layout/header.styl +204 -616
- package/source/css/_layout/index.styl +29 -271
- package/source/css/_mode/index.styl +102 -93
- package/source/css/_page/_home/category-bar.styl +74 -0
- package/source/css/_page/_home/home-top.styl +541 -0
- package/source/css/_page/_home/index.styl +15 -0
- package/source/css/_page/_home/pagination.styl +176 -0
- package/source/css/_page/_home/recent-post.styl +204 -0
- package/source/css/_page/about/index.styl +1 -0
- package/source/css/_page/about/tenyear.styl +56 -0
- package/source/css/_page/about.styl +555 -626
- package/source/css/_page/category.styl +95 -119
- package/source/css/_page/douban.styl +126 -0
- package/source/css/_page/equipment.styl +100 -99
- package/source/css/_page/error.styl +130 -146
- package/source/css/_page/home.styl +41 -50
- package/source/css/_page/index.styl +42 -10
- package/source/css/_page/links.styl +306 -0
- package/source/css/_page/moment.styl +51 -51
- package/source/css/_page/music.styl +506 -0
- package/source/css/_page/rss.styl +62 -67
- package/source/css/_page/says.styl +375 -344
- package/source/css/_page/tag.styl +15 -13
- package/source/css/_widgets/{aside → _aside}/flip.styl +7 -5
- package/source/css/_widgets/{aside → _aside}/history.styl +9 -2
- package/source/css/_widgets/_aside/index.styl +96 -0
- package/source/css/_widgets/{aside → _aside}/info.styl +86 -89
- package/source/css/_widgets/{aside → _aside}/newPost.styl +7 -1
- package/source/css/_widgets/{aside → _aside}/toc.styl +28 -5
- package/source/css/_widgets/{comment → _comment}/index.styl +4 -12
- package/source/css/_widgets/{comment → _comment}/twikoo.styl +5 -2
- package/source/css/_widgets/{comment → _comment}/waline.styl +21 -5
- package/source/css/{_extra → _widgets/_extra}/console.styl +33 -10
- package/source/css/_widgets/_extra/fullpage.styl +46 -0
- package/source/css/_widgets/_extra/music.styl +218 -0
- package/source/css/_widgets/_extra/pace.styl +39 -0
- package/source/css/_widgets/_extra/rightmenu.styl +78 -0
- package/source/css/_widgets/_mixins/article-sort.styl +93 -0
- package/source/css/_widgets/_mixins/footer.styl +273 -0
- package/source/css/_widgets/_mixins/other.styl +34 -0
- package/source/css/_widgets/_mixins/sidebar.styl +230 -0
- package/source/css/_widgets/_post/_highlight/diff.styl +75 -0
- package/source/css/_widgets/_post/_highlight/index.styl +144 -0
- package/source/css/_widgets/_post/_highlight/theme/default.styl +12 -0
- package/source/css/_widgets/_post/_highlight/theme/mac.styl +25 -0
- package/source/css/_widgets/_post/_highlight/theme.styl +68 -0
- package/source/css/_widgets/_post/commentBarrage.styl +144 -0
- package/source/css/_widgets/_post/content.styl +152 -0
- package/source/css/_widgets/_post/copyright.styl +98 -0
- package/source/css/_widgets/_post/index.styl +20 -0
- package/source/css/_widgets/_post/meta.styl +420 -0
- package/source/css/_widgets/_post/pagination.styl +177 -0
- package/source/css/_widgets/_post/postAI.styl +131 -0
- package/source/css/{_post → _widgets/_post}/relatedPost.styl +4 -1
- package/source/css/_widgets/_post/tools.styl +249 -0
- package/source/css/{_search → _widgets/_search}/algolia-search.styl +4 -0
- package/source/css/{_search → _widgets/_search}/local-search.styl +15 -5
- package/source/css/_widgets/_tags/button.styl +60 -0
- package/source/css/_widgets/_tags/bvideo.styl +8 -0
- package/source/css/_widgets/_tags/card.styl +52 -0
- package/source/css/_widgets/_tags/checkbox.styl +85 -0
- package/source/css/_widgets/_tags/fold.styl +79 -0
- package/source/css/_widgets/_tags/image.styl +10 -0
- package/source/css/_widgets/_tags/index.styl +61 -0
- package/source/css/_widgets/_tags/inline-image.styl +6 -0
- package/source/css/_widgets/_tags/label.styl +3 -0
- package/source/css/_widgets/_tags/link.styl +80 -0
- package/source/css/_widgets/_tags/note.styl +101 -0
- package/source/css/_widgets/_tags/span.styl +61 -0
- package/source/css/_widgets/_tags/tabs.styl +105 -0
- package/source/css/_widgets/_tags/timeline.styl +80 -0
- package/source/css/_widgets/index.styl +50 -1
- package/source/css/index.styl +0 -25
- package/source/js/{commentBarrage.js → extend/comment/twikoo/commentBarrage.js} +0 -4
- package/source/js/extend/comment/{twikoo.js → twikoo/twikoo.js} +12 -40
- package/source/js/extend/comment/waline/commentBarrage.js +155 -0
- package/source/js/extend/comment/{waline.js → waline/waline.js} +10 -11
- package/source/js/extend/search/algolia-search.js +1 -5
- package/source/js/extend/search/local-search.js +33 -13
- package/source/js/main.js +135 -171
- package/source/js/music.js +129 -0
- package/source/js/utils.js +4 -7
- package/source/lib/cover-color.min.js +7 -0
- package/source/lib/rightside.min.js +1 -0
- package/source/lib/sco-ai.min.js +8 -0
- package/source/lib/snackbar.min.css +1 -1
- package/source/lib/txmap.min.js +1 -0
- package/source/lib/universe.min.js +1 -0
- package/source/lib/view-image.min.js +1 -1
- package/layout/includes/widgets/aside/asidePower.pug +0 -19
- package/layout/includes/widgets/home/rencentPost.pug +0 -26
- package/source/css/_extra/rightmenu.styl +0 -83
- package/source/css/_layout/articleSort.styl +0 -199
- package/source/css/_layout/footer.styl +0 -359
- package/source/css/_layout/sidebar.styl +0 -226
- package/source/css/_page/homeTop.styl +0 -1035
- package/source/css/_page/link.styl +0 -433
- package/source/css/_post/commentBarrage.styl +0 -149
- package/source/css/_post/externalTags.styl +0 -694
- package/source/css/_post/highlight.styl +0 -96
- package/source/css/_post/index.styl +0 -935
- package/source/css/_post/pagination.styl +0 -467
- package/source/css/_post/postContent.styl +0 -957
- package/source/css/_post/reward.styl +0 -217
- package/source/css/_widgets/aside/index.styl +0 -156
- package/source/css/_widgets/aside/power.styl +0 -90
- package/source/img/logo-horizontal_version.png +0 -0
- package/source/img/pwa/16.png +0 -0
- package/source/img/pwa/180.png +0 -0
- package/source/img/pwa/192.png +0 -0
- package/source/img/pwa/32.png +0 -0
- package/source/img/pwa/512.png +0 -0
- package/source/img/pwa/logo.png +0 -0
- package/source/img/pwa/siteicon/splash-1125x2436.png +0 -0
- package/source/img/pwa/siteicon/splash-1136x640.png +0 -0
- package/source/img/pwa/siteicon/splash-1170x2532.png +0 -0
- package/source/img/pwa/siteicon/splash-1179x2556.png +0 -0
- package/source/img/pwa/siteicon/splash-1242x2208.png +0 -0
- package/source/img/pwa/siteicon/splash-1242x2688.png +0 -0
- package/source/img/pwa/siteicon/splash-1248x2778.png +0 -0
- package/source/img/pwa/siteicon/splash-1290x2796.png +0 -0
- package/source/img/pwa/siteicon/splash-1334x750.png +0 -0
- package/source/img/pwa/siteicon/splash-1536x2048.png +0 -0
- package/source/img/pwa/siteicon/splash-1620x2160.png +0 -0
- package/source/img/pwa/siteicon/splash-1668x2224.png +0 -0
- package/source/img/pwa/siteicon/splash-1668x2388.png +0 -0
- package/source/img/pwa/siteicon/splash-1792x828.png +0 -0
- package/source/img/pwa/siteicon/splash-2048x1536.png +0 -0
- package/source/img/pwa/siteicon/splash-2048x2732.png +0 -0
- package/source/img/pwa/siteicon/splash-2160x1620.png +0 -0
- package/source/img/pwa/siteicon/splash-2208x1242.png +0 -0
- package/source/img/pwa/siteicon/splash-2224x1668.png +0 -0
- package/source/img/pwa/siteicon/splash-2388x1668.png +0 -0
- package/source/img/pwa/siteicon/splash-2436x1125.png +0 -0
- package/source/img/pwa/siteicon/splash-2532x1170.png +0 -0
- package/source/img/pwa/siteicon/splash-2556x1179.png +0 -0
- package/source/img/pwa/siteicon/splash-2688x1242.png +0 -0
- package/source/img/pwa/siteicon/splash-2732x2048.png +0 -0
- package/source/img/pwa/siteicon/splash-2778x1248.png +0 -0
- package/source/img/pwa/siteicon/splash-2796x1290.png +0 -0
- package/source/img/pwa/siteicon/splash-640x1136.png +0 -0
- package/source/img/pwa/siteicon/splash-750x1334.png +0 -0
- package/source/img/pwa/siteicon/splash-828x1792.png +0 -0
- package/source/img/solitude-show.jpg +0 -0
- package/source/js/extend/covercolor/local.js +0 -160
- package/source/js/rightside.js +0 -402
- package/source/js/txmap.js +0 -236
- package/source/lib/chuckle-post-ai.js +0 -1
- /package/source/css/_widgets/{aside → _aside}/allinfo.styl +0 -0
- /package/source/css/_widgets/{aside → _aside}/welcome.styl +0 -0
- /package/source/img/{theme/avatar.png → avatar.png} +0 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
function initializeCommentBarrage() {
|
2
|
+
window.commentBarrageInitialized = !0;
|
3
|
+
let config = {
|
4
|
+
maxBarrage: 1,
|
5
|
+
barrageTime: 8e3,
|
6
|
+
walineUrl: GLOBAL_CONFIG.comment.waline.url,
|
7
|
+
pageUrl: window.location.pathname,
|
8
|
+
}
|
9
|
+
new class {
|
10
|
+
commentInterval = null
|
11
|
+
|
12
|
+
constructor(config) {
|
13
|
+
this.config = {
|
14
|
+
...config,
|
15
|
+
barrageTimer: [],
|
16
|
+
barrageList: [],
|
17
|
+
barrageIndex: 0,
|
18
|
+
dom: document.querySelector(".comment-barrage")
|
19
|
+
};
|
20
|
+
this.commentInterval = null;
|
21
|
+
this.hoverOnCommentBarrage = false;
|
22
|
+
this.init();
|
23
|
+
}
|
24
|
+
|
25
|
+
async fetchComments() {
|
26
|
+
const url = new URL(`${this.config.walineUrl}/api/comment`);
|
27
|
+
const params = {
|
28
|
+
path: this.config.pageUrl,
|
29
|
+
sortBy: 'insertedAt_asc'
|
30
|
+
};
|
31
|
+
|
32
|
+
for (const [key, value] of Object.entries(params)) {
|
33
|
+
url.searchParams.append(key, value);
|
34
|
+
}
|
35
|
+
|
36
|
+
try {
|
37
|
+
const response = await fetch(url, {
|
38
|
+
method: "GET",
|
39
|
+
headers: {
|
40
|
+
"Content-Type": "application/json"
|
41
|
+
},
|
42
|
+
});
|
43
|
+
|
44
|
+
if (!response.ok) {
|
45
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
46
|
+
}
|
47
|
+
|
48
|
+
const data = await response.json();
|
49
|
+
return data.data;
|
50
|
+
} catch (error) {
|
51
|
+
console.error("An error occurred while fetching comments: ", error);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
commentLinkFilter(comments) {
|
56
|
+
return comments.data.flatMap(comment => this.getCommentReplies(comment));
|
57
|
+
}
|
58
|
+
|
59
|
+
getCommentReplies(comment) {
|
60
|
+
if (!comment.replies) {
|
61
|
+
return [comment];
|
62
|
+
}
|
63
|
+
return [comment, ...comment.replies.flatMap(reply => this.getCommentReplies(reply))];
|
64
|
+
}
|
65
|
+
|
66
|
+
processCommentContent(comment) {
|
67
|
+
const processed = comment.replace(/<blockquote\b[^>]*>[\s\S]*?<\/blockquote>|<[^>]*>|\n/g, "").trim();
|
68
|
+
return processed ? `<p>${processed}</p>` : "";
|
69
|
+
}
|
70
|
+
|
71
|
+
createCommentBarrage(comment) {
|
72
|
+
const content = this.processCommentContent(comment.comment).trim();
|
73
|
+
if (!content) {
|
74
|
+
return false;
|
75
|
+
}
|
76
|
+
|
77
|
+
const element = document.createElement("div");
|
78
|
+
element.classList.add("comment-barrage-item");
|
79
|
+
element.innerHTML = `
|
80
|
+
<div class="barrageHead">
|
81
|
+
<a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">热评</a>
|
82
|
+
<div class="barrageNick">${comment.nick}</div>
|
83
|
+
<img class="barrageAvatar" src="https://cravatar.cn/avatar/${comment.avatar}"/>
|
84
|
+
<a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();">
|
85
|
+
<i class="scoicon sco-close-fill"></i>
|
86
|
+
</a>
|
87
|
+
</div>
|
88
|
+
<a class="barrageContent" href="javascript:sco.scrollTo('${comment.objectId}');">${comment.comment}</a>
|
89
|
+
`;
|
90
|
+
|
91
|
+
this.config.dom.appendChild(element);
|
92
|
+
this.config.barrageTimer.push(element);
|
93
|
+
|
94
|
+
return true;
|
95
|
+
}
|
96
|
+
|
97
|
+
removeCommentBarrage(element) {
|
98
|
+
element.className = "comment-barrage-item out";
|
99
|
+
setTimeout(() => {
|
100
|
+
this.config.dom.removeChild(element);
|
101
|
+
}, 1000);
|
102
|
+
}
|
103
|
+
|
104
|
+
async initCommentBarrage() {
|
105
|
+
const commentBarrage = document.querySelector(".comment-barrage");
|
106
|
+
const menuCommentBarrageText = document.querySelector(".menu-commentBarrage-text");
|
107
|
+
const consoleCommentBarrage = document.querySelector("#consoleCommentBarrage");
|
108
|
+
|
109
|
+
if (localStorage.getItem("commentBarrageSwitch") != null) {
|
110
|
+
commentBarrage.style.display = "flex";
|
111
|
+
GLOBAL_CONFIG.rightside.enable && (menuCommentBarrageText.textContent = "关闭热评");
|
112
|
+
consoleCommentBarrage.classList.add("on");
|
113
|
+
} else {
|
114
|
+
commentBarrage.style.display = "none";
|
115
|
+
GLOBAL_CONFIG.rightside.enable && (menuCommentBarrageText.textContent = "显示热评");
|
116
|
+
consoleCommentBarrage.classList.remove("on");
|
117
|
+
}
|
118
|
+
|
119
|
+
const comments = await this.fetchComments();
|
120
|
+
this.config.barrageList = this.commentLinkFilter(comments);
|
121
|
+
this.config.dom.innerHTML = "";
|
122
|
+
clearInterval(this.commentInterval);
|
123
|
+
this.commentInterval = null;
|
124
|
+
|
125
|
+
const createOrRemoveBarrage = () => {
|
126
|
+
if (this.config.barrageList.length && !this.hoverOnCommentBarrage) {
|
127
|
+
if (!this.createCommentBarrage(this.config.barrageList[this.config.barrageIndex])) {
|
128
|
+
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
129
|
+
return createOrRemoveBarrage();
|
130
|
+
}
|
131
|
+
this.config.barrageIndex = (this.config.barrageIndex + 1) % this.config.barrageList.length;
|
132
|
+
}
|
133
|
+
if (this.config.barrageTimer.length > (this.config.barrageList.length > this.config.maxBarrage ? this.config.maxBarrage : this.config.barrageList.length) && !this.hoverOnCommentBarrage) {
|
134
|
+
this.removeCommentBarrage(this.config.barrageTimer.shift());
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
138
|
+
setTimeout(() => {
|
139
|
+
createOrRemoveBarrage();
|
140
|
+
if (this.commentInterval) {
|
141
|
+
clearInterval(this.commentInterval);
|
142
|
+
}
|
143
|
+
this.commentInterval = setInterval(createOrRemoveBarrage, this.config.barrageTime);
|
144
|
+
}, 3000);
|
145
|
+
}
|
146
|
+
|
147
|
+
async init() {
|
148
|
+
await this.initCommentBarrage();
|
149
|
+
const commentBarrage = document.querySelector(".comment-barrage");
|
150
|
+
commentBarrage.addEventListener('mouseover', () => this.hoverOnCommentBarrage = true);
|
151
|
+
commentBarrage.addEventListener('mouseout', () => this.hoverOnCommentBarrage = false);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
(config)
|
155
|
+
}
|
@@ -1,17 +1,16 @@
|
|
1
1
|
const changeContent = (content) => {
|
2
|
-
if (content === '') return content
|
2
|
+
if (content === '') return content;
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
const replacements = [
|
5
|
+
{ regex: /<img.*?src="(.*?)"?[^\>]+>/ig, replacement: '[图片]' },
|
6
|
+
{ regex: /<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, replacement: '[链接]' },
|
7
|
+
{ regex: /<pre><code>.*?<\/pre>/gi, replacement: '[代码]' },
|
8
|
+
{ regex: /<[^>]+>/g, replacement: "" }
|
9
|
+
];
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return content
|
11
|
+
content = replacements.reduce((str, { regex, replacement }) => str.replace(regex, replacement), content);
|
12
|
+
|
13
|
+
return content.length > 150 ? content.substring(0, 150) + '...' : content;
|
15
14
|
}
|
16
15
|
|
17
16
|
const $asideList = document.querySelector('#card-newest-comments .aside-list')
|
@@ -141,11 +141,7 @@ window.addEventListener("load", () => {
|
|
141
141
|
},
|
142
142
|
});
|
143
143
|
|
144
|
-
|
145
|
-
container: "#algolia-tips > #algolia-poweredBy",
|
146
|
-
});
|
147
|
-
|
148
|
-
search.addWidgets([configure, searchBox,stats, hits,powerBy, pagination]); // add the widgets to the instantsearch instance
|
144
|
+
search.addWidgets([configure, searchBox,stats, hits, pagination]);
|
149
145
|
|
150
146
|
search.start();
|
151
147
|
|
@@ -69,28 +69,37 @@ window.onload = () => {
|
|
69
69
|
const $results = document.getElementById("search-results");
|
70
70
|
const $search = document.getElementById("search-input");
|
71
71
|
$search.addEventListener('keydown', function (e) {
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
if (e.keyCode === 13) {
|
73
|
+
e.preventDefault();
|
74
|
+
$results.innerHTML = '';
|
75
|
+
query = this.value.trim();
|
76
|
+
if (query !== '') {
|
75
77
|
results = search(query);
|
76
78
|
renderResults(results, currentPage);
|
77
79
|
renderPagination(results.length);
|
80
|
+
} else {
|
81
|
+
clearSearchResults();
|
78
82
|
}
|
79
83
|
}
|
80
|
-
)
|
81
|
-
;
|
82
|
-
}
|
83
|
-
function search(query) {
|
84
|
-
return idx.search(query).map(result => {
|
85
|
-
return store.filter(page => {
|
86
|
-
return page.link === result.ref;
|
87
|
-
})[0];
|
88
84
|
});
|
89
85
|
}
|
86
|
+
function clearSearchResults() {
|
87
|
+
const $results = document.getElementById("search-results");
|
88
|
+
const $pagination = document.getElementById("search-pagination");
|
89
|
+
const $tips = document.getElementById("search-tips");
|
90
|
+
|
91
|
+
$results.innerHTML = '';
|
92
|
+
$pagination.innerHTML = '';
|
93
|
+
$tips.innerHTML = '';
|
94
|
+
}
|
95
|
+
function search(query) {
|
96
|
+
const regex = new RegExp(query.split('').join('.*'), 'i');
|
97
|
+
return store.filter(page => regex.test(page.title) || regex.test(page.content));
|
98
|
+
}
|
90
99
|
function renderResults(results, page) {
|
91
100
|
const $search_results = document.getElementById("search-results");
|
92
101
|
$search_results.innerHTML = '';
|
93
|
-
const $tips = document.getElementById("search-tips")
|
102
|
+
const $tips = document.getElementById("search-tips");
|
94
103
|
$tips.innerHTML = '';
|
95
104
|
const start = page * resultsPerPage;
|
96
105
|
const end = start + resultsPerPage;
|
@@ -107,7 +116,8 @@ window.onload = () => {
|
|
107
116
|
const $link = document.createElement("a");
|
108
117
|
$link.className = "search-result-title";
|
109
118
|
$link.href = result.link;
|
110
|
-
|
119
|
+
const title = highlightSearchKeyword(result.title, query);
|
120
|
+
$link.innerHTML = title;
|
111
121
|
$result.appendChild($link);
|
112
122
|
$search_results.appendChild($result);
|
113
123
|
});
|
@@ -116,6 +126,12 @@ window.onload = () => {
|
|
116
126
|
count.innerHTML = `共 <b>${results.length}</b> 条结果`;
|
117
127
|
$tips.appendChild(count);
|
118
128
|
}
|
129
|
+
|
130
|
+
function highlightSearchKeyword(text, keyword) {
|
131
|
+
const regex = new RegExp(`(${keyword.split(' ').join('|')})`, 'gi');
|
132
|
+
return text.replace(regex, '<em>$1</em>');
|
133
|
+
}
|
134
|
+
|
119
135
|
function renderPagination(totalResults) {
|
120
136
|
const totalPages = Math.ceil(totalResults / resultsPerPage);
|
121
137
|
const paginationContainer = document.getElementById("search-pagination");
|
@@ -133,6 +149,10 @@ window.onload = () => {
|
|
133
149
|
button.addEventListener('click', function () {
|
134
150
|
currentPage = i;
|
135
151
|
renderResults(results, i);
|
152
|
+
document.querySelectorAll(".pagination-item").forEach(function (btn) {
|
153
|
+
btn.classList.remove('select');
|
154
|
+
});
|
155
|
+
button.classList.add('select');
|
136
156
|
});
|
137
157
|
paginationList.appendChild(button);
|
138
158
|
}
|