Refactor blog bootstrap loader

This commit is contained in:
thePR0M3TH3AN committed 2025-10-13 17:08:43 -04:00
1 parent 455da6b3ea
commit e8e4a1e168
2 files changed
+17 -17

No files matched your search

+12 -1
View File
@@ -42,7 +42,18 @@
<link rel="stylesheet" href="./css/tailwind.generated.css" />
<script src="./js/tracking.js" defer></script>
<script type="module" crossorigin>
import "./js/blog/index.js";
import { bootstrapBlog } from "./js/blog/index.js";
import { initZapthreadsEmbed } from "./js/blog/zapthreadsEmbed.js";
const startBlog = () => {
bootstrapBlog({ initZapthreadsEmbed });
};
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", startBlog, { once: true });
} else {
startBlog();
}
</script>
</head>
<body class="blog-body">
+5 -16
View File
@@ -1,4 +1,3 @@
import { initZapthreadsEmbed } from './zapthreadsEmbed.js';
import { createCarousel, advanceSlide, destroyCarousel } from './carousel.js';
import { mountProgressBar } from './progressBar.js';
import { applyDynamicStyles } from '../ui/styleSystem.js';
@@ -460,7 +459,7 @@ function extractZapthreadsOptions(element) {
return options;
}
function initializeZapthreads({ registerCleanup, isDestroyed }) {
function initializeZapthreads({ registerCleanup, isDestroyed, initZapthreadsEmbed }) {
if (typeof initZapthreadsEmbed !== 'function') {
return;
}
@@ -528,7 +527,7 @@ function initializeZapthreads({ registerCleanup, isDestroyed }) {
});
}
function mountBlogApp() {
function mountBlogApp({ initZapthreadsEmbed } = {}) {
const runtime = {
destroyed: false,
cleanupCallbacks: new Set(),
@@ -720,6 +719,7 @@ function mountBlogApp() {
initializeZapthreads({
registerCleanup,
isDestroyed: () => runtime.destroyed,
initZapthreadsEmbed,
});
return destroy;
@@ -727,11 +727,11 @@ function mountBlogApp() {
let activeTeardown = null;
export function bootstrapBlog() {
export function bootstrapBlog(options = {}) {
if (typeof activeTeardown === 'function') {
activeTeardown();
}
const destroy = mountBlogApp();
const destroy = mountBlogApp(options);
activeTeardown = () => {
destroy();
activeTeardown = null;
@@ -745,14 +745,3 @@ export function teardownBlog() {
}
}
function runBlogBootstrap() {
bootstrapBlog();
}
if (typeof document !== 'undefined') {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', runBlogBootstrap, { once: true });
} else {
runBlogBootstrap();
}
}