-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
import { getCollection } from "astro:content"; | ||
import { exampleContentSlugToLegacyWebsiteSlug } from "./utils"; | ||
import { readFile } from "fs/promises"; | ||
export async function getStaticPaths() { | ||
const examples = await getCollection("examples"); | ||
const paths = await Promise.all( | ||
examples.map(async (example) => { | ||
const codePath = `src/content/examples/${example.id.replace("description.mdx", "code.js")}`; | ||
const code = await readFile(codePath, "utf-8"); | ||
return { | ||
params: { slug: exampleContentSlugToLegacyWebsiteSlug(example.slug) }, | ||
props: { example, code }, | ||
}; | ||
}), | ||
); | ||
return paths; | ||
} | ||
const { example, code } = Astro.props; | ||
const { Content } = await example.render(); | ||
--- | ||
|
||
<h1>{example.data.title}</h1> | ||
<p>{example.data.arialabel}</p> | ||
<Content /> | ||
<pre>{code}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** Astro automatically uses the directory structure for slug information */ | ||
/** Historically the p5 website has used a different structure for example file vs. webpage routing */ | ||
/** This function transforms the Astro slug to the appropriate webpage route to avoid breaking */ | ||
/** Any inbound legacy links */ | ||
export const exampleContentSlugToLegacyWebsiteSlug = (path: string): string => | ||
path | ||
.replace(/^en\/\d+_(.*?)\/\d+_(.*?)\/description$/, "/$1-$2.html") | ||
.replace(/_/g, "-"); | ||
|
||
export default exampleContentSlugToLegacyWebsiteSlug; |