🐛 Fix: Corrige le déploiement GitHub Pages (chemins sous /gwada-sirius/)
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>
This commit is contained in:
+16
-1
@@ -7,6 +7,12 @@ 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
|
||||
@@ -42,6 +48,7 @@ export default function (eleventyConfig) {
|
||||
"/src": path.resolve(".", "src"),
|
||||
},
|
||||
},
|
||||
base: BASE_PATH ? `${BASE_PATH}/` : "/",
|
||||
build: {
|
||||
emptyOutDir: false,
|
||||
},
|
||||
@@ -65,11 +72,19 @@ export default function (eleventyConfig) {
|
||||
eleventyConfig.addGlobalData("baseLocale", baseLocale);
|
||||
eleventyConfig.addGlobalData("currentYear", () => new Date().getFullYear());
|
||||
|
||||
eleventyConfig.addGlobalData("basePath", BASE_PATH);
|
||||
|
||||
eleventyConfig.addFilter("localeHref", (pagePath, locale) => {
|
||||
const clean = pagePath.replace(/^\/+/, "");
|
||||
return locale === baseLocale ? `/${clean}` : `/${locale}/${clean}`;
|
||||
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 = {}) => {
|
||||
|
||||
Reference in New Issue
Block a user