-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreadcrumbs.js
More file actions
75 lines (66 loc) · 2.11 KB
/
Copy pathbreadcrumbs.js
File metadata and controls
75 lines (66 loc) · 2.11 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Mapeo de páginas a sus configuraciones
const pageConfig = {
"index.html": {
id: "nav-index",
i18nKey: "breadcrumb.about",
},
"formacion.html": {
id: "nav-formacion",
i18nKey: "breadcrumb.education",
},
"intereses.html": {
id: "nav-intereses",
i18nKey: "breadcrumb.interests",
},
"proyectos.html": {
id: "nav-proyectos",
i18nKey: "breadcrumb.projects",
},
};
// Obtener la página actual
function getCurrentPage() {
const path = window.location.pathname;
const page = path.substring(path.lastIndexOf("/") + 1);
return page || "index.html";
}
// Generar breadcrumbs
function generateBreadcrumbs() {
const currentPage = getCurrentPage();
const breadcrumbList = document.getElementById("breadcrumb-list");
if (!breadcrumbList) return;
// Limpiar breadcrumbs existentes
breadcrumbList.innerHTML = "";
// Siempre añadir "Inicio"
const homeItem = document.createElement("li");
const homeLink = document.createElement("a");
homeLink.href = "index.html";
homeLink.setAttribute("data-i18n", "breadcrumb.home");
homeLink.textContent = window.i18n
? window.i18n.t("breadcrumb.home")
: "Manuel González Santos";
homeItem.appendChild(homeLink);
breadcrumbList.appendChild(homeItem);
// Si no estamos en index.html, añadir la página actual
if (currentPage !== "index.html" && pageConfig[currentPage]) {
const currentItem = document.createElement("li");
currentItem.setAttribute("aria-current", "page");
currentItem.setAttribute("data-i18n", pageConfig[currentPage].i18nKey);
currentItem.textContent = window.i18n.t(pageConfig[currentPage].i18nKey);
breadcrumbList.appendChild(currentItem);
}
}
// Destacar el elemento activo en el nav
function highlightActiveNav() {
const currentPage = getCurrentPage();
if (pageConfig[currentPage]) {
const activeLink = document.getElementById(pageConfig[currentPage].id);
if (activeLink) {
activeLink.classList.add("active");
}
}
}
// Ejecutar cuando el DOM esté listo
document.addEventListener("DOMContentLoaded", function () {
generateBreadcrumbs();
highlightActiveNav();
});