Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suport giscus comment system #277

Merged
merged 6 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ the DoIt theme may be more suitable for you.
* **Twikoo** comment system supported by [Twikoo](https://twikoo.js.org/)
* **Vssue** comment system supported by [Vssue](https://vssue.js.org/)
* **Remark42** comment system supported by[Remark42](https://remark42.com/)
* **giscus** comment system supported by [giscus](https://giscus.app/)

### Extended Features

Expand Down
3 changes: 2 additions & 1 deletion README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ DoIt 主题增加了许多新的功能与配置项,查看[变更日志](https:
* 支持 **[Utterances](https://utteranc.es/)** 评论系统
* 支持 **[Twikoo](https://twikoo.js.org/)** 评论系统
* 支持 **[Vssue](https://vssue.js.org/)** 评论系统
* 支持 **[Remark42](https://remark42.com/) 评论系统
* 支持 **[Remark42](https://remark42.com/)** 评论系统
* 支持 **[giscus](https://giscus.app/)** 评论系统

### 扩展功能

Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/theme.min.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,20 @@ enableEmoji = true
max_shown_comments = 15
show_email_subscription = true
simple_view = false
# giscus comment config (https://giscus.app/)
# giscus comment 评论系统设置 (https://giscus.app/)
[params.page.comment.giscus]
enable = false
# owner/repo
dataRepo = ""
dataRepoId = ""
dataCategory = ""
dataCategoryId = ""
dataMapping = "pathname"
dataReactionsEnabled = "1"
dataEmitMetadata = "0"
lightTheme = "light"
darkTheme = "dark"
# Third-party library config
# 第三方库配置
[params.page.library]
Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/about/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ math:
* :(fas fa-comment-alt fa-fw): **Twikoo** comment system supported by [Twikoo](https://twikoo.js.org/)
* :(fas fa-comment-alt fa-fw): **Vssue** comment system supported by [Vssue](https://vssue.js.org/)
* :(fas fa-comment-alt fa-fw): **Remark42** comment system supported by [Remark42](https://remark42.com/)
* :(fas fa-gem fa-fw): **giscus** comment system supported by [giscus](https://giscus.app/)

#### Extended Features

Expand Down
1 change: 1 addition & 0 deletions exampleSite/content/about/index.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ math:
* :(far fa-comment-alt fa-fw): 支持 **[Twikoo](https://twikoo.js.org/)** 评论系统
* :(far fa-comment-alt fa-fw): 支持 **[Vssue](https://vssue.js.org/)** 评论系统
* :(far fa-comment-alt fa-fw): 支持 **[Remark42](https://remark42.com/)** 评论系统
* :(far fa-comment-alt fa-fw): 支持 **[giscus](https://giscus.app/)** 评论系统

#### 扩展功能

Expand Down
13 changes: 13 additions & 0 deletions exampleSite/content/posts/theme-documentation-basics/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,19 @@ Please open the code block below to view the complete sample configuration :(far
max_shown_comments = 15
show_email_subscription = true
simple_view = false
# {{< version 0.2.13 >}} {{< link "https://giscus.app/" "giscus" >}} comment config
[params.page.comment.giscus]
enable = false
# owner/repo
dataRepo = ""
dataRepoId = ""
dataCategory = ""
dataCategoryId = ""
dataMapping = "pathname"
dataReactionsEnabled = "1"
dataEmitMetadata = "0"
lightTheme = "light"
darkTheme = "dark"
# {{< version 0.2.7 >}} Third-party library config
[params.page.library]
[params.page.library.css]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,19 @@ hugo
max_shown_comments = 15
show_email_subscription = true
simple_view = false
# {{< version 0.2.13 >}} {{< link "https://giscus.app/" "giscus" >}} 评论系统设置
[params.page.comment.giscus]
enable = false
# owner/repo
dataRepo = ""
dataRepoId = ""
dataCategory = ""
dataCategoryId = ""
dataMapping = "pathname"
dataReactionsEnabled = "1"
dataEmitMetadata = "0"
lightTheme = "light"
darkTheme = "dark"
# {{< version 0.2.7 >}} 第三方库配置
[params.page.library]
[params.page.library.css]
Expand Down
18 changes: 18 additions & 0 deletions layouts/partials/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@
Please enable JavaScript to view the comments powered by <a href="https://remark42.com/">Remark42</a>.
</noscript>
{{- end -}}

{{- /* giscus Comment System */ -}}
{{- $giscus := $comment.giscus | default dict -}}
{{- if $giscus.enable -}}
<div id="giscus"></div>
{{- $commentConfig = dict "dataRepo" $giscus.dataRepo | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = dict "dataRepoId" $giscus.dataRepoId | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = dict "dataCategory" $giscus.dataCategory | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = dict "dataCategoryId" $giscus.dataCategoryId | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = $giscus.dataMapping | default "pathname" | dict "dataMapping" | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = $giscus.dataReactionsEnabled | default "1" | dict "dataReactionsEnabled" | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = $giscus.dataEmitMetadata | default "0" | dict "dataEmitMetadata" | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = $giscus.lightTheme | default "light" | dict "lightTheme" | dict "giscus" | merge $commentConfig -}}
{{- $commentConfig = $giscus.darkTheme | default "dark" | dict "darkTheme" | dict "giscus" | merge $commentConfig -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://giscus.app/">giscus</a>.
</noscript>
{{- end -}}
</div>
{{- end -}}

Expand Down
29 changes: 29 additions & 0 deletions src/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,35 @@ function initComment() {
});
window.switchThemeEventSet.add(window._remark42OnSwitchTheme);
}
if (window.config.comment.giscus) {
const giscusConfig = window.config.comment.giscus;
const script = document.createElement('script');
script.src = 'https://giscus.app/client.js';
script.type = 'text/javascript';
script.setAttribute('data-repo', giscusConfig.dataRepo);
script.setAttribute('data-repo-id', giscusConfig.dataRepoId);
if (giscusConfig.dataCategory) script.setAttribute('data-category', giscusConfig.dataCategory);
script.setAttribute('data-category-id', giscusConfig.dataCategoryId);
script.setAttribute('data-mapping', giscusConfig.dataMapping);
script.setAttribute('data-reactions-enabled', giscusConfig.dataReactionsEnabled);
script.setAttribute('data-emit-metadata', giscusConfig.dataEmitMetadata);
script.setAttribute('theme', window.isDark ? giscusConfig.darkTheme : giscusConfig.lightTheme);
script.crossOrigin = 'anonymous';
script.async = true;
document.getElementById('giscus').appendChild(script);
window._giscusOnSwitchTheme = (() => {
const message = {
giscus: {
setConfig: {
theme: window.isDark ? giscusConfig.darkTheme : giscusConfig.lightTheme,
}
}
};
const iframe = document.querySelector('.giscus-frame');
iframe.contentWindow.postMessage(message, 'https://giscus.app');
});
window.switchThemeEventSet.add(window._giscusOnSwitchTheme);
}
}
}

Expand Down