Skip to content

Commit

Permalink
feat: introduce giscus comment system (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme authored Sep 27, 2023
1 parent 8a9f15c commit dd802a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.html linguist-language=java
*.html linguist-language=java
*.css linguist-language=java
*.js linguist-language=java
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<link rel="stylesheet" href="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/npm/docsify/lib/themes/vue.css" />
<link rel="stylesheet" href="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/npm/docsify-darklight-theme@latest/dist/style.min.css" />
<link rel="stylesheet" href="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/npm/[email protected]/dist/giscus.css">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png" />
<style>
Expand Down
36 changes: 34 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const giscusTheme = () =>
localStorage.getItem('DARK_LIGHT_THEME') === 'dark' ? 'noborder_dark' : 'light';

window.$docsify = {
name: 'advanced-java',
repo: 'doocs/advanced-java',
lastModifiedText: '最近更新时间:',
maxLevel: 3,
auto2top: true,
coverpage: true,
Expand All @@ -11,6 +13,7 @@ window.$docsify = {
'/.*/.*/summary': 'summary.md',
'/.*/summary.md': 'summary.md',
},
lastModifiedText: '最近更新时间:',
pagination: {
previousText: '上一篇',
nextText: '下一篇',
Expand Down Expand Up @@ -68,7 +71,7 @@ window.$docsify = {
}

const github = `[GitHub](${url})`;
const gitee = `[Gitee](${url.replace('github', 'gitee' )})`;
const gitee = `[Gitee](${url.replace('github', 'gitee')})`;

const editHtml = en
? `:memo: Edit on ${github} / ${gitee}\n`
Expand Down Expand Up @@ -108,6 +111,35 @@ window.$docsify = {
const footer = `<footer><span>Copyright © 2018-${currentYear} <a href="https://github.com/doocs" target="_blank">Doocs</a>. All Rights Reserved.</footer>`;
return html + footer;
});
hook.doneEach(() => {
const giscusScript = document.createElement('script');
giscusScript.type = 'text/javascript';
giscusScript.async = true;
giscusScript.setAttribute('src', 'https://giscus.app/client.js');
giscusScript.setAttribute('data-repo', 'doocs/advanced-java');
giscusScript.setAttribute('data-repo-id', 'MDEwOlJlcG9zaXRvcnkxNTE4MzQwNjI=');
giscusScript.setAttribute('data-mapping', 'number');
giscusScript.setAttribute('data-reactions-enabled', '1');
giscusScript.setAttribute('data-strict', '1');
giscusScript.setAttribute('data-emit-metadata', '0');
giscusScript.setAttribute('data-input-position', 'top');
giscusScript.setAttribute('crossorigin', 'anonymous');
giscusScript.setAttribute('data-term', '9');
giscusScript.setAttribute('data-lang', 'zh-CN');
giscusScript.setAttribute('data-theme', giscusTheme());

document
.getElementById('main')
.insertBefore(giscusScript, document.getElementById('main').lastChild);

document.getElementById('docsify-darklight-theme').addEventListener('click', () => {
const frame = document.querySelector('.giscus-frame');
frame.contentWindow.postMessage(
{ giscus: { setConfig: { theme: giscusTheme() } } },
'https://giscus.app',
);
});
})
},
],
};

0 comments on commit dd802a8

Please sign in to comment.