Skip to content

Commit 08fc758

Browse files
committed
Remix attribution layout code cleanup
1 parent 3d64ff1 commit 08fc758

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/layouts/ExampleLayout.astro

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ const relatedReferences =
4343
4444
const { Content } = await example.render();
4545
46-
const collectivelyAttributedSince = example.data.remix?.reduce((acc, item) => {
47-
if (typeof item === "string") return acc;
48-
if (item.collectivelyAttributedSince) {
49-
return item.collectivelyAttributedSince;
50-
}
51-
return acc;
52-
}, null);
53-
46+
// Extract the collective attribution year. If multiple provided, uses last shown.
47+
const collectivelyAttributedSince = example.data.remix?.reduce(
48+
(acc: number | null, item) => {
49+
if (typeof item === "string") return acc;
50+
if (item.collectivelyAttributedSince) {
51+
return item.collectivelyAttributedSince;
52+
}
53+
return acc;
54+
},
55+
null
56+
);
5457
5558
---
5659

@@ -83,6 +86,9 @@ const collectivelyAttributedSince = example.data.remix?.reduce((acc, item) => {
8386

8487
const parts = [];
8588

89+
// Each remix entry requires either attribution, or a codeURL; these have no defaults
90+
// If a remix entry contains a collective attribution starting year, it is ignored here
91+
8692
if (!item.collectivelyAttributedSince && (item.attribution || item.codeURL)) {
8793
parts.push(<>{item.description}</>);
8894

@@ -93,7 +99,7 @@ const collectivelyAttributedSince = example.data.remix?.reduce((acc, item) => {
9399
{item.attribution.map((a, j) => (
94100
<>
95101
{a.URL ? <a href={a.URL}>{a.name}</a> : a.name}
96-
{j < item.attribution.length - 1 ? ", " : !item.codeURL ? "." : ""}
102+
{j < (item.attribution?.length ?? 0) - 1 ? ", " : !item.codeURL ? "." : ""}
97103
</>
98104
))}
99105
</>
@@ -109,7 +115,7 @@ const collectivelyAttributedSince = example.data.remix?.reduce((acc, item) => {
109115
}
110116
}
111117

112-
return <span key={i}>{i > 0 && " "}{parts}</span>;
118+
return <span>{i > 0 && " "}{parts}</span>;
113119
})}
114120

115121
{collectivelyAttributedSince ? (

0 commit comments

Comments
 (0)