Skip to content

Commit 6c6f9a3

Browse files
committed
add validation filtering in getStaticPaths for OpenProcessing sketches
- Add basic validation (visualID, type check) in sketch getStaticPaths - Remove unnecessary isNaN check from SketchLayout - Prevent invalid sketch pages from being generated during build
1 parent 5764d4c commit 6c6f9a3

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed

src/layouts/SketchLayout.astro

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ const { sketchId, authorName } = Astro.props;
2424
2525
const sketchIdNumber = Number(sketchId);
2626
27-
if (isNaN(sketchIdNumber)) {
28-
console.error(`Invalid sketch ID: ${sketchId}`);
29-
}
30-
3127
const { title, createdOn, instructions } = await getSketch(sketchIdNumber);
3228
3329
const currentLocale = getCurrentLocale(Astro.url.pathname);

src/pages/[locale]/sketches/[...slug].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function getStaticPaths() {
77
const sketches = await getCurationSketches();
88
const entries = await Promise.all(
99
nonDefaultSupportedLocales.map(async (locale) => {
10-
return sketches.map((sketch) => ({
10+
return sketches.filter(sketch => sketch.visualID && typeof sketch.visualID === 'number').map((sketch) => ({
1111
// Even though slug gets converted to string at runtime,
1212
// TypeScript infers it as number from sketch.visualID, so we explicitly convert to string.
1313
params: { locale, slug: String(sketch.visualID) },

src/pages/sketches/[...slug].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getCurationSketches } from "@src/api/OpenProcessing";
44
55
export async function getStaticPaths() {
66
const sketches = await getCurationSketches();
7-
return sketches.map((sketch) => ({
7+
return sketches.filter(sketch => sketch.visualID && typeof sketch.visualID === 'number').map((sketch) => ({
88
// Even though slug gets converted to string at runtime,
99
// TypeScript infers it as number from sketch.visualID, so we explicitly convert to string.
1010
params: { slug: String(sketch.visualID) },

0 commit comments

Comments
 (0)