-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheader.js
More file actions
39 lines (35 loc) · 1.28 KB
/
header.js
File metadata and controls
39 lines (35 loc) · 1.28 KB
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
29
30
31
32
33
34
35
36
37
38
39
document.addEventListener("DOMContentLoaded", function() {
const pages = {
"/index.html": "Inicio",
"/reservas.html": "Reservas",
"/promociones.html": "Promociones",
"/trabajos.html": "Trabajos",
"/contactos.html": "Contactos",
"./comercio/e-comers.html": "Ventas"
};
// Obtener la ruta relativa correcta de la página actual
const pathParts = window.location.pathname.split("/");
const currentPage = (pathParts.slice(-2).join("/") || "index.html").replace(/^\//, '');
const navItems = Object.keys(pages).map(page => {
const pageKey = page.replace(/^\.\//, ''); // Eliminar ./ del inicio de la clave
if (pageKey === currentPage) {
return '';
} else {
return `<li><a href="${page}">${pages[page]}</a></li>`;
}
}).join("");
const headerContent = `
<img src="../imagenes/barbershoplogo.png" alt="log" class="header-img">
<nav>
<ul>
${navItems}
</ul>
</nav>
`;
const headerElement = document.getElementById("main-header");
if (headerElement) {
headerElement.innerHTML = headerContent;
} else {
console.error("Header element with id 'main-header' not found.");
}
});