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+ }
0 commit comments