hexo-theme-solitude 1.0.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.
- package/LICENSE +19 -0
- package/README.md +56 -0
- package/_config.yml +432 -0
- package/languages/en-US.yml +39 -0
- package/languages/zh-CN.yml +39 -0
- package/layout/404.ejs +34 -0
- package/layout/archive.ejs +10 -0
- package/layout/category.ejs +18 -0
- package/layout/index.ejs +20 -0
- package/layout/layout.ejs +35 -0
- package/layout/page/about.ejs +13 -0
- package/layout/page/categories.ejs +12 -0
- package/layout/page/circle.ejs +5 -0
- package/layout/page/echarts.ejs +14 -0
- package/layout/page/equipment.ejs +2 -0
- package/layout/page/links.ejs +57 -0
- package/layout/page/page.ejs +3 -0
- package/layout/page/rss.ejs +37 -0
- package/layout/page/says.ejs +16 -0
- package/layout/page/tags.ejs +12 -0
- package/layout/page/tlink.ejs +11 -0
- package/layout/page.ejs +45 -0
- package/layout/partial/body.ejs +8 -0
- package/layout/partial/compoment/about/authorinfo.ejs +18 -0
- package/layout/partial/compoment/about/award.ejs +57 -0
- package/layout/partial/compoment/about/contentinfo.ejs +33 -0
- package/layout/partial/compoment/about/hobbies.ejs +44 -0
- package/layout/partial/compoment/about/motto.ejs +17 -0
- package/layout/partial/compoment/about/other.ejs +68 -0
- package/layout/partial/compoment/about/personalities.ejs +11 -0
- package/layout/partial/compoment/about/skillsinfo.ejs +62 -0
- package/layout/partial/compoment/aside/aside.ejs +28 -0
- package/layout/partial/compoment/aside/asideAllInfo.ejs +6 -0
- package/layout/partial/compoment/aside/asideArchive.ejs +11 -0
- package/layout/partial/compoment/aside/asideFlipCard.ejs +8 -0
- package/layout/partial/compoment/aside/asideInfoCard.ejs +39 -0
- package/layout/partial/compoment/aside/asideNewestPost.ejs +31 -0
- package/layout/partial/compoment/aside/asidePower.ejs +31 -0
- package/layout/partial/compoment/aside/asideSwitch.ejs +35 -0
- package/layout/partial/compoment/aside/asideTag.ejs +5 -0
- package/layout/partial/compoment/aside/asideToc.ejs +11 -0
- package/layout/partial/compoment/aside/asideWebInfo.ejs +60 -0
- package/layout/partial/compoment/circle/angle.ejs +26 -0
- package/layout/partial/compoment/circle/banner.ejs +11 -0
- package/layout/partial/compoment/circle/content.ejs +22 -0
- package/layout/partial/compoment/dorakika/rightmenu.ejs +115 -0
- package/layout/partial/compoment/equipment/list.ejs +37 -0
- package/layout/partial/compoment/home/homeCategoryBar.ejs +11 -0
- package/layout/partial/compoment/home/postList.ejs +37 -0
- package/layout/partial/compoment/hometop/bbTimeList.ejs +15 -0
- package/layout/partial/compoment/hometop/categoryGroup.ejs +19 -0
- package/layout/partial/compoment/hometop/groupTag.ejs +30 -0
- package/layout/partial/compoment/hometop/topGroup.ejs +48 -0
- package/layout/partial/compoment/inject/body.ejs +57 -0
- package/layout/partial/compoment/inject/head.ejs +19 -0
- package/layout/partial/compoment/links/banner.ejs +42 -0
- package/layout/partial/compoment/links/linksCard.ejs +27 -0
- package/layout/partial/compoment/links/linksItem.ejs +21 -0
- package/layout/partial/compoment/mixins/articleSort.ejs +26 -0
- package/layout/partial/compoment/mixins/pagination.ejs +11 -0
- package/layout/partial/compoment/nav/left.ejs +22 -0
- package/layout/partial/compoment/nav/menu.ejs +25 -0
- package/layout/partial/compoment/nav/right.ejs +42 -0
- package/layout/partial/compoment/post/award.ejs +52 -0
- package/layout/partial/compoment/post/copyright.ejs +37 -0
- package/layout/partial/compoment/post/postMeta.ejs +83 -0
- package/layout/partial/compoment/post/postNav.ejs +41 -0
- package/layout/partial/compoment/post/wave.ejs +14 -0
- package/layout/partial/compoment/says/banner.ejs +10 -0
- package/layout/partial/compoment/says/saysBottom.ejs +18 -0
- package/layout/partial/compoment/says/saysContent.ejs +11 -0
- package/layout/partial/compoment/third-party/comments/comment.ejs +12 -0
- package/layout/partial/compoment/third-party/comments/twikoo.ejs +29 -0
- package/layout/partial/compoment/third-party/comments/twikoo_k.ejs +29 -0
- package/layout/partial/compoment/third-party/music.ejs +5 -0
- package/layout/partial/compoment/third-party/pjax.ejs +31 -0
- package/layout/partial/compoment/third-party/search/algolia-search.ejs +20 -0
- package/layout/partial/compoment/third-party/search/index.ejs +10 -0
- package/layout/partial/compoment/third-party/search/local-search.ejs +22 -0
- package/layout/partial/compoment/tlink/banner.ejs +10 -0
- package/layout/partial/console.ejs +62 -0
- package/layout/partial/footer.ejs +107 -0
- package/layout/partial/head.ejs +37 -0
- package/layout/partial/header.ejs +6 -0
- package/layout/partial/hometop.ejs +15 -0
- package/layout/partial/loading.ejs +86 -0
- package/layout/partial/nav.ejs +34 -0
- package/layout/partial/pwa.ejs +40 -0
- package/layout/partial/sidebar.ejs +31 -0
- package/layout/post.ejs +36 -0
- package/layout/tag.ejs +19 -0
- package/package.json +24 -0
- package/scripts/event/init.js +22 -0
- package/scripts/event/page.js +40 -0
- package/scripts/event/welcome.js +15 -0
- package/scripts/filter/checkThemeConfig.js +18 -0
- package/scripts/filter/default.js +23 -0
- package/scripts/filter/katex.js +25 -0
- package/scripts/filter/lazyload.js +11 -0
- package/scripts/filter/randomPosts.js +9 -0
- package/scripts/helper/charts.js +397 -0
- package/scripts/helper/getArchiveLength.js +18 -0
- package/scripts/helper/randomLinks.js +16 -0
- package/scripts/helper/related_post.js +91 -0
- package/scripts/helper/themeJsExport.js +77 -0
- package/scripts/tags/bvideo.js +42 -0
- package/scripts/tags/expand.js +4 -0
- package/scripts/tags/fold.js +19 -0
- package/scripts/tags/link.js +17 -0
- package/scripts/tags/note.js +3 -0
- package/scripts/tags/tabs.js +61 -0
- package/scripts/tags/timeline.js +35 -0
- package/source/css/commentBarrage.css +174 -0
- package/source/css/custom.css +901 -0
- package/source/css/main.css +16471 -0
- package/source/css/search/algolia-search.css +141 -0
- package/source/css/search/local-search.css +138 -0
- package/source/css/var.css +186 -0
- package/source/img/default.png +0 -0
- package/source/img/loading.gif +0 -0
- package/source/img/power.png +0 -0
- package/source/img/pwa/180.png +0 -0
- package/source/img/pwa/192.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/theme/avatar.png +0 -0
- package/source/js/circle.js +1828 -0
- package/source/js/commentBarrage.js +148 -0
- package/source/js/extend/console/comment.js +99 -0
- package/source/js/extend/covercolor/local.js +150 -0
- package/source/js/extend/covercolor/web.js +137 -0
- package/source/js/extend/search/algolia-search.js +136 -0
- package/source/js/extend/search/local-search.js +160 -0
- package/source/js/main.js +705 -0
- package/source/js/post_ai.js +517 -0
- package/source/js/utils.js +153 -0
- package/source/lib/bundle.js +27 -0
- package/source/lib/friends_post.js +98 -0
- package/source/lib/lazyload.js +1 -0
- package/source/lib/snackbar.js +16 -0
- package/source/lib/snackbar.min.css +1 -0
- package/source/lib/view-image.js +13 -0
- package/source/lib/waterfall.min.js +1 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
var commentBarrageConfig = {
|
2
|
+
maxBarrage: 1,
|
3
|
+
barrageTime: 8e3,
|
4
|
+
twikooUrl: "https://twikoo.sondy.top",
|
5
|
+
pageUrl: window.location.pathname,
|
6
|
+
barrageTimer: [],
|
7
|
+
barrageList: [],
|
8
|
+
barrageIndex: 0,
|
9
|
+
dom: document.querySelector(".comment-barrage")
|
10
|
+
}
|
11
|
+
, commentInterval = null
|
12
|
+
, hoverOnCommentBarrage = !1
|
13
|
+
, isFirstTime = !0;
|
14
|
+
document.querySelector(".comment-barrage").addEventListener("mouseenter", (function () {
|
15
|
+
hoverOnCommentBarrage = !0
|
16
|
+
}
|
17
|
+
)),
|
18
|
+
document.querySelector(".comment-barrage").addEventListener("mouseleave", (function () {
|
19
|
+
hoverOnCommentBarrage = !1
|
20
|
+
}
|
21
|
+
));
|
22
|
+
var fetchComments = async function () {
|
23
|
+
try {
|
24
|
+
var e = await fetch(commentBarrageConfig.twikooUrl, {
|
25
|
+
method: "POST",
|
26
|
+
headers: {
|
27
|
+
"Content-Type": "application/json"
|
28
|
+
},
|
29
|
+
body: JSON.stringify({
|
30
|
+
event: "COMMENT_GET",
|
31
|
+
accessToken: commentBarrageConfig.accessToken,
|
32
|
+
url: commentBarrageConfig.pageUrl
|
33
|
+
})
|
34
|
+
});
|
35
|
+
if (!e.ok)
|
36
|
+
throw new Error("HTTP error! status: " + e.status);
|
37
|
+
return (await e.json()).data
|
38
|
+
} catch (e) {
|
39
|
+
console.error("An error occurred while fetching comments: ", e)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
, initCommentBarrage = function () {
|
43
|
+
"false" !== localStorage.getItem("commentBarrageSwitch") ? (commentBarrageConfig.dom.style.display = "none",
|
44
|
+
document.querySelector(".menu-commentBarrage-text").textContent = "显示热评",
|
45
|
+
document.querySelector("#consoleCommentBarrage").classList.remove("on")) : (commentBarrageConfig.dom.style.display = "flex",
|
46
|
+
document.querySelector(".menu-commentBarrage-text").textContent = "关闭热评",
|
47
|
+
document.querySelector("#consoleCommentBarrage").classList.add("on")),
|
48
|
+
fetchComments().then((function (e) {
|
49
|
+
commentBarrageConfig.barrageList = commentLinkFilter(e),
|
50
|
+
commentBarrageConfig.dom.innerHTML = "",
|
51
|
+
clearInterval(commentInterval),
|
52
|
+
commentInterval = null;
|
53
|
+
var r = function () {
|
54
|
+
if (commentBarrageConfig.barrageList.length && !hoverOnCommentBarrage) {
|
55
|
+
if (!popCommentBarrage(commentBarrageConfig.barrageList[commentBarrageConfig.barrageIndex]))
|
56
|
+
return commentBarrageConfig.barrageIndex += 1,
|
57
|
+
commentBarrageConfig.barrageIndex %= commentBarrageConfig.barrageList.length,
|
58
|
+
r();
|
59
|
+
commentBarrageConfig.barrageIndex += 1,
|
60
|
+
commentBarrageConfig.barrageIndex %= commentBarrageConfig.barrageList.length
|
61
|
+
}
|
62
|
+
commentBarrageConfig.barrageTimer.length > (commentBarrageConfig.barrageList.length > commentBarrageConfig.maxBarrage ? commentBarrageConfig.maxBarrage : commentBarrageConfig.barrageList.length) && !hoverOnCommentBarrage && removeCommentBarrage(commentBarrageConfig.barrageTimer.shift())
|
63
|
+
};
|
64
|
+
setTimeout((function () {
|
65
|
+
r(),
|
66
|
+
commentInterval = setInterval(r, commentBarrageConfig.barrageTime)
|
67
|
+
}
|
68
|
+
), 3e3)
|
69
|
+
}
|
70
|
+
))
|
71
|
+
};
|
72
|
+
|
73
|
+
function commentLinkFilter(e) {
|
74
|
+
e.sort((function (e, r) {
|
75
|
+
return e.created - r.created
|
76
|
+
}
|
77
|
+
));
|
78
|
+
var r = [];
|
79
|
+
return e.forEach((function (e) {
|
80
|
+
r.push(...getCommentReplies(e))
|
81
|
+
}
|
82
|
+
)),
|
83
|
+
r
|
84
|
+
}
|
85
|
+
|
86
|
+
function getCommentReplies(e) {
|
87
|
+
if (e.replies) {
|
88
|
+
var r = [e];
|
89
|
+
return e.replies.forEach((function (e) {
|
90
|
+
r.push(...getCommentReplies(e))
|
91
|
+
}
|
92
|
+
)),
|
93
|
+
r
|
94
|
+
}
|
95
|
+
return []
|
96
|
+
}
|
97
|
+
|
98
|
+
function processCommentContent(e) {
|
99
|
+
var r = document.createElement("div");
|
100
|
+
r.innerHTML = e;
|
101
|
+
for (var a = r.getElementsByTagName("img"), n = a.length - 1; n >= 0; n--) {
|
102
|
+
var t = a[n];
|
103
|
+
t.parentNode.removeChild(t)
|
104
|
+
}
|
105
|
+
var o = r.getElementsByTagName("blockquote");
|
106
|
+
for (n = o.length - 1; n >= 0; n--) {
|
107
|
+
var m = o[n];
|
108
|
+
m.parentNode.removeChild(m)
|
109
|
+
}
|
110
|
+
var c = r.getElementsByTagName("a");
|
111
|
+
for (n = c.length - 1; n >= 0; n--) {
|
112
|
+
var i = c[n]
|
113
|
+
, g = document.createTextNode(i.textContent);
|
114
|
+
i.parentNode.replaceChild(g, i)
|
115
|
+
}
|
116
|
+
var s = r.getElementsByTagName("p");
|
117
|
+
for (n = s.length - 1; n >= 0; n--) {
|
118
|
+
var l = s[n];
|
119
|
+
"" === l.textContent.trim() && l.parentNode.removeChild(l)
|
120
|
+
}
|
121
|
+
return r.innerHTML
|
122
|
+
}
|
123
|
+
|
124
|
+
function popCommentBarrage(e) {
|
125
|
+
var r = processCommentContent(e.comment);
|
126
|
+
if (!r.trim())
|
127
|
+
return !1;
|
128
|
+
var a = document.createElement("div");
|
129
|
+
return a.className = "comment-barrage-item",
|
130
|
+
a.innerHTML = `\n <div class="barrageHead">\n <a class="barrageTitle" href="javascript:sco.scrollTo('post-comment')">热评</a>\n <div class="barrageNick">${e.nick}</div>\n <img class="barrageAvatar" src="https://cravatar.cn/avatar/${e.mailMd5}"/>\n <a class="comment-barrage-close" href="javascript:sco.switchCommentBarrage();"><i class="scofont icon-close-fill"></i></a>\n </div>\n <a class="barrageContent" href="javascript:sco.scrollTo('${e.id}');">${r}</a>\n `,
|
131
|
+
commentBarrageConfig.barrageTimer.push(a),
|
132
|
+
commentBarrageConfig.dom.appendChild(a),
|
133
|
+
!0
|
134
|
+
}
|
135
|
+
|
136
|
+
function removeCommentBarrage(e) {
|
137
|
+
e.className = "comment-barrage-item out",
|
138
|
+
setTimeout((function () {
|
139
|
+
commentBarrageConfig.dom.removeChild(e)
|
140
|
+
}
|
141
|
+
), 1e3)
|
142
|
+
}
|
143
|
+
|
144
|
+
initCommentBarrage(),
|
145
|
+
document.addEventListener("pjax:send", (function () {
|
146
|
+
clearInterval(commentInterval)
|
147
|
+
}
|
148
|
+
));
|
@@ -0,0 +1,99 @@
|
|
1
|
+
const changeContent = (content) => {
|
2
|
+
if (content === '') return content
|
3
|
+
|
4
|
+
content = content.replace(/<img.*?src="(.*?)"?[^\>]+>|<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>|<pre><code>.*?<\/pre>|<[^>]+>/g, (match, img, link, code) => {
|
5
|
+
if (img) return '[图片]';
|
6
|
+
if (link) return '[链接]';
|
7
|
+
if (code) return '[代码]';
|
8
|
+
return '';
|
9
|
+
})
|
10
|
+
|
11
|
+
if (content.length > 150) {
|
12
|
+
content = content.substring(0,150) + '...'
|
13
|
+
}
|
14
|
+
return content
|
15
|
+
}
|
16
|
+
|
17
|
+
const getComment = () => {
|
18
|
+
const $dom = document.querySelector('#card-newest-comments .aside-list')
|
19
|
+
|
20
|
+
const runTwikoo = () => {
|
21
|
+
twikoo.getRecentComments({
|
22
|
+
envId: GLOBALCONFIG.comment.twikooUrl,
|
23
|
+
region: '',
|
24
|
+
pageSize: 6,
|
25
|
+
includeReply: true
|
26
|
+
}).then(function (res) {
|
27
|
+
const twikooArray = res.map(e => ({
|
28
|
+
'content': changeContent(e.comment),
|
29
|
+
'avatar': e.avatar,
|
30
|
+
'nick': e.nick,
|
31
|
+
'url': `${e.url}#${e.id}`,
|
32
|
+
'date': new Date(e.created).toISOString()
|
33
|
+
}))
|
34
|
+
|
35
|
+
if(window.location.pathname === "/links/" || window.location.pathname === "/links"){
|
36
|
+
let submit = document.getElementsByClassName('tk-submit ')
|
37
|
+
let text = document.getElementsByClassName("el-textarea__inner");
|
38
|
+
text[0].value += `昵称(请勿包含博客等字样):
|
39
|
+
网站地址(要求博客地址,请勿提交个人主页):
|
40
|
+
头像图片url(请提供尽可能清晰的图片,我会上传到我的图床):
|
41
|
+
描述:`;
|
42
|
+
text[0].style.height = "142px"
|
43
|
+
submit.item(0).style.display = "none";
|
44
|
+
|
45
|
+
window.checkForm = function(){
|
46
|
+
const checkboxes = document.querySelectorAll('input[onclick="checkForm()"]');
|
47
|
+
let allChecked = true;
|
48
|
+
|
49
|
+
checkboxes.forEach(checkbox => {
|
50
|
+
if (!checkbox.checked) {
|
51
|
+
allChecked = false;
|
52
|
+
}
|
53
|
+
});
|
54
|
+
|
55
|
+
if(allChecked){
|
56
|
+
submit.item(0).style.display = "block";
|
57
|
+
}else {
|
58
|
+
submit.item(0).style.display = "none";
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
generateHtml(twikooArray)
|
64
|
+
}).catch(function (err) {
|
65
|
+
$dom.innerHTML= "无法获取评论,请确认相关配置是否正确"
|
66
|
+
})
|
67
|
+
}
|
68
|
+
runTwikoo()
|
69
|
+
}
|
70
|
+
|
71
|
+
const generateHtml = array => {
|
72
|
+
const $dom = document.querySelector('#card-newest-comments .aside-list')
|
73
|
+
|
74
|
+
let result = array.length ? array.map(item => `
|
75
|
+
<div class='aside-list-item'>
|
76
|
+
<a href='${item.url}' class='thumbnail'>
|
77
|
+
<img src='${item.avatar}' alt='${item.nick}'>
|
78
|
+
<div class='name'><span>${item.nick}</span></div>
|
79
|
+
</a>
|
80
|
+
<div class='content'>
|
81
|
+
<a class='comment' href='${item.url}'>${item.content}</a>
|
82
|
+
<time class="datetime" datetime="${item.date}"></time>
|
83
|
+
</div>
|
84
|
+
</div>
|
85
|
+
`).join('') : '没有评论'
|
86
|
+
|
87
|
+
$dom.innerHTML = result
|
88
|
+
window.lazyLoadInstance && window.lazyLoadInstance.update()
|
89
|
+
window.pjax && window.pjax.refresh($dom)
|
90
|
+
chageTimeFormate()
|
91
|
+
}
|
92
|
+
|
93
|
+
const newestCommentInit = () => {
|
94
|
+
const $asideList = document.querySelector('#card-newest-comments .aside-list')
|
95
|
+
if ($asideList) {
|
96
|
+
getComment()
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
@@ -0,0 +1,150 @@
|
|
1
|
+
function coverColor() {
|
2
|
+
var path = document.getElementById("post-cover")?.src;
|
3
|
+
if (path !== undefined) {
|
4
|
+
var img = new Image();
|
5
|
+
img.crossOrigin = "Anonymous";
|
6
|
+
img.src = path;
|
7
|
+
img.onload = function () {
|
8
|
+
var canvas = document.createElement("canvas");
|
9
|
+
canvas.width = this.width;
|
10
|
+
canvas.height = this.height;
|
11
|
+
var ctx = canvas.getContext("2d");
|
12
|
+
ctx.drawImage(this, 0, 0);
|
13
|
+
var data = ctx.getImageData(0, 0, this.width, this.height).data;
|
14
|
+
var r = 0, g = 0, b = 0;
|
15
|
+
var step = 5;
|
16
|
+
for (var i = 0; i < data.length; i += 4 * step) {
|
17
|
+
r += data[i];
|
18
|
+
g += data[i + 1];
|
19
|
+
b += data[i + 2];
|
20
|
+
}
|
21
|
+
r = Math.floor(r / (data.length / 4 / step));
|
22
|
+
g = Math.floor(g / (data.length / 4 / step));
|
23
|
+
b = Math.floor(b / (data.length / 4 / step));
|
24
|
+
var value = "#" + r.toString(16) + g.toString(16) + b.toString(16);
|
25
|
+
if (getContrastYIQ(value) == "light") {
|
26
|
+
value = LightenDarkenColor(colorHex(value), -50)
|
27
|
+
}
|
28
|
+
|
29
|
+
document.documentElement.style.setProperty('--sco-main', value);
|
30
|
+
document.documentElement.style.setProperty('--sco-main-op', value + '23');
|
31
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', value + 'dd');
|
32
|
+
document.documentElement.style.setProperty('--sco-main-none', value + '00');
|
33
|
+
initThemeColor()
|
34
|
+
document.getElementById("coverdiv").classList.add("loaded");
|
35
|
+
}
|
36
|
+
} else {
|
37
|
+
document.documentElement.style.setProperty('--sco-main', 'var(--sco-theme)');
|
38
|
+
document.documentElement.style.setProperty('--sco-main-op', 'var(--sco-theme-op)');
|
39
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', 'var(--sco-theme-op-deep)');
|
40
|
+
document.documentElement.style.setProperty('--sco-main-none', 'var(--sco-theme-none)');
|
41
|
+
initThemeColor()
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
function colorHex(colorString) {
|
47
|
+
const hexRegex = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
48
|
+
let color = colorString;
|
49
|
+
|
50
|
+
if (/^(rgb|RGB)/.test(color)) {
|
51
|
+
const colorArr = color.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
|
52
|
+
const hexArr = colorArr.map(c => {
|
53
|
+
const hex = Number(c).toString(16);
|
54
|
+
return hex.length === 1 ? "0" + hex : hex;
|
55
|
+
});
|
56
|
+
return "#" + hexArr.join("");
|
57
|
+
} else if (hexRegex.test(color)) {
|
58
|
+
const hexDigits = color.replace(/#/, "").split("");
|
59
|
+
if (hexDigits.length === 6) {
|
60
|
+
return color;
|
61
|
+
} else if (hexDigits.length === 3) {
|
62
|
+
const hexArr = hexDigits.map(c => c + c);
|
63
|
+
return "#" + hexArr.join("");
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return color;
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
function colorRgb(str) {
|
72
|
+
const HEX_SHORT_REGEX = /^#([0-9a-fA-f]{3})$/;
|
73
|
+
const HEX_LONG_REGEX = /^#([0-9a-fA-f]{6})$/;
|
74
|
+
const HEX_SHORT_LENGTH = 4;
|
75
|
+
|
76
|
+
if (!str || typeof str !== 'string') {
|
77
|
+
return str;
|
78
|
+
}
|
79
|
+
|
80
|
+
const sColor = str.toLowerCase();
|
81
|
+
let hexValue = "";
|
82
|
+
|
83
|
+
if (sColor && (HEX_SHORT_REGEX.test(sColor) || HEX_LONG_REGEX.test(sColor))) {
|
84
|
+
hexValue = sColor.length === HEX_SHORT_LENGTH ?
|
85
|
+
sColor.replace(/^#(.)/g, "#$1$1") :
|
86
|
+
sColor;
|
87
|
+
|
88
|
+
const rgbValue = hexValue.slice(1)
|
89
|
+
.match(/.{2}/g)
|
90
|
+
.map(val => parseInt(val, 16));
|
91
|
+
|
92
|
+
return `rgb(${rgbValue[0]}, ${rgbValue[1]}, ${rgbValue[2]})`;
|
93
|
+
} else {
|
94
|
+
return sColor;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
function LightenDarkenColor(col, amt) {
|
100
|
+
let usePound = false;
|
101
|
+
|
102
|
+
if (col[0] === "#") {
|
103
|
+
col = col.slice(1);
|
104
|
+
usePound = true;
|
105
|
+
}
|
106
|
+
|
107
|
+
const num = parseInt(col, 16);
|
108
|
+
const r = Math.min(255, Math.max(0, (num >> 16) + amt));
|
109
|
+
const b = Math.min(255, Math.max(0, ((num >> 8) & 0xff) + amt));
|
110
|
+
const g = Math.min(255, Math.max(0, (num & 0xff) + amt));
|
111
|
+
|
112
|
+
return `${usePound ? "#" : ""}${(g | (b << 8) | (r << 16)).toString(16).padStart(6, "0")}`;
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
function getContrastYIQ(hexcolor) {
|
117
|
+
var colorrgb = colorRgb(hexcolor);
|
118
|
+
var colors = colorrgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
119
|
+
var red = colors[1];
|
120
|
+
var green = colors[2];
|
121
|
+
var blue = colors[3];
|
122
|
+
var brightness;
|
123
|
+
brightness = (red * 299) + (green * 587) + (blue * 114);
|
124
|
+
brightness = brightness / 255000;
|
125
|
+
if (brightness >= 0.5) {
|
126
|
+
return "light";
|
127
|
+
} else {
|
128
|
+
return "dark";
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
function initThemeColor() {
|
133
|
+
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
134
|
+
let themeColor;
|
135
|
+
if (currentTop > 0) {
|
136
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-card-bg');
|
137
|
+
} else if (PAGECONFIG.is_post) {
|
138
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-main');
|
139
|
+
} else {
|
140
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-background');
|
141
|
+
}
|
142
|
+
changeThemeColor(themeColor);
|
143
|
+
}
|
144
|
+
|
145
|
+
function changeThemeColor(color) {
|
146
|
+
const meta = document.querySelector('meta[name="theme-color"]');
|
147
|
+
if (meta) {
|
148
|
+
meta.setAttribute('content', color);
|
149
|
+
}
|
150
|
+
}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
function coverColor() {
|
2
|
+
var path = document.getElementById("post-cover")?.src;
|
3
|
+
if (path !== undefined) {
|
4
|
+
var httpRequest = new XMLHttpRequest();
|
5
|
+
httpRequest.open('GET', path + '?imageAve', true);
|
6
|
+
httpRequest.send();
|
7
|
+
httpRequest.onreadystatechange = function () {
|
8
|
+
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
|
9
|
+
var json = httpRequest.responseText;
|
10
|
+
var obj = eval('(' + json + ')');
|
11
|
+
var value = obj.RGB;
|
12
|
+
value = "#" + value.slice(2)
|
13
|
+
if (getContrastYIQ(value) == "light") {
|
14
|
+
value = LightenDarkenColor(colorHex(value), -50)
|
15
|
+
}
|
16
|
+
|
17
|
+
document.documentElement.style.setProperty('--sco-main', value);
|
18
|
+
document.documentElement.style.setProperty('--sco-main-op', value + '23');
|
19
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', value + 'dd');
|
20
|
+
document.documentElement.style.setProperty('--sco-main-none', value + '00');
|
21
|
+
initThemeColor()
|
22
|
+
document.getElementById("coverdiv").classList.add("loaded");
|
23
|
+
}
|
24
|
+
};
|
25
|
+
} else {
|
26
|
+
document.documentElement.style.setProperty('--sco-main', 'var(--sco-theme)');
|
27
|
+
document.documentElement.style.setProperty('--sco-main-op', 'var(--sco-theme-op)');
|
28
|
+
document.documentElement.style.setProperty('--sco-main-op-deep', 'var(--sco-theme-op-deep)');
|
29
|
+
document.documentElement.style.setProperty('--sco-main-none', 'var(--sco-theme-none)');
|
30
|
+
initThemeColor()
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
function colorHex(colorString) {
|
37
|
+
const hexRegex = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
38
|
+
let color = colorString;
|
39
|
+
|
40
|
+
if (/^(rgb|RGB)/.test(color)) {
|
41
|
+
const colorArr = color.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
|
42
|
+
const hexArr = colorArr.map(c => {
|
43
|
+
const hex = Number(c).toString(16);
|
44
|
+
return hex.length === 1 ? "0" + hex : hex;
|
45
|
+
});
|
46
|
+
return "#" + hexArr.join("");
|
47
|
+
} else if (hexRegex.test(color)) {
|
48
|
+
const hexDigits = color.replace(/#/, "").split("");
|
49
|
+
if (hexDigits.length === 6) {
|
50
|
+
return color;
|
51
|
+
} else if (hexDigits.length === 3) {
|
52
|
+
const hexArr = hexDigits.map(c => c + c);
|
53
|
+
return "#" + hexArr.join("");
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return color;
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
function colorRgb(str) {
|
62
|
+
const HEX_SHORT_REGEX = /^#([0-9a-fA-f]{3})$/;
|
63
|
+
const HEX_LONG_REGEX = /^#([0-9a-fA-f]{6})$/;
|
64
|
+
const HEX_SHORT_LENGTH = 4;
|
65
|
+
|
66
|
+
const sColor = str.toLowerCase();
|
67
|
+
let hexValue = "";
|
68
|
+
|
69
|
+
if (sColor && (HEX_SHORT_REGEX.test(sColor) || HEX_LONG_REGEX.test(sColor))) {
|
70
|
+
hexValue = sColor.length === HEX_SHORT_LENGTH ?
|
71
|
+
sColor.replace(/^#(.)/g, "#$1$1") :
|
72
|
+
sColor;
|
73
|
+
|
74
|
+
const rgbValue = hexValue.slice(1)
|
75
|
+
.match(/.{2}/g)
|
76
|
+
.map(val => parseInt(val, 16))
|
77
|
+
.join(",");
|
78
|
+
|
79
|
+
return `rgb(${rgbValue})`;
|
80
|
+
} else {
|
81
|
+
return sColor;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
function LightenDarkenColor(col, amt) {
|
87
|
+
let usePound = false;
|
88
|
+
|
89
|
+
if (col[0] === "#") {
|
90
|
+
col = col.slice(1);
|
91
|
+
usePound = true;
|
92
|
+
}
|
93
|
+
|
94
|
+
const num = parseInt(col, 16);
|
95
|
+
const r = Math.min(255, Math.max(0, (num >> 16) + amt));
|
96
|
+
const b = Math.min(255, Math.max(0, ((num >> 8) & 0xff) + amt));
|
97
|
+
const g = Math.min(255, Math.max(0, (num & 0xff) + amt));
|
98
|
+
|
99
|
+
return `${usePound ? "#" : ""}${(g | (b << 8) | (r << 16)).toString(16).padStart(6, "0")}`;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
function getContrastYIQ(hexcolor) {
|
104
|
+
var colorrgb = colorRgb(hexcolor);
|
105
|
+
var colors = colorrgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
106
|
+
var red = colors[1];
|
107
|
+
var green = colors[2];
|
108
|
+
var blue = colors[3];
|
109
|
+
var brightness;
|
110
|
+
brightness = (red * 299) + (green * 587) + (blue * 114);
|
111
|
+
brightness = brightness / 255000;
|
112
|
+
if (brightness >= 0.5) {
|
113
|
+
return "light";
|
114
|
+
} else {
|
115
|
+
return "dark";
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
function initThemeColor() {
|
120
|
+
const currentTop = window.scrollY || document.documentElement.scrollTop;
|
121
|
+
let themeColor;
|
122
|
+
if (currentTop > 0) {
|
123
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-card-bg');
|
124
|
+
} else if (PAGECONFIG.is_post) {
|
125
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-main');
|
126
|
+
} else {
|
127
|
+
themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-background');
|
128
|
+
}
|
129
|
+
changeThemeColor(themeColor);
|
130
|
+
}
|
131
|
+
|
132
|
+
function changeThemeColor(color) {
|
133
|
+
const meta = document.querySelector('meta[name="theme-color"]');
|
134
|
+
if (meta) {
|
135
|
+
meta.setAttribute('content', color);
|
136
|
+
}
|
137
|
+
}
|
@@ -0,0 +1,136 @@
|
|
1
|
+
const $searchMask = document.getElementById('search-mask'),
|
2
|
+
$searchDialog = document.querySelector('#algolia-search .search-dialog')
|
3
|
+
|
4
|
+
class search {
|
5
|
+
static openSearch() {
|
6
|
+
utils.fadeIn($searchMask, '0.5')
|
7
|
+
utils.fadeIn($searchDialog, '0.5')
|
8
|
+
document.addEventListener('keydown', function f(event) {
|
9
|
+
if (event.code === 'Escape') {
|
10
|
+
closeSearch()
|
11
|
+
document.removeEventListener('keydown', f)
|
12
|
+
}
|
13
|
+
})
|
14
|
+
}
|
15
|
+
|
16
|
+
static closeSearch() {
|
17
|
+
utils.fadeOut($searchDialog, '0.5')
|
18
|
+
utils.fadeOut($searchMask, '0.5')
|
19
|
+
}
|
20
|
+
|
21
|
+
static cutContent(content) {
|
22
|
+
if (content === '') return ''
|
23
|
+
|
24
|
+
const firstOccur = content.indexOf('<mark>')
|
25
|
+
|
26
|
+
let start = firstOccur - 30
|
27
|
+
let end = firstOccur + 120
|
28
|
+
let pre = ''
|
29
|
+
let post = ''
|
30
|
+
|
31
|
+
if (start <= 0) {
|
32
|
+
start = 0
|
33
|
+
end = 140
|
34
|
+
} else {
|
35
|
+
pre = '...'
|
36
|
+
}
|
37
|
+
|
38
|
+
if (end > content.length) {
|
39
|
+
end = content.length
|
40
|
+
} else {
|
41
|
+
post = '...'
|
42
|
+
}
|
43
|
+
|
44
|
+
const matchContent = pre + content.substring(start, end) + post
|
45
|
+
return matchContent
|
46
|
+
}
|
47
|
+
|
48
|
+
static search() {
|
49
|
+
const algolia = GLOBALCONFIG.algolia, that = this
|
50
|
+
const isAlgoliaValid = algolia.appId && algolia.apiKey && algolia.indexName
|
51
|
+
if (!isAlgoliaValid) {
|
52
|
+
return console.error('Algolia setting is invalid!')
|
53
|
+
}
|
54
|
+
|
55
|
+
const init = instantsearch({
|
56
|
+
indexName: algolia.indexName,
|
57
|
+
searchClient: algoliasearch(algolia.appId, algolia.apiKey),
|
58
|
+
searchFunction(helper) {
|
59
|
+
helper.state.query && helper.search()
|
60
|
+
}
|
61
|
+
})
|
62
|
+
|
63
|
+
const searchBox = instantsearch.widgets.searchBox({
|
64
|
+
container: '#search-input',
|
65
|
+
showReset: false,
|
66
|
+
showSubmit: false,
|
67
|
+
autofocus: true,
|
68
|
+
placeholder: GLOBALCONFIG.lang.search.placeholder,
|
69
|
+
showLoadingIndicator: false
|
70
|
+
})
|
71
|
+
|
72
|
+
const hits = instantsearch.widgets.hits({
|
73
|
+
container: '#algolia-hits',
|
74
|
+
templates: {
|
75
|
+
item(data) {
|
76
|
+
const link = '/posts/' + data.permalink.split('/')[4]
|
77
|
+
const result = data._highlightResult
|
78
|
+
const content = result.contentStripTruncate
|
79
|
+
? that.cutContent(result.contentStripTruncate.value)
|
80
|
+
: result.contentStrip
|
81
|
+
? that.cutContent(result.contentStrip.value)
|
82
|
+
: result.content
|
83
|
+
? that.cutContent(result.content.value)
|
84
|
+
: ''
|
85
|
+
return `
|
86
|
+
<a href="${link}" class="algolia-hit-item-link">
|
87
|
+
${result.title.value}
|
88
|
+
</a>
|
89
|
+
<p class="algolia-hit-item-content">${content}</p>`
|
90
|
+
},
|
91
|
+
empty: function (data) {
|
92
|
+
return (
|
93
|
+
`<div id="algolia-hits-empty">${GLOBALCONFIG.lang.search.empty}</div>`
|
94
|
+
)
|
95
|
+
}
|
96
|
+
}
|
97
|
+
})
|
98
|
+
|
99
|
+
const stats = instantsearch.widgets.stats({
|
100
|
+
container: '.algolia-stats',
|
101
|
+
templates: {
|
102
|
+
text: function (data) {
|
103
|
+
const stats = GLOBALCONFIG.lang.search.hit.replace('${query}', `<mark>${data.nbHits}</mark>`)
|
104
|
+
return (
|
105
|
+
stats
|
106
|
+
)
|
107
|
+
}
|
108
|
+
}
|
109
|
+
})
|
110
|
+
|
111
|
+
init.addWidgets([searchBox, hits, stats]) // add the widgets to the instantsearch instance
|
112
|
+
init.start()
|
113
|
+
init.on('render', () => {
|
114
|
+
pjax.refresh(document.getElementById('algolia-hits'))
|
115
|
+
})
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
const searchClickFn = () => {
|
120
|
+
document.querySelector('#search-button > .search').addEventListener('click', search.openSearch)
|
121
|
+
}
|
122
|
+
|
123
|
+
const searchClickFnOnce = () => {
|
124
|
+
document.querySelector('#algolia-search .search-close-button').addEventListener('click', search.closeSearch)
|
125
|
+
$searchMask.addEventListener('click', search.closeSearch)
|
126
|
+
}
|
127
|
+
|
128
|
+
window.addEventListener('load', () => {
|
129
|
+
searchClickFn()
|
130
|
+
searchClickFnOnce()
|
131
|
+
search.search()
|
132
|
+
})
|
133
|
+
|
134
|
+
window.addEventListener('pjax:complete', () => {
|
135
|
+
searchClickFn()
|
136
|
+
})
|