refactor: use import.meta to resolve assets (Take 2)

suppression-manon-adrien
Sebastien Arod 2024-06-07 14:21:06 +02:00
parent c06b3947ce
commit 53331c5ccd
8 changed files with 41 additions and 139 deletions

View File

@ -1,19 +1,17 @@
import "mapbox-gl/dist/mapbox-gl.css";
import React from "react";
import { RouterProvider } from "react-router-dom";
import { ViewMode } from "./routes/ViewMode";
import { DisplayModeContext } from "./context/DisplayModeContext";
import { HomeContext } from "./context/HomeContext";
import { router } from "./router";
import "mapbox-gl/dist/mapbox-gl.css";
import "./style/SquareSpace/vars.css";
import "./style/SquareSpace/global.css";
import { ViewMode } from "./routes/ViewMode";
import "./style/SquareSpace/blocks.css";
import "./style/SquareSpace/global.css";
import "./style/SquareSpace/table.css";
import "./style/SquareSpace/vars.css";
import "./style/SquareSpace/video.css";
import "./style/thumbs.css";
import "./style/row.css";
import "./photos";
import "./declarations";
import "./style/thumbs.css";
interface Props {
defaultViewMode: ViewMode;

View File

@ -1,50 +0,0 @@
import "./alexandre-julie.pdf";
import "./andrea-gherard.pdf";
import "./andrea-jerome.pdf";
import "./angelique-jonathan.pdf";
import "./anne-laure-damien.pdf";
import "./anne-lise-marc.pdf";
import "./arnaud-pauline.pdf";
import "./audrey-jeremie.pdf";
import "./benedicte-yves.pdf";
import "./bertrand-angelique.pdf";
import "./caroline-gael.pdf";
import "./caroline-maxime-gregory.pdf";
import "./cecile-jordan.pdf";
import "./celine-fabrice.pdf";
import "./elodie-mathieu.pdf";
import "./emeline-sebastien.pdf";
import "./fleur-gael.pdf";
import "./florence-pierre-alexandre.pdf";
import "./guilhem-eglantine.pdf";
import "./helene-volodia.pdf";
import "./isabelle-julio.pdf";
import "./jenny-thierry.pdf";
import "./julia-dawy.pdf";
import "./laure-labadie.pdf";
import "./lea-frederic.pdf";
import "./lola-morgan.pdf";
import "./louise-lionel.pdf";
import "./lourenco-porcel.pdf";
import "./manon-adrien.pdf";
import "./marie-alexis.pdf";
import "./marie-julien.pdf";
import "./marie-matthieu.pdf";
import "./marina-romain.pdf";
import "./marion-quentin.pdf";
import "./mathilde-thomas.pdf";
import "./maylis-benoit.pdf";
import "./olivia-pascoal.pdf";
import "./perrina-benjamin.pdf";
import "./perrine-francois.pdf";
import "./philomene-mathieu.pdf";
import "./rachel-bastien.pdf";
import "./samuel-laurence.pdf";
import "./sebastien-marie.pdf";
import "./stephanie-david.pdf";
import "./sultane-mehmet.pdf";
import "./valene-emilien.pdf";
import "./virginie-eric.pdf";
import "./virginie-gaetan.pdf";
import "./virginie-mikael.pdf";
import "./virginie-yves.pdf";

View File

@ -0,0 +1,4 @@
export const getPortableAssetAbsoluteUrl = (assetUrl: string): string => {
const moduleUrl = import.meta.url;
return new URL(assetUrl, moduleUrl).toString();
};

View File

@ -1,2 +1,14 @@
export const getResistantDeclarationUrl = (resistantId: string) =>
`https://enfance-libre.frama.io/resistants/assets/${resistantId}.pdf`;
import { getPortableAssetAbsoluteUrl } from "./getPortableAssetAbsoluteUrl";
const declarationUrls = import.meta.glob("./declarations/*.pdf", {
query: "?url",
eager: true,
import: "default",
});
export const getResistantDeclarationUrl = (resistantId: string): string => {
const declarationUrl = declarationUrls[
`./declarations/${resistantId}.pdf`
] as string;
return getPortableAssetAbsoluteUrl(declarationUrl);
};

View File

@ -1,4 +1,13 @@
import { Resistant } from "./Resistant";
import { getPortableAssetAbsoluteUrl } from "./getPortableAssetAbsoluteUrl";
export const getResistantPhotoUrl = (resistant: Resistant) =>
`https://enfance-libre.frama.io/resistants/assets/${resistant.id}.jpg`;
const photoUrls = import.meta.glob("./photos/*.jpg", {
query: "?url",
eager: true,
import: "default",
});
export const getResistantPhotoUrl = (resistant: Resistant): string => {
const photoUrl = photoUrls[`./photos/${resistant.id}.jpg`] as string;
return getPortableAssetAbsoluteUrl(photoUrl);
};

View File

@ -1,76 +0,0 @@
import "./alexandre-julie.jpg";
import "./amelie-vincent.jpg";
import "./andrea-gherard.jpg";
import "./andrea-jerome.jpg";
import "./angelique-jonathan.jpg";
import "./anne-laure-damien.jpg";
import "./anne-lise-marc.jpg";
import "./arnaud-pauline.jpg";
import "./audrey-jeremie.jpg";
import "./audreyanne-michael.jpg";
import "./benedicte-yves.jpg";
import "./bertrand-angelique.jpg";
import "./caroline-gael.jpg";
import "./caroline-maxime-gregory.jpg";
import "./cecile-jordan.jpg";
import "./celine-fabrice.jpg";
import "./david-coralie.jpg";
import "./deborah-florian.jpg";
import "./elodie-mathieu.jpg";
import "./emeline-sebastien.jpg";
import "./emmanuelle-philippe.jpg";
import "./fleur-gael.jpg";
import "./florence-alexis.jpg";
import "./florence-pierre-alexandre.jpg";
import "./guilhem-eglantine.jpg";
import "./helene-d.jpg";
import "./helene-f.jpg";
import "./helene-volodia.jpg";
import "./isabelle-julio.jpg";
import "./isabelle-nicolas.jpg";
import "./jenny-thierry.jpg";
import "./jerome-gwenaelle.jpg";
import "./jonathan-caroline.jpg";
import "./julia-dawy.jpg";
import "./julie-jeanchristophe.jpg";
import "./karene-jalil.jpg";
import "./laure-labadie.jpg";
import "./lea-frederic.jpg";
import "./lola-morgan.jpg";
import "./louise-lionel.jpg";
import "./manon-adrien.jpg";
import "./marianne-denis.jpg";
import "./marie-alexis.jpg";
import "./marie-julien.jpg";
import "./marie-matthieu.jpg";
import "./marina-frederic.jpg";
import "./marina-romain.jpg";
import "./marion-quentin.jpg";
import "./marlene-benjamin.jpg";
import "./mathilde-cyril.jpg";
import "./mathilde-dorian.jpg";
import "./mathilde-thomas.jpg";
import "./maylis-benoit.jpg";
import "./myriam-timothee.jpg";
import "./nicolas-elodie.jpg";
import "./olivia-pascoal.jpg";
import "./ophelie-sylvain.jpg";
import "./perrina-benjamin.jpg";
import "./perrine-francois.jpg";
import "./philomene-mathieu.jpg";
import "./rachel-bastien.jpg";
import "./ramin-marjorie.jpg";
import "./roseline-jonathan.jpg";
import "./samuel-laurence.jpg";
import "./sarah-jerome.jpg";
import "./sebastien-marie.jpg";
import "./sita-pascal.jpg";
import "./sonia-jeanchristophe.jpg";
import "./stephanie-david.jpg";
import "./sultane-mehmet.jpg";
import "./sylvaine-olivier.jpg";
import "./valene-emilien.jpg";
import "./virginie-eric.jpg";
import "./virginie-gaetan.jpg";
import "./virginie-mikael.jpg";
import "./virginie-yves.jpg";

View File

@ -14,7 +14,10 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"types": [
"vite/client" // Needed for import.meta.glob
]
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]

View File

@ -1,9 +1,11 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
// Resistants module is deployed in framagit under /resistants
base: "/resistants",
build: {
rollupOptions: {
output: {