diff options
| author | Reorx <novoreorx@gmail.com> | 2022-05-31 00:24:54 +0800 |
|---|---|---|
| committer | Reorx <novoreorx@gmail.com> | 2022-05-31 00:25:27 +0800 |
| commit | 338bc7077410564e4651d6cd05863b1396c88ac1 (patch) | |
| tree | d4b1995c7925292be03992a79dfa63067602e7f8 | |
| parent | f79aa51e05ef77b0a7d735e0a5085430d71a06c3 (diff) | |
support remark42 in comments
| -rw-r--r-- | layouts/partials/comments.html | 8 | ||||
| -rw-r--r-- | layouts/partials/remark42.html | 61 |
2 files changed, 67 insertions, 2 deletions
diff --git a/layouts/partials/comments.html b/layouts/partials/comments.html index a07744a..a9d5391 100644 --- a/layouts/partials/comments.html +++ b/layouts/partials/comments.html @@ -1,9 +1,13 @@ {{- /* You can add your own layouts/comments.html to override this file */ -}} -{{- with site.Params.commentSystem.disqus -}} - {{- partial "disqus.html" . }} +{{- with site.Params.commentSystem.remark42 -}} + {{- partial "remark42.html" . }} {{- end -}} {{- with site.Params.commentSystem.telegramWidget -}} {{- partial "telegram_widget.html" . }} {{- end -}} + +{{- with site.Params.commentSystem.disqus -}} + {{- partial "disqus.html" . }} +{{- end -}} diff --git a/layouts/partials/remark42.html b/layouts/partials/remark42.html new file mode 100644 index 0000000..bbf4f98 --- /dev/null +++ b/layouts/partials/remark42.html @@ -0,0 +1,61 @@ +<div id="remark42"></div> + +<script> + var remark_config = { + host: '{{ .url }}', + site_id: '{{ .site }}', + components: ['embed'], + max_shown_comments: 20, + theme: 'light', + // page_title: 'My custom title for a page', + // show_email_subscription: false, + simple_view: true + }; + if (isDarkTheme()) { + remark_config.theme = 'dark' + } + + (function() { + console.log('ok') + const remark42 = window.REMARK42 + + if (remark42) { + remark42.destroy() + remark42.createInstance(remark_config) + } else { + for (const component of remark_config.components) { + var d = document, s = d.createElement('script'); + s.src = `${remark_config.host}/web/${component}.mjs`; + s.type = 'module'; + s.defer = true; + // prevent the <script> from loading mutiple times by InstantClick + s.setAttribute('data-no-instant', '') + d.head.appendChild(s); + } + } + })(); +</script> + +<script data-no-instant> + (function() { + if (!toggleThemeCallbacks) { + return; + } + + toggleThemeCallbacks.push((isDark) => { + const remark42 = window.REMARK42 + if (!remark42) { + return; + } + if (!document.getElementById('remark42')) { + return; + } + + if (isDark) { + remark42.changeTheme('light'); + } else { + remark42.changeTheme('dark'); + } + }); + })(); +</script> |
