This commit is contained in:
xaoxuu 2021-02-21 18:48:38 +08:00
parent ba4008e57d
commit c971cd4988
5 changed files with 30 additions and 20 deletions

View File

@ -33,8 +33,8 @@ meta:
footer: footer:
license: '本博客所有文章除特别声明外,均采用 %s 许可协议。转载请注明出处!' license: '本博客所有文章除特别声明外,均采用 %s 许可协议。转载请注明出处!'
info_not_open_source: '本站由 %s 创建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作为主题。' info_not_open_source: '本站由 %s 创建,使用 %s 作为主题。'
info_open_source: '本站由 %s 创建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作为主题,您可以在 [%s](%s) 找到本站源码。' info_open_source: '本站由 %s 创建,使用 %s 作为主题,您可以在 %s 找到本站源码。'
page: page:
error: error:

View File

@ -33,8 +33,8 @@ meta:
footer: footer:
license: '本網誌所有文章除特別聲明外,均採用 %s 許可協議。轉載請註明出處!' license: '本網誌所有文章除特別聲明外,均採用 %s 許可協議。轉載請註明出處!'
info_not_open_source: '本站由 %s 創建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作為主題。' info_not_open_source: '本站由 %s 創建,使用 %s 作為主題。'
info_open_source: '本站由 %s 創建,使用 [Stellar](https://github.com/xaoxuu/hexo-theme-stellar) 作為主題,您可以在 [%s](%s) 找到本站源碼。' info_open_source: '本站由 %s 創建,使用 %s 作為主題,您可以在 %s 找到本站源碼。'
page: page:
error: error:

View File

@ -1,5 +1,5 @@
<% <%
const author = '[' + config.author + '](' + config.url + config.root + ')'; const author = '[@' + config.author + '](' + config.url + config.root + ')';
const using = '[' + stellar_info('name') + '](' + stellar_info('tree') + ')'; const using = '[' + stellar_info('name') + '](' + stellar_info('tree') + ')';
const source = theme.footer.source; const source = theme.footer.source;
function layoutDiv() { function layoutDiv() {

View File

@ -8,9 +8,23 @@ if (page.utterances == undefined) {
} }
} }
} }
if (page.comment_id) {
page.utterances['issue-term'] = page.comment_id;
}
if (theme.comments.utterances.theme) {
if (page.dark) {
page.utterances.theme = theme.comments.utterances.theme.dark;
} else {
page.utterances.theme = theme.comments.utterances.theme.light;
}
}
%> %>
<script> <script>
function pjax_utterances(){ stellar.comments = {
service: 'utterances',
utterances: Object.assign(<%- JSON.stringify(page.utterances) %>),
}
function utterances(){
if(!document.getElementById("utterances"))return; if(!document.getElementById("utterances"))return;
setTimeout(function() { setTimeout(function() {
var checkUtterances = setInterval(function () { var checkUtterances = setInterval(function () {
@ -21,20 +35,16 @@ if (page.utterances == undefined) {
HEAD.innerHTML=""; HEAD.innerHTML="";
} catch (error) {} } catch (error) {}
var script = document.createElement('script'); var script = document.createElement('script');
script.setAttribute('src','https://utteranc.es/client.js'); const keys = ['repo', 'issue-term', 'theme', 'label', 'crossorigin'];
script.setAttribute('repo','<%- page.utterances.repo %>'); script.src = 'https://utteranc.es/client.js';
let issuenumber = '<%- page.utterances['issue-number'] || page.comment_id %>'; for (let key of Object.keys(stellar.comments.utterances)) {
if (issuenumber) { if (keys.includes(key) && stellar.comments.utterances[key]) {
script.setAttribute('issue-term', issuenumber); script.setAttribute(key, stellar.comments.utterances[key]);
} else { }
script.setAttribute('issue-term', '<%- page.utterances['issue-term'] %>');
} }
script.setAttribute('theme', '<%- page.dark ? page.utterances.theme.dark : page.utterances.theme.light %>' );
script.setAttribute('label','<%- page.utterances.label %>');
script.setAttribute('crossorigin','<%- page.utterances.crossorigin %>');
HEAD.appendChild(script); HEAD.appendChild(script);
}, 200) }, 200)
}); });
} }
pjax_utterances(); utterances();
</script> </script>

View File

@ -98,7 +98,7 @@ const util = {
// 从 butterfly 和 volantis 获得灵感 // 从 butterfly 和 volantis 获得灵感
loadScript: (src, opt) => new Promise((resolve, reject) => { loadScript: (src, opt) => new Promise((resolve, reject) => {
const script = document.createElement('script') var script = document.createElement('script')
script.src = src script.src = src
if (opt) { if (opt) {
for (let key of Object.keys(opt)) { for (let key of Object.keys(opt)) {
@ -284,8 +284,8 @@ if (stellar.plugins.swiper) {
if (stellar.plugins.preload) { if (stellar.plugins.preload) {
if (stellar.plugins.preload.service == 'instant_page') { if (stellar.plugins.preload.service == 'instant_page') {
util.loadScript(stellar.plugins.preload.instant_page, { util.loadScript(stellar.plugins.preload.instant_page, {
defer:true, defer: true,
type:'module', type: 'module',
integrity: 'sha384-OeDn4XE77tdHo8pGtE1apMPmAipjoxUQ++eeJa6EtJCfHlvijigWiJpD7VDPWXV1' integrity: 'sha384-OeDn4XE77tdHo8pGtE1apMPmAipjoxUQ++eeJa6EtJCfHlvijigWiJpD7VDPWXV1'
}) })
} else if (stellar.plugins.preload.service == 'flying_pages') { } else if (stellar.plugins.preload.service == 'flying_pages') {