-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.js
More file actions
28 lines (24 loc) · 916 Bytes
/
components.js
File metadata and controls
28 lines (24 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Shared components loader for header and footer.
async function loadComponent(path) {
const response = await fetch(path);
if (!response.ok) throw new Error(`Errore nel caricamento di ${path}`);
return response.text();
}
async function mountLayoutComponents() {
const isBlogPage = window.location.pathname.includes("/blog/");
const basePath = isBlogPage ? ".." : ".";
try {
const [headerHtml, footerHtml] = await Promise.all([
loadComponent(`${basePath}/components/header.html`),
loadComponent(`${basePath}/components/footer.html`),
]);
document.body.insertAdjacentHTML("afterbegin", headerHtml);
document.body.insertAdjacentHTML("beforeend", footerHtml);
if (window.lucide) {
window.lucide.createIcons();
}
} catch (error) {
console.error("Component loader error:", error);
}
}
document.addEventListener("DOMContentLoaded", mountLayoutComponents);