forked from FWS/FWS-TEMPLATE-Website-OnePage
Feat(pac): add page pacage
This commit is contained in:
1 parent
f95bdd86eb
commit
d5fd472ff5
7 files changed
+1110
No files matched your search
@@ -0,0 +1,487 @@
|
||||
(() => {
|
||||
const PACKAGES_SRC = "/p/paquets/packages.json";
|
||||
|
||||
let packagesPromise = null;
|
||||
|
||||
function fetchPackages() {
|
||||
if (!packagesPromise) {
|
||||
packagesPromise = fetch(PACKAGES_SRC, { cache: "no-store" })
|
||||
.then((response) => {
|
||||
if (!response.ok) throw new Error("Erreur " + response.status);
|
||||
return response.json();
|
||||
});
|
||||
}
|
||||
return packagesPromise;
|
||||
}
|
||||
|
||||
function formatDate(iso) {
|
||||
if (!iso) return null;
|
||||
try {
|
||||
return new Date(iso).toLocaleDateString("fr-FR", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
} catch {
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Menu déroulant de la barre de navigation ── */
|
||||
|
||||
function initNavDropdown() {
|
||||
const root = document.querySelector("[data-nav-dropdown]");
|
||||
if (!root) return;
|
||||
// Le script est chargé aussi dans la page « Paquets » (injection SPA) :
|
||||
// on ne câble le menu qu'une seule fois.
|
||||
if (root.dataset.navReady === "1") return;
|
||||
root.dataset.navReady = "1";
|
||||
|
||||
const toggle = root.querySelector(".nav-dropdown-toggle");
|
||||
const panel = root.querySelector(".nav-dropdown-panel");
|
||||
if (!toggle || !panel) return;
|
||||
|
||||
function setOpen(open) {
|
||||
root.classList.toggle("is-open", open);
|
||||
toggle.setAttribute("aria-expanded", open ? "true" : "false");
|
||||
}
|
||||
|
||||
function closeIfOutside(event) {
|
||||
if (!root.contains(event.target)) setOpen(false);
|
||||
}
|
||||
|
||||
toggle.addEventListener("click", (event) => {
|
||||
event.stopPropagation();
|
||||
setOpen(!root.classList.contains("is-open"));
|
||||
});
|
||||
|
||||
document.addEventListener("click", closeIfOutside);
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape" && root.classList.contains("is-open")) {
|
||||
setOpen(false);
|
||||
toggle.focus();
|
||||
}
|
||||
});
|
||||
|
||||
// Refermer le menu quand on navigue vers une autre page et
|
||||
// réévaluer l'état actif une fois l'URL SPA réécrite.
|
||||
document.addEventListener("page:before-route-change", () => {
|
||||
setOpen(false);
|
||||
setTimeout(markActiveRoute, 300);
|
||||
});
|
||||
|
||||
function markActiveRoute() {
|
||||
const search = window.location.search || "";
|
||||
const active = search.includes("p=paquets") || search.includes("p/paquets");
|
||||
if (active) {
|
||||
toggle.setAttribute("aria-current", "page");
|
||||
} else {
|
||||
toggle.removeAttribute("aria-current");
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("popstate", markActiveRoute);
|
||||
markActiveRoute();
|
||||
|
||||
const list = panel.querySelector("[data-packages-nav]");
|
||||
if (!list) return;
|
||||
|
||||
fetchPackages()
|
||||
.then((packages) => {
|
||||
list.innerHTML = "";
|
||||
packages.forEach((pkg, index) => {
|
||||
const item = document.createElement("a");
|
||||
item.className = "nav-dropdown-item";
|
||||
item.href = "/?p/paquets/" + (index + 1) + "/";
|
||||
item.dataset.route = "paquets/" + (index + 1);
|
||||
|
||||
const name = document.createElement("strong");
|
||||
name.textContent = pkg.name;
|
||||
|
||||
if (pkg.latest && pkg.latest.name) {
|
||||
const version = document.createElement("span");
|
||||
version.className = "nav-dropdown-version";
|
||||
version.textContent = pkg.latest.name;
|
||||
name.appendChild(version);
|
||||
}
|
||||
|
||||
const tagline = document.createElement("small");
|
||||
tagline.textContent = pkg.tagline || "";
|
||||
|
||||
item.appendChild(name);
|
||||
item.appendChild(tagline);
|
||||
|
||||
item.addEventListener("click", () => setOpen(false));
|
||||
|
||||
list.appendChild(item);
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
list.innerHTML = '<p class="nav-dropdown-error">Impossible de charger les paquets.</p>';
|
||||
});
|
||||
}
|
||||
|
||||
/* ── Page « Paquets » ── */
|
||||
|
||||
function createEmptyState(message) {
|
||||
const p = document.createElement("p");
|
||||
p.className = "paquet-empty";
|
||||
p.textContent = message;
|
||||
return p;
|
||||
}
|
||||
|
||||
function createChangelog(pkg) {
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.className = "paquet-changelog";
|
||||
|
||||
const title = document.createElement("h3");
|
||||
title.textContent = "Historique";
|
||||
wrapper.appendChild(title);
|
||||
|
||||
if (!pkg.changelog || pkg.changelog.length === 0) {
|
||||
wrapper.appendChild(createEmptyState("Historique en cours de rédaction."));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
const timeline = document.createElement("ol");
|
||||
timeline.className = "paquet-timeline";
|
||||
|
||||
for (const entry of pkg.changelog) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "paquet-timeline-item";
|
||||
|
||||
const version = document.createElement("strong");
|
||||
version.className = "paquet-timeline-version";
|
||||
version.textContent = entry.version || "—";
|
||||
|
||||
const date = document.createElement("time");
|
||||
date.className = "paquet-timeline-date";
|
||||
date.textContent = formatDate(entry.date) || "";
|
||||
if (entry.date) date.dateTime = entry.date;
|
||||
|
||||
const notes = document.createElement("span");
|
||||
notes.className = "paquet-timeline-notes";
|
||||
notes.textContent = entry.notes || "";
|
||||
|
||||
li.appendChild(version);
|
||||
li.appendChild(date);
|
||||
if (entry.notes) li.appendChild(notes);
|
||||
timeline.appendChild(li);
|
||||
}
|
||||
|
||||
wrapper.appendChild(timeline);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function createScreens(pkg) {
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.className = "paquet-screens";
|
||||
|
||||
const title = document.createElement("h3");
|
||||
title.textContent = "Captures d'écran";
|
||||
wrapper.appendChild(title);
|
||||
|
||||
if (!pkg.screens || pkg.screens.length === 0) {
|
||||
wrapper.appendChild(createEmptyState("Captures d'écran à venir."));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
const grid = document.createElement("div");
|
||||
grid.className = "paquet-screens-grid";
|
||||
|
||||
for (const screen of pkg.screens) {
|
||||
const figure = document.createElement("figure");
|
||||
const img = document.createElement("img");
|
||||
img.src = screen.src;
|
||||
img.alt = screen.alt || pkg.name;
|
||||
img.loading = "lazy";
|
||||
figure.appendChild(img);
|
||||
if (screen.caption) {
|
||||
const figcaption = document.createElement("figcaption");
|
||||
figcaption.textContent = screen.caption;
|
||||
figure.appendChild(figcaption);
|
||||
}
|
||||
grid.appendChild(figure);
|
||||
}
|
||||
|
||||
wrapper.appendChild(grid);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function createLinks(pkg) {
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.className = "paquet-links";
|
||||
|
||||
const title = document.createElement("h3");
|
||||
title.textContent = "Liens utiles";
|
||||
wrapper.appendChild(title);
|
||||
|
||||
if (!pkg.links || pkg.links.length === 0) {
|
||||
wrapper.appendChild(createEmptyState("Aucun lien pour le moment."));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
for (const link of pkg.links) {
|
||||
const a = document.createElement("a");
|
||||
a.className = "button button-secondary";
|
||||
a.href = link.url;
|
||||
const external = /^https?:\/\//i.test(link.url);
|
||||
if (external) {
|
||||
a.target = "_blank";
|
||||
a.rel = "noopener noreferrer";
|
||||
}
|
||||
a.textContent = link.label || link.url;
|
||||
wrapper.appendChild(a);
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function createPackageCard(pkg, position) {
|
||||
const card = document.createElement("article");
|
||||
card.className = "paquet-card";
|
||||
card.id = "paquet-" + pkg.id;
|
||||
|
||||
const head = document.createElement("header");
|
||||
head.className = "paquet-head";
|
||||
|
||||
const titleRow = document.createElement("div");
|
||||
titleRow.className = "paquet-title-row";
|
||||
|
||||
const title = document.createElement("h2");
|
||||
title.textContent = pkg.name;
|
||||
|
||||
const badge = document.createElement("span");
|
||||
badge.className = "paquet-since";
|
||||
badge.textContent = pkg.sinceLabel || "FWS";
|
||||
if (pkg.since) {
|
||||
badge.title = "Depuis le " + formatDate(pkg.since);
|
||||
}
|
||||
|
||||
const detailLink = document.createElement("a");
|
||||
detailLink.className = "paquet-detail-link";
|
||||
detailLink.href = "/?p/paquets/" + position + "/";
|
||||
detailLink.dataset.route = "paquets/" + position;
|
||||
detailLink.textContent = "Voir en grand";
|
||||
|
||||
titleRow.appendChild(title);
|
||||
titleRow.appendChild(badge);
|
||||
titleRow.appendChild(detailLink);
|
||||
head.appendChild(titleRow);
|
||||
|
||||
if (pkg.tagline) {
|
||||
const tagline = document.createElement("p");
|
||||
tagline.className = "paquet-tagline";
|
||||
tagline.textContent = pkg.tagline;
|
||||
head.appendChild(tagline);
|
||||
}
|
||||
|
||||
const latest = document.createElement("p");
|
||||
latest.className = "paquet-latest";
|
||||
if (pkg.latest && pkg.latest.name) {
|
||||
latest.textContent =
|
||||
"Dernière release : " +
|
||||
pkg.latest.name +
|
||||
(pkg.latest.date ? " — " + formatDate(pkg.latest.date) : "");
|
||||
} else {
|
||||
latest.textContent = "Aucune release publiée pour le moment.";
|
||||
}
|
||||
head.appendChild(latest);
|
||||
|
||||
if (pkg.description) {
|
||||
const description = document.createElement("p");
|
||||
description.className = "paquet-description";
|
||||
description.textContent = pkg.description;
|
||||
head.appendChild(description);
|
||||
}
|
||||
|
||||
card.appendChild(head);
|
||||
|
||||
const body = document.createElement("div");
|
||||
body.className = "paquet-body";
|
||||
body.appendChild(createChangelog(pkg));
|
||||
body.appendChild(createScreens(pkg));
|
||||
body.appendChild(createLinks(pkg));
|
||||
card.appendChild(body);
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
function initPackagesPage(container) {
|
||||
fetchPackages()
|
||||
.then((packages) => {
|
||||
container.innerHTML = "";
|
||||
packages.forEach((pkg, index) => {
|
||||
container.appendChild(createPackageCard(pkg, index + 1));
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
container.innerHTML = "";
|
||||
container.appendChild(
|
||||
createEmptyState("Impossible de charger les paquets. Réessayez plus tard.")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/* ── Page détail « Paquets / N » ── */
|
||||
|
||||
function packageIndexFromLocation() {
|
||||
const haystack = window.location.search + window.location.pathname;
|
||||
const match = haystack.match(/paquets\/(\d+)/);
|
||||
return match ? parseInt(match[1], 10) : 1;
|
||||
}
|
||||
|
||||
function createDetailNav(nav, position, total) {
|
||||
if (position > 1) {
|
||||
const prev = document.createElement("a");
|
||||
prev.className = "paquet-detail-prev";
|
||||
prev.href = "/?p/paquets/" + (position - 1) + "/";
|
||||
prev.dataset.route = "paquets/" + (position - 1);
|
||||
prev.textContent = "← Paquet précédent";
|
||||
nav.appendChild(prev);
|
||||
}
|
||||
|
||||
if (position < total) {
|
||||
const next = document.createElement("a");
|
||||
next.className = "paquet-detail-next";
|
||||
next.href = "/?p/paquets/" + (position + 1) + "/";
|
||||
next.dataset.route = "paquets/" + (position + 1);
|
||||
next.textContent = "Paquet suivant →";
|
||||
nav.appendChild(next);
|
||||
}
|
||||
}
|
||||
|
||||
function renderPackageDetail(container, pkg, position, total) {
|
||||
const back = document.createElement("a");
|
||||
back.className = "paquet-detail-back";
|
||||
back.href = "/?p/paquets/";
|
||||
back.dataset.route = "paquets";
|
||||
back.textContent = "← Tous les paquets";
|
||||
container.appendChild(back);
|
||||
|
||||
const hero = document.createElement("div");
|
||||
hero.className = "paquet-detail-hero";
|
||||
|
||||
const badge = document.createElement("span");
|
||||
badge.className = "paquet-since";
|
||||
badge.textContent = pkg.sinceLabel || "FWS";
|
||||
if (pkg.since) {
|
||||
badge.title = "Depuis le " + formatDate(pkg.since);
|
||||
}
|
||||
hero.appendChild(badge);
|
||||
|
||||
const title = document.createElement("h1");
|
||||
title.textContent = pkg.name;
|
||||
hero.appendChild(title);
|
||||
|
||||
if (pkg.tagline) {
|
||||
const tagline = document.createElement("p");
|
||||
tagline.className = "paquet-tagline";
|
||||
tagline.textContent = pkg.tagline;
|
||||
hero.appendChild(tagline);
|
||||
}
|
||||
|
||||
if (pkg.description) {
|
||||
const description = document.createElement("p");
|
||||
description.className = "paquet-description";
|
||||
description.textContent = pkg.description;
|
||||
hero.appendChild(description);
|
||||
}
|
||||
|
||||
const latest = document.createElement("div");
|
||||
latest.className = "paquet-detail-latest";
|
||||
if (pkg.latest && pkg.latest.name) {
|
||||
const version = document.createElement("span");
|
||||
version.className = "paquet-detail-version";
|
||||
version.textContent = pkg.latest.name;
|
||||
latest.appendChild(version);
|
||||
|
||||
if (pkg.latest.date) {
|
||||
const date = document.createElement("span");
|
||||
date.className = "paquet-detail-date";
|
||||
date.textContent = "Publiée le " + formatDate(pkg.latest.date);
|
||||
latest.appendChild(date);
|
||||
}
|
||||
} else {
|
||||
latest.textContent = "Aucune release publiée pour le moment.";
|
||||
latest.classList.add("paquet-detail-latest-empty");
|
||||
}
|
||||
hero.appendChild(latest);
|
||||
|
||||
container.appendChild(hero);
|
||||
|
||||
const body = document.createElement("div");
|
||||
body.className = "paquet-detail-body";
|
||||
body.appendChild(createChangelog(pkg));
|
||||
body.appendChild(createScreens(pkg));
|
||||
container.appendChild(body);
|
||||
|
||||
container.appendChild(createLinks(pkg));
|
||||
|
||||
const nav = document.createElement("nav");
|
||||
nav.className = "paquet-detail-nav";
|
||||
nav.setAttribute("aria-label", "Parcourir les paquets");
|
||||
createDetailNav(nav, position, total);
|
||||
if (nav.childNodes.length > 0) {
|
||||
container.appendChild(nav);
|
||||
}
|
||||
}
|
||||
|
||||
function initPackageDetail(container) {
|
||||
const position = packageIndexFromLocation();
|
||||
|
||||
fetchPackages()
|
||||
.then((packages) => {
|
||||
container.innerHTML = "";
|
||||
const pkg = packages[position - 1];
|
||||
if (!pkg) {
|
||||
container.appendChild(
|
||||
createEmptyState("Ce paquet n'existe pas (il y en a " + packages.length + ").")
|
||||
);
|
||||
const back = document.createElement("a");
|
||||
back.className = "paquet-detail-back";
|
||||
back.href = "/?p/paquets/";
|
||||
back.dataset.route = "paquets";
|
||||
back.textContent = "← Tous les paquets";
|
||||
container.appendChild(back);
|
||||
return;
|
||||
}
|
||||
|
||||
renderPackageDetail(container, pkg, position, packages.length);
|
||||
// Le routeur SPA applique le titre et le scroll après le rendu :
|
||||
// on force le vrai nom du paquet un peu plus tard.
|
||||
setTimeout(() => {
|
||||
document.title = pkg.name + " | FWS Linux";
|
||||
}, 150);
|
||||
})
|
||||
.catch(() => {
|
||||
container.innerHTML = "";
|
||||
container.appendChild(
|
||||
createEmptyState("Impossible de charger le paquet. Réessayez plus tard.")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/* ── Initialisation ── */
|
||||
|
||||
function init() {
|
||||
const hasNav = document.querySelector("[data-nav-dropdown]") !== null;
|
||||
const hasPage = document.querySelector("[data-packages-page]") !== null;
|
||||
const hasDetail = document.querySelector("[data-package-detail]") !== null;
|
||||
if (!hasNav && !hasPage && !hasDetail) return;
|
||||
|
||||
initNavDropdown();
|
||||
|
||||
const pageContainers = document.querySelectorAll("[data-packages-page]");
|
||||
pageContainers.forEach(initPackagesPage);
|
||||
|
||||
const detailContainers = document.querySelectorAll("[data-package-detail]");
|
||||
detailContainers.forEach(initPackageDetail);
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user