Skip to content

Commit

Permalink
feat: pre-render substance pages
Browse files Browse the repository at this point in the history
Signed-off-by: Maud Royer <hello@maudroyer.fr>
  • Loading branch information
jillro committed Aug 16, 2024
1 parent 2682292 commit 31fa972
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/substance/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import { pdbmMySQL, Specialite, SubstanceNom } from "@/db/pdbmMySQL";
import { formatSpecName, groupSpecialites } from "@/displayUtils";
import liste_CIS_MVP from "@/liste_CIS_MVP.json";

export async function generateStaticParams(): Promise<{ id: string }[]> {
return (
await pdbmMySQL
.selectFrom("Subs_Nom")
.leftJoin("Composant", "Subs_Nom.SubsId", "Composant.SubsId")
.where("Composant.SpecId", "in", liste_CIS_MVP)
.select("Subs_Nom.SubsId as id")
.distinct()
.execute()
).map(({ id }) => ({ id: id.trim() }));
}

async function getSubstance(id: string) {
const substance: SubstanceNom = await pdbmMySQL
.selectFrom("Subs_Nom")
Expand All @@ -17,7 +29,7 @@ async function getSubstance(id: string) {
selectFrom("Subs_Nom as subquery")
.select("NomId")
.whereRef("subquery.SubsId", "=", "Subs_Nom.SubsId")
.orderBy(sql`LENGTH(Subs_Nom.NomLib)`)
.orderBy(sql`LENGTH(subquery.NomLib)`)
.limit(1),
),
)
Expand Down

0 comments on commit 31fa972

Please sign in to comment.