Skip to content

Commit e1ed810

Browse files
authored
audience metadata component (#5)
* audience metadata component * everyone audience, Temporal polyfill fixes, node 26 in github, Typescript 6 * case fix for build part 1 * case fix for build part 2
1 parent 1b6ac77 commit e1ed810

11 files changed

Lines changed: 104 additions & 32 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Setup Node
4545
uses: actions/setup-node@v5
4646
with:
47-
node-version: "24"
47+
node-version: "26"
4848

4949
- name: Setup Pages
5050
uses: actions/configure-pages@v6

app/connect/connect-submission/page.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
readingTime: PT15M
3+
audiences: tre-operator
34
---
45

56
import { Steps, Callout, Table } from "nextra/components";
File renamed without changes.
File renamed without changes.

components/Badge.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { JSX, PropsWithChildren } from "react";
2+
3+
export function Badge({ children, className, ...p }: PropsWithChildren<JSX.IntrinsicElements["span"]>) {
4+
return <span className={`px-2 py-1 rounded-xl bg-blue-300 text-blue-700 text-sm ${className}`} {...p}>
5+
{children}
6+
</span>
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"use client";
22
import { useConfig } from "nextra-theme-docs";
33
import { TimeToRead } from "./TimeToRead";
4+
import { TargetAudiences } from "./TargetAudiences";
45

56
export function DocMetadata() {
67
const metadata = useConfig().normalizePagesResult.activeMetadata;
78

89
return <>
10+
<TargetAudiences metadata={metadata} />
911
<TimeToRead metadata={metadata} />
1012
</>
1113
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { LucideUsers } from "lucide-react";
2+
import { FrontMatter } from "nextra";
3+
import { Badge } from "@/components/Badge";
4+
5+
type BadgeSpec = {
6+
label: string;
7+
colors?: string;
8+
}
9+
10+
const audienceBadges: { [k: string]: BadgeSpec } = {
11+
"everyone": {label: "Everyone", colors: "text-blue-900 font-semibold bg-gradient-to-r from-red-400/70 via-green-200/70 to-violet-500/70" },
12+
"tre-operator": { label: "TRE Operator", colors: "bg-blue-200 text-blue-700" },
13+
"federation-operator": { label: "Federation Operator", colors: "bg-orange-200 text-orange-700" },
14+
"researcher": { label: "Researcher", colors: "bg-purple-200 text-purple-700" },
15+
"integrator": { label: "Integrator", colors: "bg-green-200 text-green-700" },
16+
"contributor": { label: "Contributor", colors: "bg-red-200 text-red-700" }
17+
}
18+
19+
export function TargetAudiences({ metadata }: { metadata?: FrontMatter }) {
20+
if (metadata?.audiences == null) return null;
21+
22+
// standardise to a string array, or bail if impossible
23+
let { audiences } = metadata;
24+
if (typeof audiences === "string") audiences = [audiences]
25+
if (!Array.isArray(audiences)) return null;
26+
27+
// map valid keys only to badge specs
28+
audiences = audiences.reduce((a, v) => {
29+
const badge = audienceBadges[v];
30+
return badge == null ? a : [...a, badge];
31+
}, []);
32+
33+
// Leave if we didn't have any valid keys
34+
if(audiences.length < 1) return null
35+
36+
return (<dl className="flex w-full p-2 gap-2">
37+
<dt className="">
38+
<div className="flex gap-2 font-semibold items-center">
39+
<LucideUsers /> Target Audience{audiences.length > 1 && "s"}
40+
</div>
41+
</dt>
42+
43+
<div className="flex flex-wrap gap-2">
44+
{audiences.map(({ label, colors }: BadgeSpec) => {
45+
if (label == null) return null
46+
47+
return <dd key={label}>
48+
<Badge className={colors ?? ""}>
49+
{label}
50+
</Badge>
51+
</dd>
52+
})}
53+
</div>
54+
</dl>)
55+
}

components/doc-metadata/TimeToRead.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { LucideClock } from "lucide-react";
22
import { FrontMatter } from "nextra";
3+
import { useEffect } from "react";
34

45
// conditionally polyfill Temporal for Safari :(
56
const loadTemporal = async () => {
6-
if (typeof Temporal === 'undefined') {
7-
const polyfill = await import('@js-temporal/polyfill');
8-
window.Temporal = polyfill.Temporal;
7+
if (typeof Temporal === "undefined") {
8+
const polyfill = await import("temporal-polyfill");
9+
globalThis.Temporal = polyfill.Temporal;
910
}
1011
};
1112

@@ -14,7 +15,9 @@ await loadTemporal();
1415
export function TimeToRead({ metadata }: { metadata?: FrontMatter }) {
1516
if (metadata?.readingTime == null) return null;
1617

17-
return (<dl className="flex w-full p-2 gap-2 border-solid border-white border-thick">
18+
useEffect(() => { loadTemporal() }, [])
19+
20+
return (<dl className="flex w-full p-2 gap-2 items-center">
1821
<dt className="">
1922
<div className="flex gap-2 font-semibold">
2023
<LucideClock /> Time to read

package-lock.json

Lines changed: 28 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)