forked from FWS/FWS-TEMPLATE-Website-OnePage
Feat(site): rendu serveur PHP — paquets en SQLite, releases Gitea, build ISO
- Front controller page.php + inc/site.php : coquille et pages rendues
en PHP (accueil, dl, paquets, paquets/N, equipe, contact, 404) ; les
URLs ne changent pas et l'apparence est conservée.
- Paquets stockés dans la base SQLite partagée (table packages),
éditables depuis l'onglet 📦 Paquets de /admin/bugs, avec bouton de
synchronisation des releases depuis l'API Gitea du dépôt lié.
Repli automatique sur packages.json si la base est vide.
- Releases ISO de la page Téléchargements récupérées côté serveur
(Gitea FWS/ISO sinon GitHub) avec cache fichier 10 min ; note de
release rendue en Markdown serveur (Voir plus / Voir moins).
- Suppression du routeur SPA et des chargeurs JS devenus inutiles
(app.js, packages.js, downloads.js, creators-loader.js, index.html) ;
restent nav.js, note-toggle.js et hero-carousel.js.
- Panneau admin : onglet Build ISO (git pull sur main, build.sh avec
repli setup-aur.sh, terminal des logs en direct), durcissement UTF-8
à l'écriture des paquets (json_encode ne casse plus sur des accents
mal encodés), 404 réels et gardes d'accès direct sur les corps PHP.
This commit is contained in:
1 parent
34b3f1cf3c
commit
1775adceaa
34 files changed
+2799
-1862
No files matched your search
@@ -1,108 +0,0 @@
|
||||
(() => {
|
||||
function formatDate(iso) {
|
||||
if (!iso) return null;
|
||||
try {
|
||||
const d = new Date(iso);
|
||||
return d.toLocaleDateString("fr-FR", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
} catch {
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
|
||||
function createCreatorCard(creator) {
|
||||
const card = document.createElement("article");
|
||||
card.className = "creator-card";
|
||||
|
||||
if (creator.avatar) {
|
||||
const img = document.createElement("img");
|
||||
img.className = "creator-avatar";
|
||||
img.src = creator.avatar;
|
||||
img.alt = creator.name || creator.role || "";
|
||||
img.loading = "lazy";
|
||||
card.appendChild(img);
|
||||
}
|
||||
|
||||
const info = document.createElement("div");
|
||||
info.className = "creator-info";
|
||||
|
||||
if (creator.name) {
|
||||
const name = document.createElement("h3");
|
||||
name.className = "creator-name";
|
||||
name.textContent = creator.name;
|
||||
info.appendChild(name);
|
||||
}
|
||||
|
||||
if (creator.role) {
|
||||
const role = document.createElement("span");
|
||||
role.className = "creator-role";
|
||||
role.textContent = creator.role;
|
||||
info.appendChild(role);
|
||||
}
|
||||
|
||||
if (creator.joined) {
|
||||
const joined = document.createElement("span");
|
||||
joined.className = "creator-joined";
|
||||
joined.textContent = "A rejoint le " + formatDate(creator.joined);
|
||||
info.appendChild(joined);
|
||||
}
|
||||
|
||||
if (creator.email) {
|
||||
const email = document.createElement("a");
|
||||
email.className = "creator-email";
|
||||
email.href = "mailto:" + creator.email;
|
||||
email.textContent = creator.email;
|
||||
info.appendChild(email);
|
||||
}
|
||||
|
||||
if (creator.links && creator.links.length > 0) {
|
||||
const links = document.createElement("div");
|
||||
links.className = "creator-links";
|
||||
for (const link of creator.links) {
|
||||
const a = document.createElement("a");
|
||||
a.className = "creator-link";
|
||||
a.href = link.url;
|
||||
a.target = "_blank";
|
||||
a.rel = "noopener noreferrer";
|
||||
a.textContent = link.label || link.url;
|
||||
links.appendChild(a);
|
||||
}
|
||||
info.appendChild(links);
|
||||
}
|
||||
|
||||
card.appendChild(info);
|
||||
return card;
|
||||
}
|
||||
|
||||
async function loadCreators() {
|
||||
const containers = document.querySelectorAll("[data-creators-src]");
|
||||
for (const container of containers) {
|
||||
const src = container.getAttribute("data-creators-src");
|
||||
if (!src) continue;
|
||||
|
||||
try {
|
||||
const response = await fetch(src, { cache: "no-store" });
|
||||
if (!response.ok) throw new Error("Erreur " + response.status);
|
||||
const creators = await response.json();
|
||||
|
||||
const grid = document.createElement("div");
|
||||
grid.className = "creators-grid";
|
||||
|
||||
for (const creator of creators) {
|
||||
grid.appendChild(createCreatorCard(creator));
|
||||
}
|
||||
|
||||
container.innerHTML = "";
|
||||
container.appendChild(grid);
|
||||
} catch (err) {
|
||||
container.innerHTML =
|
||||
'<p class="creators-error">Impossible de charger les données des créateurs.</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadCreators();
|
||||
})();
|
||||
@@ -1,461 +0,0 @@
|
||||
(() => {
|
||||
const OWNER = "You-re-like-Windows-a-bitch";
|
||||
const REPO = "ISO";
|
||||
const RELEASES_URL = `https://api.github.com/repos/${OWNER}/${REPO}/releases?per_page=5`;
|
||||
const TAGS_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=5`;
|
||||
const REPO_URL = `https://github.com/${OWNER}/${REPO}`;
|
||||
|
||||
const currentVersionNode = document.querySelector("[data-current-version]");
|
||||
const currentVersionDateNode = document.querySelector("[data-current-version-date]");
|
||||
const currentReleaseNoteNode = document.querySelector("[data-current-release-note]");
|
||||
const latestDownloadNode = document.querySelector("[data-latest-download]");
|
||||
const viewMoreNode = document.querySelector("[data-view-more]");
|
||||
const versionsListNode = document.querySelector("[data-versions-list]");
|
||||
const toggleNoteNode = document.querySelector("[data-toggle-release-note]");
|
||||
|
||||
let fullReleaseBodyHtml = "";
|
||||
const TRUNCATE_LENGTH = 600;
|
||||
|
||||
function formatDate(value) {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return "";
|
||||
return date.toLocaleDateString("fr-FR", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
function getReleaseLabel(entry) {
|
||||
return entry?.name || entry?.tag_name || entry?.ref || "Sans nom";
|
||||
}
|
||||
|
||||
function getReleasePageUrl(entry, mode) {
|
||||
if (mode === "releases") {
|
||||
return pickDirectDownloadUrl(entry);
|
||||
}
|
||||
|
||||
if (entry?.name) {
|
||||
return `${REPO_URL}/releases/tag/${encodeURIComponent(entry.name)}`;
|
||||
}
|
||||
|
||||
return REPO_URL;
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
return text
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">");
|
||||
}
|
||||
|
||||
function parseInline(text) {
|
||||
let result = escapeHtml(text);
|
||||
result = result.replace(/\*\*\*(.+?)\*\*\*/g, "<strong><em>$1</em></strong>");
|
||||
result = result.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
|
||||
result = result.replace(/\*(.+?)\*/g, "<em>$1</em>");
|
||||
result = result.replace(/`([^`]+)`/g, "<code>$1</code>");
|
||||
result = result.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img alt="$1" src="$2" loading="lazy">');
|
||||
result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noreferrer">$1</a>');
|
||||
return result;
|
||||
}
|
||||
|
||||
function renderMarkdown(md) {
|
||||
if (!md) return "";
|
||||
|
||||
var lines = md.split(/\r?\n/);
|
||||
var html = "";
|
||||
var inCodeBlock = false;
|
||||
var codeBlockContent = "";
|
||||
var codeBlockLang = "";
|
||||
var listBuffer = "";
|
||||
var listKind = "";
|
||||
var tableRows = [];
|
||||
var tableHeader = true;
|
||||
var blockquoteBuffer = "";
|
||||
|
||||
function flushList() {
|
||||
if (listBuffer) {
|
||||
html += "<" + listKind + ">\n" + listBuffer + "</" + listKind + ">\n";
|
||||
listBuffer = "";
|
||||
listKind = "";
|
||||
}
|
||||
}
|
||||
|
||||
function flushTable() {
|
||||
if (tableRows.length) {
|
||||
html += "<table>\n" + tableRows.join("\n") + "\n</table>\n";
|
||||
tableRows = [];
|
||||
tableHeader = true;
|
||||
}
|
||||
}
|
||||
|
||||
function flushBlockquote() {
|
||||
if (blockquoteBuffer) {
|
||||
html += "<blockquote>" + blockquoteBuffer + "</blockquote>\n";
|
||||
blockquoteBuffer = "";
|
||||
}
|
||||
}
|
||||
|
||||
function parseTableCells(line) {
|
||||
var trimmed = line.replace(/^\|/, "").replace(/\|$/, "");
|
||||
return trimmed.split("|").map(function (c) { return c.trim(); });
|
||||
}
|
||||
|
||||
function isTableSep(line) {
|
||||
return /^\|?[\s|:\-]+\|?$/.test(line) && line.indexOf("-") !== -1;
|
||||
}
|
||||
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i];
|
||||
|
||||
if (line.startsWith("```")) {
|
||||
flushBlockquote();
|
||||
flushList();
|
||||
flushTable();
|
||||
if (inCodeBlock) {
|
||||
var langAttr = codeBlockLang ? " class=\"language-" + escapeHtml(codeBlockLang) + "\"" : "";
|
||||
html += "<pre><code" + langAttr + ">" + escapeHtml(codeBlockContent.trim()) + "</code></pre>\n";
|
||||
codeBlockContent = "";
|
||||
codeBlockLang = "";
|
||||
inCodeBlock = false;
|
||||
} else {
|
||||
inCodeBlock = true;
|
||||
codeBlockLang = line.slice(3).trim();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inCodeBlock) {
|
||||
codeBlockContent += (codeBlockContent ? "\n" : "") + line;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.trim() === "") {
|
||||
flushBlockquote();
|
||||
flushList();
|
||||
flushTable();
|
||||
continue;
|
||||
}
|
||||
|
||||
var hMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
||||
if (hMatch) {
|
||||
flushBlockquote();
|
||||
flushList();
|
||||
flushTable();
|
||||
var level = hMatch[1].length;
|
||||
html += "<h" + level + ">" + parseInline(hMatch[2]) + "</h" + level + ">\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/^[-*_]{3,}\s*$/.test(line.trim())) {
|
||||
flushBlockquote();
|
||||
flushList();
|
||||
flushTable();
|
||||
html += "<hr>\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.startsWith("> ") || line.startsWith(">")) {
|
||||
flushList();
|
||||
flushTable();
|
||||
var content = line.replace(/^>\s?/, "");
|
||||
blockquoteBuffer += "<p>" + parseInline(content) + "</p>";
|
||||
continue;
|
||||
} else {
|
||||
flushBlockquote();
|
||||
}
|
||||
|
||||
if (line.includes("|") && !isTableSep(line)) {
|
||||
flushList();
|
||||
var cells = parseTableCells(line);
|
||||
var tag = tableHeader ? "th" : "td";
|
||||
tableRows.push("<tr>" + cells.map(function (c) { return "<" + tag + ">" + parseInline(c) + "</" + tag + ">"; }).join("") + "</tr>");
|
||||
if (tableHeader) tableHeader = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isTableSep(line)) {
|
||||
tableHeader = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.includes("|")) {
|
||||
flushTable();
|
||||
}
|
||||
|
||||
var ulMatch = line.match(/^(\s*)[-*+]\s+(.+)$/);
|
||||
if (ulMatch) {
|
||||
flushTable();
|
||||
if (listKind !== "ul") {
|
||||
flushList();
|
||||
listKind = "ul";
|
||||
}
|
||||
listBuffer += "<li>" + parseInline(ulMatch[2]) + "</li>\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
var olMatch = line.match(/^(\s*)\d+\.\s+(.+)$/);
|
||||
if (olMatch) {
|
||||
flushTable();
|
||||
if (listKind !== "ol") {
|
||||
flushList();
|
||||
listKind = "ol";
|
||||
}
|
||||
listBuffer += "<li>" + parseInline(olMatch[2]) + "</li>\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listBuffer && /^\s{2,}/.test(line)) {
|
||||
listBuffer = listBuffer.replace(/<\/li>\n$/, " " + parseInline(line.trim()) + "</li>\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
flushList();
|
||||
flushTable();
|
||||
html += "<p>" + parseInline(line) + "</p>\n";
|
||||
}
|
||||
|
||||
flushBlockquote();
|
||||
flushList();
|
||||
flushTable();
|
||||
if (inCodeBlock) {
|
||||
var langAttr2 = codeBlockLang ? " class=\"language-" + escapeHtml(codeBlockLang) + "\"" : "";
|
||||
html += "<pre><code" + langAttr2 + ">" + escapeHtml(codeBlockContent.trim()) + "</code></pre>\n";
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function sanitizeRenderedHtml(rawHtml) {
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.innerHTML = rawHtml;
|
||||
|
||||
wrapper.querySelectorAll("script, iframe, object, embed, link, style").forEach(function (node) { node.remove(); });
|
||||
wrapper.querySelectorAll("*").forEach(function (node) {
|
||||
Array.from(node.attributes).forEach(function (attribute) {
|
||||
var name = attribute.name.toLowerCase();
|
||||
var value = attribute.value || "";
|
||||
if (name.startsWith("on")) { node.removeAttribute(attribute.name); return; }
|
||||
if ((name === "href" || name === "src") && /^javascript:/i.test(value)) { node.removeAttribute(attribute.name); }
|
||||
});
|
||||
});
|
||||
|
||||
return wrapper.innerHTML;
|
||||
}
|
||||
|
||||
function truncateHtml(fullHtml) {
|
||||
var temp = document.createElement("div");
|
||||
temp.innerHTML = fullHtml;
|
||||
var text = temp.textContent || "";
|
||||
|
||||
if (text.length <= TRUNCATE_LENGTH) {
|
||||
return { html: fullHtml, truncated: false };
|
||||
}
|
||||
|
||||
var acc = "";
|
||||
var count = 0;
|
||||
var truncatedHtml = "";
|
||||
var children = Array.from(temp.childNodes);
|
||||
|
||||
for (var ci = 0; ci < children.length; ci++) {
|
||||
var child = children[ci];
|
||||
var childText = child.textContent || "";
|
||||
|
||||
if (count + childText.length > TRUNCATE_LENGTH && count > 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (child.nodeType === Node.ELEMENT_NODE) {
|
||||
truncatedHtml += child.outerHTML;
|
||||
} else {
|
||||
var remaining = TRUNCATE_LENGTH - count;
|
||||
if (childText.length > remaining) {
|
||||
truncatedHtml += escapeHtml(childText.slice(0, remaining)) + "…";
|
||||
count = TRUNCATE_LENGTH;
|
||||
break;
|
||||
}
|
||||
truncatedHtml += escapeHtml(childText);
|
||||
}
|
||||
count += childText.length;
|
||||
}
|
||||
|
||||
return { html: truncatedHtml, truncated: true };
|
||||
}
|
||||
|
||||
function setupToggle() {
|
||||
if (!toggleNoteNode || !currentReleaseNoteNode) return;
|
||||
|
||||
toggleNoteNode.addEventListener("click", function () {
|
||||
var expanded = toggleNoteNode.dataset.expanded === "true";
|
||||
if (expanded) {
|
||||
var result = truncateHtml(fullReleaseBodyHtml);
|
||||
currentReleaseNoteNode.innerHTML = result.html;
|
||||
toggleNoteNode.textContent = "Voir plus";
|
||||
toggleNoteNode.dataset.expanded = "false";
|
||||
} else {
|
||||
currentReleaseNoteNode.innerHTML = fullReleaseBodyHtml;
|
||||
toggleNoteNode.textContent = "Voir moins";
|
||||
toggleNoteNode.dataset.expanded = "true";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setupToggle();
|
||||
|
||||
function pickDirectDownloadUrl(release) {
|
||||
const assets = Array.isArray(release?.assets) ? release.assets : [];
|
||||
const isoAsset = assets.find((asset) => /\.iso$/i.test(asset?.name || ""));
|
||||
const directAsset = isoAsset || assets[0];
|
||||
|
||||
if (directAsset) {
|
||||
return directAsset.browser_download_url || release.html_url || REPO_URL;
|
||||
}
|
||||
|
||||
return release?.zipball_url || release?.html_url || REPO_URL;
|
||||
}
|
||||
|
||||
function renderEmptyState(title, message) {
|
||||
if (!versionsListNode) return;
|
||||
versionsListNode.innerHTML = `
|
||||
<li class="version-item version-item-empty">
|
||||
<div class="version-main">
|
||||
<strong>${title}</strong>
|
||||
<span>${message}</span>
|
||||
</div>
|
||||
<div class="version-side">
|
||||
<a class="button button-secondary" href="${REPO_URL}" target="_blank" rel="noreferrer">Voir le repo</a>
|
||||
</div>
|
||||
</li>
|
||||
`;
|
||||
}
|
||||
|
||||
function renderList(items, mode) {
|
||||
if (!versionsListNode) return;
|
||||
versionsListNode.innerHTML = "";
|
||||
|
||||
const visibleItems = items.slice(1, 6);
|
||||
|
||||
if (!visibleItems.length) {
|
||||
if (items.length === 0) {
|
||||
renderEmptyState("Aucune release trouvée", "Le dépôt n'expose pas encore de release ou les releases ne sont pas accessibles.");
|
||||
} else {
|
||||
renderEmptyState(
|
||||
mode === "releases" ? "Aucune release précédente trouvée" : "Aucun tag précédent trouvé",
|
||||
mode === "releases"
|
||||
? "Il n'y a qu'une seule release publiée pour le moment."
|
||||
: "Il n'y a qu'un seul tag disponible pour le moment."
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
visibleItems.forEach((entry) => {
|
||||
const li = document.createElement("li");
|
||||
li.className = "version-item";
|
||||
|
||||
const label = getReleaseLabel(entry);
|
||||
const downloadUrl = getReleasePageUrl(entry, mode);
|
||||
const published = formatDate(entry.published_at || entry.commit?.committer?.date);
|
||||
|
||||
li.innerHTML = `
|
||||
<div class="version-main">
|
||||
<strong>${label}</strong>
|
||||
<span>${published ? `Publié le ${published}` : mode === "releases" ? "Date inconnue" : "Tag GitHub"}</span>
|
||||
</div>
|
||||
<div class="version-side">
|
||||
<a class="button button-secondary" href="${downloadUrl}" target="_blank" rel="noreferrer">Télécharger</a>
|
||||
</div>
|
||||
`;
|
||||
|
||||
versionsListNode.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchJson(url) {
|
||||
const response = await fetch(url, {
|
||||
headers: { Accept: "application/vnd.github+json" },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`GitHub API ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async function loadReleases() {
|
||||
if (currentVersionNode) currentVersionNode.textContent = "Chargement...";
|
||||
if (currentVersionDateNode) currentVersionDateNode.textContent = "";
|
||||
if (currentReleaseNoteNode) currentReleaseNoteNode.textContent = "";
|
||||
if (latestDownloadNode) latestDownloadNode.href = REPO_URL;
|
||||
if (viewMoreNode) viewMoreNode.href = `${REPO_URL}/releases`;
|
||||
|
||||
try {
|
||||
const releases = await fetchJson(RELEASES_URL);
|
||||
|
||||
if (Array.isArray(releases) && releases.length > 0) {
|
||||
const latest = releases[0];
|
||||
const latestLabel = getReleaseLabel(latest);
|
||||
const latestDownloadUrl = pickDirectDownloadUrl(latest);
|
||||
const latestDate = formatDate(latest.published_at);
|
||||
|
||||
if (currentVersionNode) currentVersionNode.textContent = latestLabel;
|
||||
if (currentVersionDateNode) currentVersionDateNode.textContent = latestDate ? ` · ${latestDate}` : "";
|
||||
if (currentReleaseNoteNode) {
|
||||
fullReleaseBodyHtml = sanitizeRenderedHtml(renderMarkdown(latest.body || ""));
|
||||
var result = truncateHtml(fullReleaseBodyHtml);
|
||||
currentReleaseNoteNode.innerHTML = result.html || "<p>Release GitHub la plus récente.</p>";
|
||||
if (toggleNoteNode) {
|
||||
toggleNoteNode.style.display = result.truncated ? "inline-block" : "none";
|
||||
toggleNoteNode.dataset.expanded = "false";
|
||||
toggleNoteNode.textContent = "Voir plus";
|
||||
}
|
||||
}
|
||||
if (latestDownloadNode) latestDownloadNode.href = latestDownloadUrl;
|
||||
|
||||
renderList(releases, "releases");
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur fetch releases:", error.message);
|
||||
// On tente le fallback tags ci-dessous.
|
||||
}
|
||||
|
||||
try {
|
||||
const tags = await fetchJson(TAGS_URL);
|
||||
|
||||
if (Array.isArray(tags) && tags.length > 0) {
|
||||
const latestTag = tags[0];
|
||||
const latestLabel = getReleaseLabel(latestTag);
|
||||
const latestDownloadUrl = `${REPO_URL}/releases/tag/${encodeURIComponent(latestTag.name)}`;
|
||||
|
||||
if (currentVersionNode) currentVersionNode.textContent = `${latestLabel} (tag)`;
|
||||
if (currentVersionDateNode) currentVersionDateNode.textContent = "";
|
||||
if (currentReleaseNoteNode) {
|
||||
currentReleaseNoteNode.textContent = "Aucune release GitHub publiée pour le moment, affichage des tags du dépôt.";
|
||||
}
|
||||
if (latestDownloadNode) latestDownloadNode.href = latestDownloadUrl;
|
||||
|
||||
renderList(tags, "tags");
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentVersionNode) currentVersionNode.textContent = "Aucune release trouvée";
|
||||
if (currentReleaseNoteNode) {
|
||||
currentReleaseNoteNode.textContent = "Le dépôt ne renvoie ni release ni tag public.";
|
||||
}
|
||||
renderEmptyState("Aucune release trouvée", "Le dépôt ne renvoie ni release ni tag public.");
|
||||
} catch (error) {
|
||||
console.error("Erreur fetch tags:", error.message);
|
||||
if (currentVersionNode) currentVersionNode.textContent = "Impossible de charger les releases";
|
||||
if (currentReleaseNoteNode) {
|
||||
currentReleaseNoteNode.textContent = `Erreur: ${error.message}. Vérifie que le repo GitHub est public et qu'il expose des releases ou des tags.`;
|
||||
}
|
||||
renderEmptyState("Impossible de charger les releases", "Ouvre le repo GitHub pour vérifier les releases ou les tags.");
|
||||
}
|
||||
}
|
||||
|
||||
loadReleases();
|
||||
})();
|
||||
@@ -0,0 +1,23 @@
|
||||
(() => {
|
||||
const note = document.querySelector("[data-current-release-note]");
|
||||
const toggle = document.querySelector("[data-toggle-release-note]");
|
||||
if (!note || !toggle) return;
|
||||
|
||||
const fullTemplate = note.querySelector("template[data-note-full]");
|
||||
if (!fullTemplate) return;
|
||||
const fullHtml = fullTemplate.innerHTML;
|
||||
const truncatedHtml = note.innerHTML;
|
||||
|
||||
toggle.addEventListener("click", () => {
|
||||
const expanded = toggle.dataset.expanded === "true";
|
||||
if (expanded) {
|
||||
note.innerHTML = truncatedHtml;
|
||||
toggle.textContent = "Voir plus";
|
||||
toggle.dataset.expanded = "false";
|
||||
} else {
|
||||
note.innerHTML = fullHtml;
|
||||
toggle.textContent = "Voir moins";
|
||||
toggle.dataset.expanded = "true";
|
||||
}
|
||||
});
|
||||
})();
|
||||
@@ -1,487 +0,0 @@
|
||||
(() => {
|
||||
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();
|
||||
}
|
||||
})();
|
||||
@@ -1,222 +0,0 @@
|
||||
(() => {
|
||||
const main = document.getElementById("app-main");
|
||||
const footerYear = document.getElementById("footer-year");
|
||||
const pageStyleSelectors = "[data-page-style='true']";
|
||||
const pageScriptSelectors = "script[data-page-script='true']";
|
||||
|
||||
const links = Array.from(document.querySelectorAll("[data-route]"));
|
||||
|
||||
if (footerYear) {
|
||||
footerYear.textContent = new Date().getFullYear().toString();
|
||||
}
|
||||
|
||||
function clearInjectedPageStyles() {
|
||||
document.querySelectorAll(pageStyleSelectors).forEach((node) => node.remove());
|
||||
}
|
||||
|
||||
function clearInjectedPageScripts() {
|
||||
document.dispatchEvent(new CustomEvent("page:before-route-change"));
|
||||
document.querySelectorAll(pageScriptSelectors).forEach((node) => node.remove());
|
||||
}
|
||||
|
||||
function injectPageStyles(parsedDocument, sourceUrl) {
|
||||
clearInjectedPageStyles();
|
||||
|
||||
const head = parsedDocument.head;
|
||||
if (!head) {
|
||||
return;
|
||||
}
|
||||
|
||||
const styleNodes = Array.from(head.querySelectorAll("link[rel='stylesheet'], style"));
|
||||
|
||||
styleNodes.forEach((node) => {
|
||||
const clonedNode = node.cloneNode(true);
|
||||
clonedNode.setAttribute("data-page-style", "true");
|
||||
|
||||
if (clonedNode.tagName === "LINK") {
|
||||
const href = clonedNode.getAttribute("href");
|
||||
if (href) {
|
||||
clonedNode.href = new URL(href, sourceUrl).toString();
|
||||
}
|
||||
}
|
||||
|
||||
document.head.appendChild(clonedNode);
|
||||
});
|
||||
}
|
||||
|
||||
async function injectPageScripts(parsedDocument, sourceUrl) {
|
||||
clearInjectedPageScripts();
|
||||
|
||||
const scriptNodes = Array.from(parsedDocument.querySelectorAll("script"));
|
||||
|
||||
for (const node of scriptNodes) {
|
||||
const scriptElement = document.createElement("script");
|
||||
scriptElement.setAttribute("data-page-script", "true");
|
||||
|
||||
const src = node.getAttribute("src");
|
||||
if (src) {
|
||||
scriptElement.src = new URL(src, sourceUrl).toString();
|
||||
scriptElement.async = false;
|
||||
if (node.defer) {
|
||||
scriptElement.defer = true;
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
scriptElement.onload = () => resolve();
|
||||
scriptElement.onerror = () => reject(new Error(`Impossible de charger le script: ${src}`));
|
||||
document.body.appendChild(scriptElement);
|
||||
});
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
scriptElement.textContent = node.textContent;
|
||||
document.body.appendChild(scriptElement);
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeRoute(value) {
|
||||
const raw = (value ?? "").toString().trim().toLowerCase();
|
||||
if (!raw || raw === "/" || raw === "home" || raw === "index" || raw === "accueil") {
|
||||
return "index";
|
||||
}
|
||||
return raw.replace(/^\/+|\/+$/g, "") || "index";
|
||||
}
|
||||
|
||||
function routeFromLocation() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
if (params.has("p")) {
|
||||
return normalizeRoute(params.get("p"));
|
||||
}
|
||||
|
||||
const rawSearch = window.location.search.replace(/^\?/, "");
|
||||
if (rawSearch.startsWith("p/")) {
|
||||
return normalizeRoute(rawSearch.slice(2));
|
||||
}
|
||||
|
||||
if (rawSearch.startsWith("p=")) {
|
||||
return normalizeRoute(rawSearch.slice(2));
|
||||
}
|
||||
|
||||
const path = window.location.pathname.replace(/^\/+|\/+$/g, "");
|
||||
if (path) {
|
||||
if (path.endsWith(".html")) {
|
||||
return "index";
|
||||
}
|
||||
|
||||
const parts = path.split("/");
|
||||
if (parts[0] === "p" && parts[1]) {
|
||||
return normalizeRoute(parts.slice(1).join("/"));
|
||||
}
|
||||
return normalizeRoute(parts[0]);
|
||||
}
|
||||
|
||||
return "index";
|
||||
}
|
||||
|
||||
function setActiveRoute(route) {
|
||||
links.forEach((link) => {
|
||||
const isActive = link.dataset.route === route;
|
||||
if (isActive) {
|
||||
link.setAttribute("aria-current", "page");
|
||||
} else {
|
||||
link.removeAttribute("aria-current");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setCanonicalUrl(route, replace = false) {
|
||||
const url = route === "index" ? "/?p/index/" : `/?p/${route}/`;
|
||||
if (replace) {
|
||||
history.replaceState({ route }, "", url);
|
||||
return;
|
||||
}
|
||||
history.pushState({ route }, "", url);
|
||||
}
|
||||
|
||||
function routeToSource(route) {
|
||||
// Les routes « paquets/N » affichent le détail (grand format) du paquet N.
|
||||
if (/^paquets\/\d+$/.test(route)) {
|
||||
return "p/paquets/_detail/index.html";
|
||||
}
|
||||
return `p/${route}/index.html`;
|
||||
}
|
||||
|
||||
function routeToTitle(route) {
|
||||
if (route === "index") {
|
||||
return "Accueil | FWS Linux";
|
||||
}
|
||||
|
||||
const label = route
|
||||
.split("/")
|
||||
.filter(Boolean)
|
||||
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
||||
.join(" / ");
|
||||
|
||||
return `${label} | FWS Linux`;
|
||||
}
|
||||
|
||||
async function loadRoute(route) {
|
||||
clearInjectedPageScripts();
|
||||
|
||||
const source = routeToSource(route);
|
||||
// On laisse le cache HTTP faire son travail (revalidation 304) :
|
||||
// le .htaccess renvoie « Cache-Control: no-cache » sur le HTML,
|
||||
// donc on revalide à chaque navigation sans re-télécharger le corps.
|
||||
const response = await fetch(source);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Impossible de charger ${source} (${response.status})`);
|
||||
}
|
||||
|
||||
const html = await response.text();
|
||||
const parsed = new DOMParser().parseFromString(html, "text/html");
|
||||
injectPageStyles(parsed, response.url);
|
||||
const injected = parsed.querySelector("[data-page-content]") ?? parsed.body;
|
||||
main.innerHTML = injected.innerHTML.trim();
|
||||
await injectPageScripts(parsed, response.url);
|
||||
// Update document title from the fetched page if present, otherwise use generated title
|
||||
const pageTitleEl = parsed.querySelector("title");
|
||||
if (pageTitleEl && pageTitleEl.textContent && pageTitleEl.textContent.trim()) {
|
||||
document.title = pageTitleEl.textContent.trim();
|
||||
} else {
|
||||
document.title = routeToTitle(route);
|
||||
}
|
||||
}
|
||||
|
||||
function render(route, { replaceHistory = false } = {}) {
|
||||
const safeRoute = route || "index";
|
||||
|
||||
loadRoute(safeRoute)
|
||||
.then(() => {
|
||||
setActiveRoute(safeRoute);
|
||||
setCanonicalUrl(safeRoute, replaceHistory);
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
})
|
||||
.catch((error) => {
|
||||
main.innerHTML = `<section class="hero"><h1>Erreur de chargement</h1><p class="lead">${error.message}</p></section>`;
|
||||
setActiveRoute("index");
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", (event) => {
|
||||
const link = event.target.closest("[data-route]");
|
||||
if (!link) {
|
||||
return;
|
||||
}
|
||||
|
||||
const route = normalizeRoute(link.dataset.route);
|
||||
if (!route) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
render(route);
|
||||
});
|
||||
|
||||
window.addEventListener("popstate", () => {
|
||||
render(routeFromLocation(), { replaceHistory: true });
|
||||
});
|
||||
|
||||
render(routeFromLocation(), { replaceHistory: true });
|
||||
})();
|
||||
@@ -0,0 +1,35 @@
|
||||
(() => {
|
||||
/* Menu déroulant « Paquets » de la barre de navigation.
|
||||
Le reste (contenu, données, états actifs) est rendu côté serveur. */
|
||||
const root = document.querySelector("[data-nav-dropdown]");
|
||||
if (!root) return;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
toggle.addEventListener("click", (event) => {
|
||||
event.stopPropagation();
|
||||
setOpen(!root.classList.contains("is-open"));
|
||||
});
|
||||
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!root.contains(event.target)) setOpen(false);
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape" && root.classList.contains("is-open")) {
|
||||
setOpen(false);
|
||||
toggle.focus();
|
||||
}
|
||||
});
|
||||
|
||||
panel.querySelectorAll("a").forEach((link) => {
|
||||
link.addEventListener("click", () => setOpen(false));
|
||||
});
|
||||
})();
|
||||
@@ -460,38 +460,6 @@
|
||||
grid-column: auto;
|
||||
}
|
||||
|
||||
.paquet-detail-nav {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
|
||||
.paquet-detail-nav a {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
font-size: 0.95rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.5rem;
|
||||
background: var(--surface);
|
||||
transition: color 160ms ease, background 160ms ease;
|
||||
}
|
||||
|
||||
.paquet-detail-nav a:hover {
|
||||
color: var(--accent-strong);
|
||||
background: var(--accent-bg);
|
||||
}
|
||||
|
||||
.paquet-detail-prev {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.paquet-detail-next {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
/* ── Responsive ── */
|
||||
|
||||
@media (max-width: 700px) {
|
||||
|
||||
Reference in new issue
Block a user