diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5a042e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.freebuff/ +gestionnaire/ diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..e1d2560 --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +Options +Indexes diff --git a/p/assets/js/downloads.js b/p/assets/js/downloads.js index 0559bdb..c8b542a 100644 --- a/p/assets/js/downloads.js +++ b/p/assets/js/downloads.js @@ -1,8 +1,8 @@ (() => { const OWNER = "You-re-like-Windows-a-bitch"; const REPO = "ISO"; - const RELEASES_URL = `https://api.github.com/repos/${OWNER}/${REPO}/releases?per_page=6`; - const TAGS_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=6`; + 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]"); @@ -11,6 +11,10 @@ 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 ""; @@ -29,7 +33,7 @@ function getReleasePageUrl(entry, mode) { if (mode === "releases") { - return entry?.html_url || REPO_URL; + return pickDirectDownloadUrl(entry); } if (entry?.name) { @@ -39,37 +43,274 @@ return REPO_URL; } - function sanitizeReleaseHtml(html) { + function escapeHtml(text) { + return text + .replace(/&/g, "&") + .replace(//g, ">"); + } + + function parseInline(text) { + let result = escapeHtml(text); + result = result.replace(/\*\*\*(.+?)\*\*\*/g, "$1"); + result = result.replace(/\*\*(.+?)\*\*/g, "$1"); + result = result.replace(/\*(.+?)\*/g, "$1"); + result = result.replace(/`([^`]+)`/g, "$1"); + result = result.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '$1'); + result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); + 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 + "\n"; + listBuffer = ""; + listKind = ""; + } + } + + function flushTable() { + if (tableRows.length) { + html += "\n" + tableRows.join("\n") + "\n
\n"; + tableRows = []; + tableHeader = true; + } + } + + function flushBlockquote() { + if (blockquoteBuffer) { + html += "
" + blockquoteBuffer + "
\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 += "
" + escapeHtml(codeBlockContent.trim()) + "
\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 += "" + parseInline(hMatch[2]) + "\n"; + continue; + } + + if (/^[-*_]{3,}\s*$/.test(line.trim())) { + flushBlockquote(); + flushList(); + flushTable(); + html += "
\n"; + continue; + } + + if (line.startsWith("> ") || line.startsWith(">")) { + flushList(); + flushTable(); + var content = line.replace(/^>\s?/, ""); + blockquoteBuffer += "

" + parseInline(content) + "

"; + continue; + } else { + flushBlockquote(); + } + + if (line.includes("|") && !isTableSep(line)) { + flushList(); + var cells = parseTableCells(line); + var tag = tableHeader ? "th" : "td"; + tableRows.push("" + cells.map(function (c) { return "<" + tag + ">" + parseInline(c) + ""; }).join("") + ""); + 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 += "
  • " + parseInline(ulMatch[2]) + "
  • \n"; + continue; + } + + var olMatch = line.match(/^(\s*)\d+\.\s+(.+)$/); + if (olMatch) { + flushTable(); + if (listKind !== "ol") { + flushList(); + listKind = "ol"; + } + listBuffer += "
  • " + parseInline(olMatch[2]) + "
  • \n"; + continue; + } + + if (listBuffer && /^\s{2,}/.test(line)) { + listBuffer = listBuffer.replace(/<\/li>\n$/, " " + parseInline(line.trim()) + "\n"); + continue; + } + + flushList(); + flushTable(); + html += "

    " + parseInline(line) + "

    \n"; + } + + flushBlockquote(); + flushList(); + flushTable(); + if (inCodeBlock) { + var langAttr2 = codeBlockLang ? " class=\"language-" + escapeHtml(codeBlockLang) + "\"" : ""; + html += "
    " + escapeHtml(codeBlockContent.trim()) + "
    \n"; + } + + return html; + } + + function sanitizeRenderedHtml(rawHtml) { const wrapper = document.createElement("div"); - wrapper.innerHTML = html || ""; + wrapper.innerHTML = rawHtml; - wrapper.querySelectorAll("script, iframe, object, embed, link, style").forEach((node) => node.remove()); - wrapper.querySelectorAll("*").forEach((node) => { - Array.from(node.attributes).forEach((attribute) => { - const name = attribute.name.toLowerCase(); - const 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); - } + 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 || directAsset.url || release.html_url || REPO_URL; + return directAsset.browser_download_url || release.html_url || REPO_URL; } return release?.zipball_url || release?.html_url || REPO_URL; @@ -163,15 +404,22 @@ if (currentVersionNode) currentVersionNode.textContent = latestLabel; if (currentVersionDateNode) currentVersionDateNode.textContent = latestDate ? ` · ${latestDate}` : ""; if (currentReleaseNoteNode) { - const bodyHtml = sanitizeReleaseHtml(latest.body || ""); - currentReleaseNoteNode.innerHTML = bodyHtml || "Release GitHub la plus récente."; + fullReleaseBodyHtml = sanitizeRenderedHtml(renderMarkdown(latest.body || "")); + var result = truncateHtml(fullReleaseBodyHtml); + currentReleaseNoteNode.innerHTML = result.html || "

    Release GitHub la plus récente.

    "; + if (toggleNoteNode) { + toggleNoteNode.style.display = result.truncated ? "inline-block" : "none"; + toggleNoteNode.dataset.expanded = "false"; + toggleNoteNode.textContent = "Voir plus"; + } } - if (latestDownloadNode) latestDownloadNode.href = latest.html_url || REPO_URL; + 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. } @@ -200,6 +448,7 @@ } 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.`; diff --git a/p/assets/styles/downloads.css b/p/assets/styles/downloads.css index 849942c..1ec2914 100644 --- a/p/assets/styles/downloads.css +++ b/p/assets/styles/downloads.css @@ -32,6 +32,100 @@ margin: 0.85rem 0 0; color: var(--muted); line-height: 1.6; + max-height: none; + overflow: visible; +} + +.latest-note h1, +.latest-note h2, +.latest-note h3, +.latest-note h4 { + color: #e2e8f0; + margin: 1.2rem 0 0.5rem; +} + +.latest-note h2 { + font-size: 1.2rem; +} + +.latest-note h3 { + font-size: 1.05rem; +} + +.latest-note p { + margin: 0.5rem 0; +} + +.latest-note ul, +.latest-note ol { + margin: 0.4rem 0; + padding-left: 1.4rem; +} + +.latest-note li { + margin: 0.25rem 0; +} + +.latest-note table { + width: 100%; + border-collapse: collapse; + margin: 0.75rem 0; + font-size: 0.92rem; +} + +.latest-note th, +.latest-note td { + padding: 0.45rem 0.65rem; + border: 1px solid rgba(148, 163, 184, 0.18); + text-align: left; +} + +.latest-note th { + background: rgba(148, 163, 184, 0.08); + font-weight: 600; + color: #cbd5e1; +} + +.latest-note blockquote { + margin: 0.6rem 0; + padding: 0.5rem 0.9rem; + border-left: 3px solid #7dd3fc; + background: rgba(125, 211, 252, 0.06); + border-radius: 0 0.4rem 0.4rem 0; + color: #b0bec5; +} + +.latest-note blockquote p { + margin: 0; +} + +.latest-note code { + background: rgba(148, 163, 184, 0.12); + padding: 0.15em 0.4em; + border-radius: 0.3rem; + font-size: 0.9em; + font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; +} + +.latest-note pre { + background: rgba(2, 6, 23, 0.5); + border: 1px solid rgba(148, 163, 184, 0.12); + border-radius: 0.5rem; + padding: 0.8rem 1rem; + overflow-x: auto; + margin: 0.6rem 0; +} + +.latest-note pre code { + background: none; + padding: 0; + font-size: 0.88rem; +} + +.latest-note hr { + border: none; + border-top: 1px solid rgba(148, 163, 184, 0.15); + margin: 1rem 0; } .latest-note img { @@ -51,6 +145,23 @@ text-decoration: underline; } +.toggle-note { + display: inline-block; + margin-top: 0.5rem; + padding: 0.35rem 0.9rem; + font-size: 0.88rem; + background: rgba(125, 211, 252, 0.08); + color: #7dd3fc; + border: 1px solid rgba(125, 211, 252, 0.2); + border-radius: 0.4rem; + cursor: pointer; + transition: background 0.2s; +} + +.toggle-note:hover { + background: rgba(125, 211, 252, 0.16); +} + .versions-archive { margin-top: 1rem; } diff --git a/p/dl/index.html b/p/dl/index.html index b895133..693679a 100644 --- a/p/dl/index.html +++ b/p/dl/index.html @@ -25,11 +25,12 @@ Télécharger -

    +
    +
    -

    5 versions précédentes

    +

    Versions précédentes