Skip to content

Commit

Permalink
feat: unified URL structure
Browse files Browse the repository at this point in the history
Signed-off-by: Maud Royer <[email protected]>
  • Loading branch information
jillro committed Nov 12, 2024
1 parent cca7b17 commit c263820
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 26 deletions.
20 changes: 20 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ const nextConfig = {
});
return config;
},
async rewrites() {
return [
{
source: "/articles/:letter([A-Za-z])",
destination: "/alpha_lists/articles/:letter",
},
{
source: "/medicaments/:letter([A-Za-z])/:page(\\d+)",
destination: "/alpha_lists/medicaments/:letter/:page",
},
{
source: "/pathologies/:letter([A-Za-z])",
destination: "/alpha_lists/pathologies/:letter",
},
{
source: "/substances/:letter([A-Za-z])",
destination: "/alpha_lists/substances/:letter",
},
];
},
experimental: {
instrumentationHook: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default async function Page({
<h1 className={fr.cx("fr-h1", "fr-mb-8w")}>Liste des médicaments</h1>
<AlphabeticNav
letters={letters}
url={(letter) => `/parcourir/medicaments/${letter}/1`}
url={(letter) => `/medicaments/${letter}/1`}
/>
<MedGroupSpecListList
items={medicaments.slice(
Expand All @@ -82,7 +82,7 @@ export default async function Page({
count={pageCount}
defaultPage={pageNumber}
getPageLinkProps={(number: number) => ({
href: `/parcourir/medicaments/${letter}/${number}`,
href: `/medicaments/${letter}/${number}`,
})}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ export default async function Page({
<h1 className={fr.cx("fr-h1", "fr-mb-8w")}>Liste des pathologies</h1>
<AlphabeticNav
letters={letters}
url={(letter) => `/parcourir/pathologies/${letter}`}
url={(letter) => `/pathologies/${letter}`}
/>
<ul className={fr.cx("fr-raw-list")}>
{pathos.map((patho, i) => (
<li key={i} className={fr.cx("fr-mb-1v")}>
<Link
href={`/pathologie/${patho.codePatho}`}
href={`/pathologies/${patho.codePatho}`}
className={fr.cx("fr-link")}
>
{patho.NomPatho}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ export default async function Page({
<h1 className={fr.cx("fr-h1", "fr-mb-8w")}>Liste des substances</h1>
<AlphabeticNav
letters={letters}
url={(letter) => `/parcourir/substances/${letter}`}
url={(letter) => `/substances/${letter}`}
/>
<ul className={fr.cx("fr-raw-list")}>
{substances.map((substance, i) => (
<li key={i} className={fr.cx("fr-mb-1v")}>
<Link
href={`/substance/${substance.NomId}`}
href={`/substances/${substance.NomId}`}
className={fr.cx("fr-link")}
>
{substance.NomLib}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function Page({
{ label: "Acceuil", linkProps: { href: "/" } },
{
label: "Liste des articles",
linkProps: { href: "/parcourir/articles" },
linkProps: { href: "/articles" },
},
]}
currentPageLabel={title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async function Page() {
.map(({ title, slug }) => (
<li key={slug} className={"fr-mb-1w"}>
<Link
href={`/article/${slug}`}
href={`/articles/${slug}`}
className={fr.cx(
"fr-link",
"fr-link--icon-left",
Expand Down
2 changes: 1 addition & 1 deletion src/app/(container)/atc/[code]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const dynamicParams = true;

const SubstanceItem = ({ item }: { item: SubstanceNom }) => (
<li key={item.NomId} className={fr.cx("fr-mb-1w")}>
<Link className={fr.cx("fr-link")} href={`/substance/${item.NomId}`}>
<Link className={fr.cx("fr-link")} href={`/substances/${item.NomId}`}>
{item.NomLib}
</Link>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { afterEach, describe, expect, test } from "vitest";
import { cleanup, screen, within } from "@testing-library/react";
import HTMLParser from "node-html-parser";

import DsfrLeafletSection from "@/app/(container)/medicament/[CIS]/DsfrLeafletSection";
import DsfrLeafletSection from "./DsfrLeafletSection";
import { renderServerComponent } from "@/testsUtils/renderServerComponent";

describe("DsfrLeafletSection", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { HTMLElement, Node, NodeType } from "node-html-parser";
import { JSX } from "react";
import Image from "next/image";
import { fr } from "@codegouvfr/react-dsfr";
import {
isEmptyTextNode,
isHtmlElement,
isListItem,
} from "@/app/(container)/medicament/[CIS]/leafletUtils";
import { isEmptyTextNode, isHtmlElement, isListItem } from "./leafletUtils";
import { getLeafletImage } from "@/db";

async function DsfrLeafletElement({ node }: { node: HTMLElement }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { Nullable, sql } from "kysely";

import { pdbmMySQL } from "@/db/pdbmMySQL";
import liste_CIS_MVP from "@/liste_CIS_MVP.json";
import DsfrLeafletSection from "@/app/(container)/medicament/[CIS]/DsfrLeafletSection";
import { isHtmlElement } from "@/app/(container)/medicament/[CIS]/leafletUtils";
import DsfrLeafletSection from "./DsfrLeafletSection";
import { isHtmlElement } from "./leafletUtils";
import {
dateShortFormat,
displayCompleteComposants,
Expand Down Expand Up @@ -356,7 +356,7 @@ export default async function Page({
key={substance.NomId}
small
linkProps={{
href: `/substance/${substance.NomId}`,
href: `/substances/${substance.NomId}`,
className: cx("fr-tag--custom-alt-substance"),
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async function Page({
{
label: "Listes des pathologies",
linkProps: {
href: `/parcourir/pathologies/${patho.NomPatho.slice(0, 1)}`,
href: `/pathologies/${patho.NomPatho.slice(0, 1)}`,
},
},
]}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(container)/rechercher/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SubstanceResult = ({ item }: { item: SubstanceNom }) => (
)}
/>
<Link
href={`/substance/${item.NomId}`}
href={`/substances/${item.NomId}`}
className={fr.cx("fr-text--md", "fr-text--bold", "fr-link")}
>
{formatSpecName(item.NomLib)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default async function Page({
<ul>
{specialites?.map((specialite) => (
<li key={specialite.SpecId}>
<Link href={`/medicament/${specialite.SpecId}`}>
<Link href={`/medicaments/${specialite.SpecId}`}>
{formatSpecName(specialite.SpecDenom01)}
</Link>
</li>
Expand Down
8 changes: 4 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ export default async function RootLayout({
menuLinks: [
{
text: "Tous les médicaments",
linkProps: { href: "/parcourir/medicaments/A/1" },
linkProps: { href: "/medicaments/A/1" },
},
{
text: "Toutes les substances",
linkProps: { href: "/parcourir/substances/A" },
linkProps: { href: "/substances/A" },
},
{
text: "Toutes les pathologies",
linkProps: { href: "/parcourir/pathologies/A" },
linkProps: { href: "/pathologies/A" },
},
],
},
{
text: "Articles",
linkProps: { href: "/parcourir/articles" },
linkProps: { href: "/articles" },
},
]}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MedGroupSpecList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default async function MedGroupSpecList({
{specialites?.map((specialite, i) => (
<li key={i} className={fr.cx("fr-mb-1v")}>
<Link
href={`/medicament/${specialite.SpecId}`}
href={`/medicaments/${specialite.SpecId}`}
className={fr.cx("fr-text--sm", "fr-link")}
>
{formatSpecName(specialite.SpecDenom01)}
Expand Down

0 comments on commit c263820

Please sign in to comment.