Generate sitemap before build

pull/2175/head
Jérémy Rialland 2022-06-13 13:07:46 +02:00 committed by Jérémy Rialland
parent 8355df6b23
commit 87a21a5882
9 changed files with 62 additions and 137 deletions

1
site/.gitignore vendored
View File

@ -5,3 +5,4 @@ cypress/videos
cypress/screenshots
cypress/downloads
.deps.json
source/public/sitemap.*.txt

View File

@ -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",

View File

@ -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',
})

View File

@ -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 = () => {
<Route path={sitePaths.budget} component={Budget} />
<Route path={sitePaths.accessibilité} component={Accessibilité} />
<Route exact path="/dev/sitemap" component={Sitemap} />
<Route
exact
path="/dev/integration-test"

View File

@ -11,11 +11,13 @@ import { useContext } from 'react'
import { Helmet } from 'react-helmet-async'
import { Trans, useTranslation } from 'react-i18next'
import { ThemeProvider } from 'styled-components'
import { hrefLangLink } from '@/sitePaths'
import { alternateLinks } from '@/sitePaths'
import InscriptionBetaTesteur from './InscriptionBetaTesteur'
import Privacy from './Privacy'
import { useShowFeedback } from './useShowFeedback'
const hrefLangLink = alternateLinks()
export default function Footer() {
const sitePaths = useContext(SitePathsContext)
const showFeedback = useShowFeedback()

View File

@ -1,22 +0,0 @@
import { SitePathsContext } from '@/components/utils/SitePathsContext'
import { H1 } from '@/design-system/typography/heading'
import { useContext } from 'react'
import { generateSiteMap } from '../../sitePaths'
export default function SiteMap() {
const sitePaths = useContext(SitePathsContext)
return (
<>
<H1>Sitemap</H1>
<pre>
{generateSiteMap(sitePaths).map((path) => (
<span key={path}>
{path}
<br />
</span>
))}
</pre>
</>
)
}

View File

@ -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

View File

@ -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

View File

@ -236,7 +236,13 @@ export const constructLocalizedSitePath = (language: 'en' | 'fr') => {
export type SitePathsType = ReturnType<typeof constructLocalizedSitePath>
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<string>
export const generateSiteMap = (sitePaths: SitePathsType): SiteMap =>
deepReduce(
(paths: Array<string>, path: string) => [...paths, ...[path]],
(paths: Array<string>, 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' }])
),
}
}