2024-05-31 20:32:04 +08:00
|
|
|
<script type="module">
|
|
|
|
const el = document.querySelector('#comments #giscus');
|
|
|
|
util.viewportLazyload(el, load_discus, <%= theme.comments.lazyload ?? false %>);
|
|
|
|
|
|
|
|
function load_discus() {
|
|
|
|
if (!el) return;
|
|
|
|
try {
|
2022-08-28 19:54:34 +08:00
|
|
|
el.innerHTML = '';
|
|
|
|
} catch (error) {
|
2023-12-06 13:22:07 +08:00
|
|
|
console.error(error);
|
2022-08-28 19:54:34 +08:00
|
|
|
}
|
2024-05-31 20:32:04 +08:00
|
|
|
const script = document.createElement('script');
|
2022-08-28 19:54:34 +08:00
|
|
|
script.async = true;
|
2024-05-31 20:32:04 +08:00
|
|
|
for (const key of Object.keys(el.attributes)) {
|
|
|
|
const attr = el.attributes[key];
|
2022-08-28 19:54:34 +08:00
|
|
|
if (['class', 'id'].includes(attr.name) === false) {
|
|
|
|
script.setAttribute(attr.name, attr.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
el.appendChild(script);
|
2024-05-31 20:32:04 +08:00
|
|
|
}
|
2022-08-28 19:54:34 +08:00
|
|
|
</script>
|