542323ceaa
Le site était bien déployé mais tous les chemins absolus (CSS/JS bundlés par Vite, polices, favicon, manifest, service worker, liens de nav/footer) pointaient vers la racine du domaine (/assets/..., /favicon.svg, /, /en/…) au lieu de /gwada-sirius/... — GitHub Pages sert un site de projet sous /<nom-du-repo>/, pas à la racine. Résultat : CSS et polices en 404, liens de navigation cassés. Ajoute une variable d'env BASE_PATH (vide par défaut, /gwada-sirius en CI via .github/workflows/deploy.yml) : passée à viteOptions.base pour que Vite préfixe lui-même les assets qu'il bundle, et à un filtre maison withBase/localeHref pour les liens de nav, favicon, manifest et l'enregistrement du service worker. Le manifest PWA passe en chemins relatifs pour ne pas avoir besoin d'être templaté. Vérifié en simulant un vrai déploiement (build préfixé servi depuis un sous-dossier /gwada-sirius/ d'un serveur statique) : plus aucune requête 404, navigation, service worker (scope correctement limité au sous-chemin) et carte Leaflet fonctionnels de bout en bout. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
113 lines
3.7 KiB
JavaScript
113 lines
3.7 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import EleventyVitePlugin from "@11ty/eleventy-plugin-vite";
|
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
import * as m from "./src/paraglide/messages.js";
|
|
import { locales, baseLocale } from "./src/paraglide/runtime.js";
|
|
|
|
const OUTPUT_DIR = "_site";
|
|
|
|
// GitHub Pages project sites are served under /<repo-name>/, not at the
|
|
// domain root — set BASE_PATH (no trailing slash, e.g. "/gwada-sirius")
|
|
// in CI to prefix internal links and Vite's own asset URLs accordingly.
|
|
// Left empty for local dev and for a future custom-domain deployment.
|
|
const BASE_PATH = (process.env.BASE_PATH || "").replace(/\/+$/, "");
|
|
|
|
// Vite's build wipes the output dir (emptyOutDir) after 11ty has already
|
|
// copied passthrough assets into it — re-copy them once Vite is done.
|
|
// https://github.com/11ty/eleventy-plugin-vite/issues/42
|
|
function restorePassthroughCopy(copies) {
|
|
return {
|
|
name: "restore-passthrough-copy",
|
|
apply: "build",
|
|
closeBundle() {
|
|
for (const [from, to] of copies) {
|
|
if (!fs.existsSync(from)) continue;
|
|
fs.cpSync(from, path.join(OUTPUT_DIR, to), {
|
|
recursive: true,
|
|
force: true,
|
|
});
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
export default function (eleventyConfig) {
|
|
eleventyConfig.addPlugin(EleventyVitePlugin, {
|
|
viteOptions: {
|
|
appType: "mpa",
|
|
plugins: [
|
|
svelte(),
|
|
restorePassthroughCopy([
|
|
["src/assets", "assets"],
|
|
["public", "."],
|
|
]),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
"/src": path.resolve(".", "src"),
|
|
},
|
|
},
|
|
base: BASE_PATH ? `${BASE_PATH}/` : "/",
|
|
build: {
|
|
emptyOutDir: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
eleventyConfig.ignores.add("src/paraglide/**");
|
|
eleventyConfig.ignores.add("src/islands/**");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/assets");
|
|
eleventyConfig.addPassthroughCopy({ public: "." });
|
|
|
|
// Trilingual message lookup for Nunjucks templates: {{ "hero_title1" | t(locale) }}
|
|
eleventyConfig.addFilter("t", (key, locale, params = {}) => {
|
|
const fn = m[key];
|
|
if (!fn) return key;
|
|
return fn(params, { locale });
|
|
});
|
|
|
|
eleventyConfig.addGlobalData("locales", locales);
|
|
eleventyConfig.addGlobalData("baseLocale", baseLocale);
|
|
eleventyConfig.addGlobalData("currentYear", () => new Date().getFullYear());
|
|
|
|
eleventyConfig.addGlobalData("basePath", BASE_PATH);
|
|
|
|
eleventyConfig.addFilter("localeHref", (pagePath, locale) => {
|
|
const clean = pagePath.replace(/^\/+/, "");
|
|
const localePath = locale === baseLocale ? `/${clean}` : `/${locale}/${clean}`;
|
|
return BASE_PATH + localePath;
|
|
});
|
|
|
|
// For static/passthrough assets referenced by absolute path outside of
|
|
// Vite's own bundling (favicon, manifest, service worker, font preloads —
|
|
// anything marked vite-ignore in layouts/base.njk).
|
|
eleventyConfig.addFilter("withBase", (assetPath) => BASE_PATH + assetPath);
|
|
|
|
eleventyConfig.addFilter("dump", (value) => JSON.stringify(value).replace(/</g, "\\u003c"));
|
|
|
|
eleventyConfig.addFilter("formatDate", (isoDate, locale, options = {}) => {
|
|
// new Date("YYYY-MM-DD") parses as UTC midnight, which can roll back a
|
|
// day once formatted in a timezone behind UTC (e.g. Guadeloupe, UTC-4).
|
|
// Build the date from its local components instead.
|
|
const [year, month, day] = isoDate.split("-").map(Number);
|
|
return new Date(year, month - 1, day).toLocaleDateString(
|
|
locale === "ht" ? "fr" : locale,
|
|
{ day: "numeric", month: "long", year: "numeric", ...options }
|
|
);
|
|
});
|
|
|
|
return {
|
|
dir: {
|
|
input: "src",
|
|
output: OUTPUT_DIR,
|
|
includes: "_includes",
|
|
data: "_data",
|
|
},
|
|
templateFormats: ["njk", "md"],
|
|
markdownTemplateEngine: "njk",
|
|
htmlTemplateEngine: "njk",
|
|
};
|
|
}
|