Skip to content

Commit 8b3d87f

Browse files
committed
Use remixLookup to reduce duplicate .mdx headers
1 parent f9596c7 commit 8b3d87f

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

src/content/examples/config.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z, defineCollection, reference } from "astro:content";
22

3+
34
/**
45
* Content collection for the Examples section of the site.
56
* Each file represents a single example.
@@ -22,19 +23,49 @@ export const examplesCollection = defineCollection({
2223

2324
// Start of collective attribution
2425
collectivelyAttributedSince: z.number().optional(),
25-
26+
2627
// Optional list of remixes to add to license
2728
remix: z
2829
.array(
29-
z.object({
30-
attributionURL: z.string().optional(),
31-
attributionLabel: z.string().optional(),
32-
remixURL: z.string().optional(),
33-
remixLabel: z.string().optional(),
34-
})
30+
z.union([
31+
z.string(),
32+
z.object({
33+
attributionURL: z.string().optional(),
34+
attributionLabel: z.string().optional(),
35+
remixURL: z.string().optional(),
36+
remixLabel: z.string().optional(),
37+
}),
38+
])
3539
)
3640
.optional()
3741
.default([]),
3842
}),
3943
});
4044

45+
/**
46+
* The `remix` field lets you add remix attributions in two ways:
47+
* 1. Full objects with all details.
48+
* 2. Short string keys that refer to predefined entries in `remixLookup`.
49+
* When rendering (in ExampleLayout.astro), these keys are replaced
50+
* with their full details from `remixLookup`.
51+
*/
52+
export const remixLookup = {
53+
"revision-2023-calebfoss": {
54+
attributionURL: "https://github.com/calebfoss",
55+
attributionLabel: "Caleb calebfoss",
56+
remixURL: "https://github.com/processing/p5.js-example",
57+
remixLabel: "Revised in 2023",
58+
},
59+
"revision-2023-dkessner": {
60+
attributionURL: "https://github.com/dkessner",
61+
attributionLabel: "Darren Kessner",
62+
remixURL: "https://github.com/processing/p5.js-example",
63+
remixLabel: "Revised in 2023",
64+
},
65+
"revision-2023-katlich112358": {
66+
attributionURL: "https://www.klich.co/",
67+
attributionLabel: "Kasey Lichtlyter",
68+
remixURL: "https://github.com/processing/p5.js-example",
69+
remixLabel: "Revised in 2023",
70+
}
71+
};

src/content/examples/en/01_Shapes_And_Color/00_Shape_Primitives/description.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ relatedReference:
88
- en/p5/ellipse
99

1010
remix:
11-
- attributionURL: https://github.com/dkessner
12-
attributionLabel: Darren Kessner
13-
remixURL: https://github.com/processing/p5.js-example
14-
remixLabel: Revised in 2023
11+
- revision-2023-dkessner
1512
---
1613

1714
This program demonstrates the use of the basic shape

src/content/examples/en/02_Animation_And_Variables/00_Drawing_Lines/description.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ featuredImage: "../../../images/featured/02_Animation_And_Variables-00_Drawing_L
33
featuredImageAlt: A squiggly rainbow line on a black background.
44
title: Drawing Lines
55
oneLineDescription: Draw with the mouse.
6+
7+
remix:
8+
- attributionURL: https://github.com/dkessner
9+
attributionLabel: Darren Kessner
10+
remixURL: https://github.com/processing/p5.js-example
11+
remixLabel: Revised in 2023
612
---
713

814
Click and drag the mouse to draw a line.

src/content/examples/en/02_Animation_And_Variables/01_Animation_With_Events/description.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ featuredImage: "../../../images/featured/02_Animation_And_Variables-01_Animation
33
featuredImageAlt: A small green circle on a black background.
44
title: Animation with Events
55
oneLineDescription: Pause and resume animation.
6+
7+
remix:
8+
- revision-2023-dkessner
69
---
710

811
This example demonstrates the use of

src/content/examples/en/15_Math_And_Physics/03_Smoke_Particle_System/description.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ collectivelyAttributedSince: 2024
99
remix:
1010
- attributionURL: https://natureofcode.com/book/chapter-4-particle-systems/
1111
attributionLabel: Dan Shiffman's example
12-
- attributionURL: https://github.com/dkessner
13-
attributionLabel: Darren Kessner
14-
remixURL: https://github.com/processing/p5.js-example
15-
remixLabel: Revised in 2023
12+
- revision-2023-dkessner
1613
---
1714

1815

src/layouts/ExampleLayout.astro

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { CollectionEntry } from "astro:content";
33
import Head from "@components/Head/index.astro";
44
import { setJumpToState } from "../globals/state";
5+
import { remixLookup } from "../content/examples/config";
56
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
67
import {
78
generateJumpToState,
@@ -41,6 +42,12 @@ const relatedReferences =
4142
)
4243
: [];
4344
45+
// Rather than using example.data.remix, use resolvedRemix
46+
// Which fills in widely-used attributions to avoid duplication
47+
const resolvedRemix = example.data.remix.map((entry: any) =>
48+
typeof entry === "string" ? remixLookup[entry] : entry
49+
);
50+
4451
const { Content } = await example.render();
4552
---
4653

@@ -68,7 +75,7 @@ const { Content } = await example.render();
6875

6976
<a href={Astro.url.pathname}>{example.data.title}</a>:
7077

71-
{example.data.remix?.map((item, i) => (
78+
{resolvedRemix?.map((item, i) => (
7279
<>
7380
{i > 0 && " "}
7481
{item.remixLabel && item.remixURL ? (

0 commit comments

Comments
 (0)