diff --git a/site/.gitignore b/site/.gitignore index 6c4ac34b7..f0c04bf77 100644 --- a/site/.gitignore +++ b/site/.gitignore @@ -5,3 +5,4 @@ cypress/videos cypress/screenshots cypress/downloads .deps.json +source/public/sitemap.*.txt \ No newline at end of file diff --git a/site/package.json b/site/package.json index 6c4b27d7b..1c4e903c0 100644 --- a/site/package.json +++ b/site/package.json @@ -22,11 +22,12 @@ "build:yaml-to-dts": "ts-node-esm scripts/build-yaml-to-dts.ts", "postinstall": "node scripts/prepare.js", "start": "vite dev", - "build": "NODE_OPTIONS='--max-old-space-size=6144'; vite build && yarn build:iframe-script", + "build": "NODE_OPTIONS='--max-old-space-size=6144'; yarn build:sitemap && vite build && yarn build:iframe-script", "build:ssr": "NODE_OPTIONS='--max-old-space-size=4096'; vite build --ssr ./source/entry-server.tsx --outDir ./dist/server --emptyOutDir && echo '{\"module\": \"commonjs\"}' > dist/package.json", "build:prerender": "node prerender.cjs", "build:iframe-script": "NODE_OPTIONS='--max-old-space-size=4096'; vite build --config vite-iframe-script.config.ts", "build:preview": "VITE_FR_BASE_URL=http://localhost:8888; VITE_EN_BASE_URL=http://localhost:8889; yarn build && yarn build:ssr && yarn build:prerender", + "build:sitemap": "ts-node-esm scripts/build-sitemap.ts", "preview:mon-entreprise": "sed 's|:SITE_FR||g' netlify.toml | sed 's|:API_URL|http://localhost:3004|g' > dist/netlify.toml && cd dist && npx netlify-cli dev -d ./ -p 8888", "preview:infrance": "sed 's|:SITE_EN||g' | sed 's|:API_URL|http://localhost:3004|g' netlify.toml > dist/netlify.toml && cd dist && npx netlify-cli dev -d ./ -p 8889", "typecheck:watch": "tsc --skipLibCheck --noEmit --watch", diff --git a/site/scripts/build-sitemap.ts b/site/scripts/build-sitemap.ts new file mode 100644 index 000000000..f5ef372ab --- /dev/null +++ b/site/scripts/build-sitemap.ts @@ -0,0 +1,24 @@ +import { writeFileSync } from 'node:fs' +import { + constructLocalizedSitePath, + generateSiteMap, +} from '../source/sitePaths.js' + +const basePathEn = + process.env.VITE_EN_BASE_URL ?? 'http://localhost:3000/infrance' +const basePathFr = + process.env.VITE_FR_BASE_URL ?? 'http://localhost:3000/mon-entreprise' + +const enSiteMap = generateSiteMap(constructLocalizedSitePath('en')).map( + (path) => basePathEn + path +) +const frSiteMap = generateSiteMap(constructLocalizedSitePath('fr')).map( + (path) => basePathFr + path +) + +writeFileSync('source/public/sitemap.en.txt', enSiteMap.join('\n') + '\n', { + encoding: 'utf8', +}) +writeFileSync('source/public/sitemap.fr.txt', frSiteMap.join('\n') + '\n', { + encoding: 'utf8', +}) diff --git a/site/source/App.tsx b/site/source/App.tsx index 3c3c49068..e17affea5 100644 --- a/site/source/App.tsx +++ b/site/source/App.tsx @@ -27,7 +27,6 @@ import Budget from './pages/Budget/Budget' import Créer from './pages/Creer' import IntegrationTest from './pages/Dev/IntegrationTest' import Personas from './pages/Dev/Personas' -import Sitemap from './pages/Dev/Sitemap' import Documentation from './pages/Documentation' import Gérer from './pages/gerer' import Iframes from './pages/Iframes' @@ -136,7 +135,6 @@ const App = () => { - -

Sitemap

-
-				{generateSiteMap(sitePaths).map((path) => (
-					
-						{path}
-						
-
- ))} -
- - ) -} diff --git a/site/source/public/sitemap.en.txt b/site/source/public/sitemap.en.txt deleted file mode 100644 index 48db8871e..000000000 --- a/site/source/public/sitemap.en.txt +++ /dev/null @@ -1,42 +0,0 @@ -https://mycompanyinfrance.urssaf.fr -https://mycompanyinfrance.urssaf.fr/create -https://mycompanyinfrance.urssaf.fr/create/EI -https://mycompanyinfrance.urssaf.fr/create/EIRL -https://mycompanyinfrance.urssaf.fr/create/EURL -https://mycompanyinfrance.urssaf.fr/create/SAS -https://mycompanyinfrance.urssaf.fr/create/SARL -https://mycompanyinfrance.urssaf.fr/create/SASU -https://mycompanyinfrance.urssaf.fr/create/auto-entrepreneur -https://mycompanyinfrance.urssaf.fr/create/auto-entrepreneur-EIRL -https://mycompanyinfrance.urssaf.fr/create/SA -https://mycompanyinfrance.urssaf.fr/create/after-registration -https://mycompanyinfrance.urssaf.fr/create/legal-status -https://mycompanyinfrance.urssaf.fr/create/legal-status/list -https://mycompanyinfrance.urssaf.fr/create/legal-status/liability -https://mycompanyinfrance.urssaf.fr/create/legal-status/director -https://mycompanyinfrance.urssaf.fr/create/legal-status/auto-entrepreneur -https://mycompanyinfrance.urssaf.fr/create/legal-status/multiple-associates -https://mycompanyinfrance.urssaf.fr/create/legal-status/chairman-or-managing-director -https://mycompanyinfrance.urssaf.fr/manage -https://mycompanyinfrance.urssaf.fr/manage/hiring -https://mycompanyinfrance.urssaf.fr/manage/social-security -https://mycompanyinfrance.urssaf.fr/manage/declaration-aid-independent -https://mycompanyinfrance.urssaf.fr/calculators -https://mycompanyinfrance.urssaf.fr/calculators/sasu-chairman -https://mycompanyinfrance.urssaf.fr/calculators/independant -https://mycompanyinfrance.urssaf.fr/calculators/auto-entrepreneur -https://mycompanyinfrance.urssaf.fr/calculators/social-scheme-comparaison -https://mycompanyinfrance.urssaf.fr/calculators/salary -https://mycompanyinfrance.urssaf.fr/calculators/artist-author -https://mycompanyinfrance.urssaf.fr/calculators/partial-unemployement -https://mycompanyinfrance.urssaf.fr/calculators/liberal-profession -https://mycompanyinfrance.urssaf.fr/calculators/liberal-profession/doctor -https://mycompanyinfrance.urssaf.fr/calculators/liberal-profession/medical-auxiliary -https://mycompanyinfrance.urssaf.fr/calculators/liberal-profession/dental-surgeon -https://mycompanyinfrance.urssaf.fr/calculators/liberal-profession/midwife -https://mycompanyinfrance.urssaf.fr/calculators/sharing-economy -https://mycompanyinfrance.urssaf.fr/calculators/sharing-economy/your-situation -https://mycompanyinfrance.urssaf.fr/integration -https://mycompanyinfrance.urssaf.fr/integration/iframe -https://mycompanyinfrance.urssaf.fr/integration/library -https://mycompanyinfrance.urssaf.fr/documentation diff --git a/site/source/public/sitemap.fr.txt b/site/source/public/sitemap.fr.txt deleted file mode 100644 index 4f9f0e5ec..000000000 --- a/site/source/public/sitemap.fr.txt +++ /dev/null @@ -1,46 +0,0 @@ -https://mon-entreprise.urssaf.fr/créer -https://mon-entreprise.urssaf.fr/créer/EI -https://mon-entreprise.urssaf.fr/créer/EIRL -https://mon-entreprise.urssaf.fr/créer/EURL -https://mon-entreprise.urssaf.fr/créer/SAS -https://mon-entreprise.urssaf.fr/créer/SARL -https://mon-entreprise.urssaf.fr/créer/SASU -https://mon-entreprise.urssaf.fr/créer/auto-entrepreneur -https://mon-entreprise.urssaf.fr/créer/auto-entrepreneur-EIRL -https://mon-entreprise.urssaf.fr/créer/SA -https://mon-entreprise.urssaf.fr/créer/après-la-création -https://mon-entreprise.urssaf.fr/créer/statut-juridique -https://mon-entreprise.urssaf.fr/créer/statut-juridique/liste -https://mon-entreprise.urssaf.fr/créer/statut-juridique/responsabilité -https://mon-entreprise.urssaf.fr/créer/statut-juridique/dirigeant -https://mon-entreprise.urssaf.fr/créer/statut-juridique/auto-entrepreneur-ou-entreprise-individuelle -https://mon-entreprise.urssaf.fr/créer/statut-juridique/nombre-associés -https://mon-entreprise.urssaf.fr/créer/statut-juridique/gérant-majoritaire-ou-minoritaire -https://mon-entreprise.urssaf.fr/gérer -https://mon-entreprise.urssaf.fr/gérer/embaucher -https://mon-entreprise.urssaf.fr/gérer/sécurité-sociale -https://mon-entreprise.urssaf.fr/gérer/aide-declaration-independants -https://mon-entreprise.urssaf.fr/gérer/demande-mobilité -https://mon-entreprise.urssaf.fr/simulateurs -https://mon-entreprise.urssaf.fr/simulateurs/dirigeant-sasu -https://mon-entreprise.urssaf.fr/simulateurs/indépendant -https://mon-entreprise.urssaf.fr/simulateurs/auto-entrepreneur -https://mon-entreprise.urssaf.fr/simulateurs/comparaison-régimes-sociaux -https://mon-entreprise.urssaf.fr/simulateurs/salaire-brut-net -https://mon-entreprise.urssaf.fr/simulateurs/artiste-auteur -https://mon-entreprise.urssaf.fr/simulateurs/profession-liberale -https://mon-entreprise.urssaf.fr/simulateurs/profession-liberale/medecin -https://mon-entreprise.urssaf.fr/simulateurs/profession-liberale/auxiliaire-medical -https://mon-entreprise.urssaf.fr/simulateurs/profession-liberale/chirurgien-dentiste -https://mon-entreprise.urssaf.fr/simulateurs/profession-liberale/sage-femme -https://mon-entreprise.urssaf.fr/simulateurs/chômage-partiel -https://mon-entreprise.urssaf.fr/simulateurs/économie-collaborative -https://mon-entreprise.urssaf.fr/simulateurs/économie-collaborative/votre-situation -https://mon-entreprise.urssaf.fr/nouveautés -https://mon-entreprise.urssaf.fr/stats -https://mon-entreprise.urssaf.fr/budget -https://mon-entreprise.urssaf.fr/intégration -https://mon-entreprise.urssaf.fr/intégration/iframe -https://mon-entreprise.urssaf.fr/intégration/bibliothèque-de-calcul -https://mon-entreprise.urssaf.fr/documentation - diff --git a/site/source/sitePaths.ts b/site/source/sitePaths.ts index df41a564a..d5f59349d 100644 --- a/site/source/sitePaths.ts +++ b/site/source/sitePaths.ts @@ -236,7 +236,13 @@ export const constructLocalizedSitePath = (language: 'en' | 'fr') => { export type SitePathsType = ReturnType -const deepReduce = (fn: any, initialValue?: any, object?: any): any => +type Obj = { [k: string]: string | Obj } + +const deepReduce = ( + fn: (acc: string[], val: string, key: string) => string[], + initialValue: string[], + object: Obj +): string[] => Object.entries(object).reduce( (acc, [key, value]) => typeof value === 'object' @@ -249,33 +255,36 @@ type SiteMap = Array export const generateSiteMap = (sitePaths: SitePathsType): SiteMap => deepReduce( - (paths: Array, path: string) => [...paths, ...[path]], + (paths: Array, path: string) => + /\/:/.test(path) ? paths : [...paths, ...[path]], [], sitePaths ) -const basePathFr = - import.meta.env.DEV && typeof window !== 'undefined' - ? `http://${window.location.host}/mon-entreprise` - : import.meta.env.VITE_FR_BASE_URL ?? '' +export const alternateLinks = () => { + const basePathFr = + import.meta.env.DEV && typeof window !== 'undefined' + ? `http://${window.location.host}/mon-entreprise` + : import.meta.env.VITE_FR_BASE_URL ?? '' -const basePathEn = - import.meta.env.DEV && typeof window !== 'undefined' - ? `http://${window.location.host}/infrance` - : import.meta.env.VITE_EN_BASE_URL ?? '' + const basePathEn = + import.meta.env.DEV && typeof window !== 'undefined' + ? `http://${window.location.host}/infrance` + : import.meta.env.VITE_EN_BASE_URL ?? '' -const enSiteMap = generateSiteMap(constructLocalizedSitePath('en')).map( - (path) => basePathEn + path -) -const frSiteMap = generateSiteMap(constructLocalizedSitePath('fr')).map( - (path) => basePathFr + path -) + const enSiteMap = generateSiteMap(constructLocalizedSitePath('en')).map( + (path) => basePathEn + path + ) + const frSiteMap = generateSiteMap(constructLocalizedSitePath('fr')).map( + (path) => basePathFr + path + ) -export const hrefLangLink = { - en: Object.fromEntries( - enSiteMap.map((key, i) => [key, { href: frSiteMap[i], hrefLang: 'fr' }]) - ), - fr: Object.fromEntries( - frSiteMap.map((key, i) => [key, { href: enSiteMap[i], hrefLang: 'en' }]) - ), + return { + en: Object.fromEntries( + enSiteMap.map((key, i) => [key, { href: frSiteMap[i], hrefLang: 'fr' }]) + ), + fr: Object.fromEntries( + frSiteMap.map((key, i) => [key, { href: enSiteMap[i], hrefLang: 'en' }]) + ), + } }