mirror of
https://github.com/lbr77/blog-astro.git
synced 2026-04-09 00:19:12 +00:00
log
This commit is contained in:
@@ -6,8 +6,16 @@
|
|||||||
|
|
||||||
function renderTwikoo() {
|
function renderTwikoo() {
|
||||||
var container = document.querySelector(TARGET_SELECTOR)
|
var container = document.querySelector(TARGET_SELECTOR)
|
||||||
if (!container || !window.twikoo) return
|
if (!container) {
|
||||||
|
console.warn('[twikoo-loader] target container not found')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!window.twikoo) {
|
||||||
|
console.warn('[twikoo-loader] twikoo is not ready when render called')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.info('[twikoo-loader] renderTwikoo: init comments')
|
||||||
container.innerHTML = ''
|
container.innerHTML = ''
|
||||||
window.twikoo.init({
|
window.twikoo.init({
|
||||||
envId: 'https://twikoo.hk.nvme0n1p.dev/',
|
envId: 'https://twikoo.hk.nvme0n1p.dev/',
|
||||||
@@ -20,31 +28,37 @@
|
|||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
if (existing.dataset.failed === 'true') {
|
if (existing.dataset.failed === 'true') {
|
||||||
|
console.warn('[twikoo-loader] previous load failed, removing script')
|
||||||
existing.remove()
|
existing.remove()
|
||||||
} else {
|
} else {
|
||||||
if (!window.twikoo) {
|
if (!window.twikoo) {
|
||||||
|
console.info('[twikoo-loader] script already present, waiting for load')
|
||||||
existing.addEventListener('load', renderTwikoo, { once: true })
|
existing.addEventListener('load', renderTwikoo, { once: true })
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info('[twikoo-loader] injecting script', TWIKOO_SRC)
|
||||||
var script = document.createElement('script')
|
var script = document.createElement('script')
|
||||||
script.id = SCRIPT_ID
|
script.id = SCRIPT_ID
|
||||||
script.src = TWIKOO_SRC
|
script.src = TWIKOO_SRC
|
||||||
script.async = true
|
script.async = true
|
||||||
script.onload = function () {
|
script.onload = function () {
|
||||||
|
console.info('[twikoo-loader] twikoo script loaded')
|
||||||
script.dataset.loaded = 'true'
|
script.dataset.loaded = 'true'
|
||||||
renderTwikoo()
|
renderTwikoo()
|
||||||
}
|
}
|
||||||
script.onerror = function (err) {
|
script.onerror = function (err) {
|
||||||
script.dataset.failed = 'true'
|
script.dataset.failed = 'true'
|
||||||
|
console.error('[twikoo-loader] Failed to load Twikoo:', err)
|
||||||
console.error('Failed to load Twikoo:', err)
|
console.error('Failed to load Twikoo:', err)
|
||||||
}
|
}
|
||||||
document.head.appendChild(script)
|
document.head.appendChild(script)
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
console.info('[twikoo-loader] init called')
|
||||||
ensureScript()
|
ensureScript()
|
||||||
|
|
||||||
if (window.twikoo) {
|
if (window.twikoo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user