2022-05-05 17:36:54 +02:00
|
|
|
{%- if site.utterances.follow_site_theme -%}
|
2022-07-14 17:39:28 +02:00
|
|
|
<div id="utterances-placeholder"></div>
|
2022-05-05 17:36:54 +02:00
|
|
|
<script>
|
2022-07-14 17:39:28 +02:00
|
|
|
const utterancesThemeFromDataTheme = () => {
|
|
|
|
const dataTheme = document.documentElement.getAttribute('data-theme');
|
|
|
|
return `github-${dataTheme}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setUtterancesTheme = () => {
|
2022-05-05 17:36:54 +02:00
|
|
|
const iframe = document.querySelector('.utterances-frame');
|
|
|
|
if (iframe) {
|
|
|
|
const message = {
|
|
|
|
type: 'set-theme',
|
2022-07-14 17:39:28 +02:00
|
|
|
theme: utterancesThemeFromDataTheme()
|
2022-05-05 17:36:54 +02:00
|
|
|
};
|
|
|
|
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// dynamic change
|
|
|
|
const observer = new MutationObserver((mutationsList, observer) => {
|
|
|
|
for (let mutation of mutationsList) {
|
|
|
|
if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') {
|
2022-07-14 17:39:28 +02:00
|
|
|
setUtterancesTheme();
|
2022-05-05 17:36:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-07-14 17:39:28 +02:00
|
|
|
observer.observe(document.documentElement, { attributes: true, childList: false, subtree: false });
|
|
|
|
|
|
|
|
let utterancesScript = document.createElement('script');
|
|
|
|
utterancesScript.async = true;
|
|
|
|
utterancesScript.src = 'https://utteranc.es/client.js';
|
|
|
|
utterancesScript.crossOrigin = 'anonymous';
|
|
|
|
utterancesScript.setAttribute('issue-term', '{{ site.utterances.issue_term }}');
|
|
|
|
utterancesScript.setAttribute('label', '{{ site.utterances.label }}');
|
|
|
|
utterancesScript.setAttribute('repo', '{{ site.utterances.repo }}');
|
|
|
|
utterancesScript.setAttribute('theme', utterancesThemeFromDataTheme());
|
|
|
|
|
|
|
|
const placeholder = document.getElementById('utterances-placeholder');
|
|
|
|
placeholder.parentNode.replaceChild(utterancesScript, placeholder);
|
2022-05-05 17:36:54 +02:00
|
|
|
</script>
|
2022-07-14 17:39:28 +02:00
|
|
|
{%- else -%}
|
|
|
|
<script async
|
|
|
|
crossorigin="anonymous"
|
|
|
|
issue-term="{{ site.utterances.issue_term }}"
|
|
|
|
label="{{ site.utterances.label }}"
|
|
|
|
repo="{{ site.utterances.repo }}"
|
|
|
|
src="https://utteranc.es/client.js"
|
|
|
|
theme="{{ site.utterances.theme }}">
|
|
|
|
</script>
|
2022-05-05 17:36:54 +02:00
|
|
|
{%- endif -%}
|