blog/themes/fluid/layout/_partials/comments/giscus.ejs
2024-11-16 11:34:10 +08:00

37 lines
1.6 KiB
Plaintext

<% if (theme.giscus && theme.giscus['repo'] && theme.giscus['repo-id']) { %>
<div id="giscus" class="giscus"></div>
<script type="text/javascript">
Fluid.utils.loadComments('#giscus', function() {
var options = <%- JSON.stringify(theme.giscus || {}) %>;
var attributes = {};
for (let option in options) {
if (!option.startsWith('theme-')) {
var key = option.startsWith('data-') ? option : 'data-' + option;
attributes[key] = options[option];
}
}
var light = '<%= theme.giscus['theme-light'] || 'light' %>';
var dark = '<%= theme.giscus['theme-dark'] || 'dark' %>';
window.GiscusThemeLight = light;
window.GiscusThemeDark = dark;
attributes['data-theme'] = document.documentElement.getAttribute('data-user-color-scheme') === 'dark' ? dark : light;
for (let attribute in attributes) {
var value = attributes[attribute];
if (value === undefined || value === null || value === '') {
delete attributes[attribute];
}
}
var s = document.createElement('script');
s.setAttribute('src', 'https://giscus.app/client.js');
s.setAttribute('crossorigin', 'anonymous');
for (let attribute in attributes) {
s.setAttribute(attribute, attributes[attribute]);
}
var ss = document.getElementsByTagName('script');
var e = ss.length > 0 ? ss[ss.length - 1] : document.head || document.documentElement;
e.parentNode.insertBefore(s, e.nextSibling);
});
</script>
<noscript>Please enable JavaScript to view the comments</noscript>
<% } %>