Skip to content

Commit

Permalink
feat(comments): add Giscus support (#50)
Browse files Browse the repository at this point in the history
* feat(comments) add Giscus support

* feat: default value for reactionsEnabled and emitMetadata

* feat: support custom mapping

* fix: add quote

* style: giscus border and top padding
  • Loading branch information
WingLim authored Oct 8, 2021
1 parent 2c54bd4 commit 7bf7c39
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/sass/base/_scaffolding.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ a.section-button {
}

.container {
max-width: 825px;
max-width: 830px;
padding: 0 1.5rem;
margin-left: auto;
margin-right: auto;
Expand Down
4 changes: 4 additions & 0 deletions assets/sass/components/_comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@

#cusdis_thread {
padding-top: 2rem;
}

.giscus {
padding-top: 2rem;
}
42 changes: 42 additions & 0 deletions layouts/partials/comments/provider/giscus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script src="https://giscus.app/client.js"
data-repo="{{ .Site.Params.comments.giscus.repo }}"
data-repo-id="{{ .Site.Params.comments.giscus.id }}"
{{ with .Site.Params.comments.giscus.category }}
data-category="{{ .name }}"
data-category-id="{{ .id }}"
{{ end }}
data-mapping="{{ .Site.Params.comments.giscus.mapping | default "pathname" }}"
data-reactions-enabled="{{ .Site.Params.comments.giscus.reactionsEnabled | default 1 }}"
data-emit-metadata="{{ .Site.Params.comments.giscus.emitMetadata | default 0 }}"
data-theme="light"
crossorigin="anonymous"
async
>
</script>

<script>
function setGiscusTeheme(theme) {
let giscus = document.querySelector('.giscus iframe');
if (giscus) {
giscus.contentWindow.postMessage(
{
giscus: {
setConfig: {
theme: theme
}
}
},
'https://giscus.app'
)
}
}

addEventListener('message', event => {
if (event.origin !== 'https://giscus.app') return;
setGiscusTeheme(document.documentElement.dataset.userColorScheme)
});

window.addEventListener('onColorSchemeChange', (e) => {
setGiscusTeheme(e.detail)
})
</script>

0 comments on commit 7bf7c39

Please sign in to comment.