-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathExampleLayout.astro
More file actions
188 lines (163 loc) · 5.42 KB
/
ExampleLayout.astro
File metadata and controls
188 lines (163 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
---
import type { CollectionEntry } from "astro:content";
import Head from "@components/Head/index.astro";
import { getCurrentLocale, getUiTranslator } from "../i18n/utils";
import {
generateJumpToState,
getRelatedEntriesinCollection,
} from "../pages/_utils";
import BaseLayout from "./BaseLayout.astro";
import EditableSketch from "@components/EditableSketch/index.astro";
import RelatedItems from "@components/RelatedItems/index.astro";
import OutdatedTranslationBanner from "@components/OutdatedTranslationBanner/index.astro";
import { checkTranslationBanner } from "../utils/translationBanner";
interface Props {
example: CollectionEntry<"examples">;
code: string;
relatedExamples: CollectionEntry<"examples">[];
}
const { example, code, relatedExamples } = Astro.props;
const currentLocale = getCurrentLocale(Astro.url.pathname);
const t = await getUiTranslator(currentLocale);
const jumpToState = await generateJumpToState(
"examples",
example.slug,
"Examples",
t,
currentLocale
);
Astro.locals.jumpToState = jumpToState;
const relatedReferences =
example.data.relatedReference !== undefined
? await getRelatedEntriesinCollection(
"reference",
currentLocale,
example.data.relatedReference.map((r: any) => r.slug)
)
: [];
const { Content } = await example.render();
// Extract the collective attribution year. If multiple provided, uses last shown.
const collectivelyAttributedSince = example.data.remix?.reduce(
(acc: number | null, item) => {
if (item.collectivelyAttributedSince) {
return item.collectivelyAttributedSince;
}
return acc;
},
null
);
// Boolean value on whether the remix history contains links to code
const remixHistoryHasCodeLinks = example.data.remix?.some(
(item) => Array.isArray(item.code) && item.code.length > 0
);
const { showBanner, englishUrl } = checkTranslationBanner(
'examples',
example.id,
currentLocale,
Astro.url.pathname,
Astro.url.origin
);
---
<Head
title={example.data.title}
locale={currentLocale}
featuredImageSrc={example.data.featuredImage.src}
description={example.data.oneLineDescription}
/>
<BaseLayout
title={example.data.title}
titleClass=""
subtitle={null}
variant="item"
topic="examples"
className="example"
>
{showBanner && <OutdatedTranslationBanner englishUrl={englishUrl} locale={currentLocale} />}
<div class="mt-xl mb-4xl lg:mb-3xl max-w-[770px]">
<div class="rendered-markdown">
<Content />
</div>
<div class="rendered-markdown">
<img src="/images/by-nc-sa.svg" alt="Creative Commons BY-NC-SA license badge" />
<p>
<a href={Astro.url.pathname}>{example.data.title}</a>:{" "}
{example.data.remix?.map((item, i) => {
const parts = [];
// Each remix entry requires at least one attribution
// If a remix entry contains a collective attribution starting year, it is ignored here
if (!item.collectivelyAttributedSince && item.attribution) {
parts.push(<>{t("attribution", item.description)}</>);
if (item.attribution?.length) {
parts.push(
<>
{" "}
{item.attribution.map((a, j) => (
<>
{a.URL ? <a href={a.URL}>{t(a.name)}</a> : t(a.name)}
{
item.attribution?.length
? j < item.attribution.length - 1 ? ", " : "."
: ""
}
</>
))}
</>
);
}
}
return <span>{i > 0 && " "}{parts}</span>;
})}
{collectivelyAttributedSince ? (
<>{t("attribution", `From ${collectivelyAttributedSince} onwards, edited and maintained by`)}{" "}</>
) : (
<>{t("attribution", "Edited and maintained by")}{" "}</>
)}
<span>
<a href="https://github.com/processing/p5.js?tab=readme-ov-file#contributors">p5.js Contributors</a>{" "}
{t("attribution", "and")}{" "}
<a href="https://processingfoundation.org/people">Processing Foundation</a>.
Licensed under{" "}
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>.
</span>
</p>
<p>
{remixHistoryHasCodeLinks ? (
<>
{t("attribution", "You can find the code history of these examples here")}{": "}
{example.data.remix
.map(item => item?.code)
.flat()
.filter(codeItem => codeItem && codeItem.URL)
.map((codeItem, i, codeItemsList) => (
<>
<a href={codeItem?.URL}>{codeItem?.label}</a>{
i < (codeItemsList?.length ?? 0) - 1 ? ", " : ". "
}
</>
))}
{t("attribution", "You can suggest improvements by")}{" "}
<a href="https://github.com/processing/p5.js-website">{t("attribution", "contributing to the current website")}</a>!
</>
) : (
<></>
)}
</p>
</div>
<EditableSketch code={code} />
<p>{example.data.arialabel}</p>
</div>
<div class="grid gap-y-4xl lg:gap-y-mb-3xl mt-2xl">
{
relatedReferences.length > 0 ? (
<RelatedItems
title={t("Related References") as string}
items={relatedReferences}
/>
) : null
}
<RelatedItems
title={t("Related Examples") as string}
items={relatedExamples}
/>
</div>
</BaseLayout>