File tree Expand file tree Collapse file tree 3 files changed +74
-17
lines changed
Expand file tree Collapse file tree 3 files changed +74
-17
lines changed Original file line number Diff line number Diff line change 22import { getFunctionInfo } from ' @src/utils/functions' ;
33import { getEventTypePretty } from ' @src/utils/events' ;
44import { Icon } from ' @astrojs/starlight/components' ;
5+ import { badgeConfig } from " @src/utils/badges" ;
6+ import { Badge } from " @astrojs/starlight/components" ;
57
68interface Props {
79 itemsByCategory: any ;
@@ -134,14 +136,50 @@ function displayCategory(category: string) {
134136 <h4 >{ displayTitle (category )}
135137 <a href = { ` #${slugify (category )} ` } ><Icon size = " 1.5rem" name = " external" class = " mtainfoicon" /></a >
136138 </h4 >
139+
137140 <ul >
138141 { items
139142 .slice ()
140143 .sort ((a , b ) => a .id .localeCompare (b .id ))
141- .map (item => (
142- <li set :html = { displayItem (item )} ></li >
143- ))}
144+ .map ((item ) => {
145+ const isFunction = item .collection === " functions" ;
146+ const funcInfo = isFunction ? getFunctionInfo (item .data ) : null ;
147+
148+ const badgeType = funcInfo ?.version ?.added ? " new" : funcInfo ?.version ?.updated ? " updated" : null ;
149+ const badge = badgeType ? badgeConfig [badgeType ] : null ;
150+
151+ return (
152+ <li >
153+ <a href = { ` /reference/${item .id } ` } >{ item .id } </a >
154+
155+ { what === " all_functions" && funcInfo && (
156+ <>
157+ (<span class = { ` side-${funcInfo .type } ` } >{ funcInfo .typePretty } </span >)
158+ </>
159+ )}
160+
161+ { what === " all_events" && (
162+ <>
163+ { " " }
164+ (<span class = { ` side-${item .data .type } ` } >
165+ { getEventTypePretty (item .data .type )} -side
166+ </span >)
167+ </>
168+ )}
169+
170+ { badge && (
171+ <Badge
172+ text = { badge .text }
173+ variant = { badge .variant }
174+ size = " medium"
175+ style = " font-weight: bold;"
176+ />
177+ )}
178+ </li >
179+ );
180+ })}
144181 </ul >
182+
145183 </section >
146184 ))}
147185</section >
Original file line number Diff line number Diff line change 11---
22import type { SeeAlsoLinkGroup } from " @src/utils/general" ;
3+ import { getBadgeConfig } from " @src/utils/badges" ;
34import { Badge } from " @astrojs/starlight/components" ;
45
56export interface Props {
@@ -8,16 +9,6 @@ export interface Props {
89}
910
1011const { seeAlsoLinks, currentId } = Astro .props ;
11-
12- const badgeConfig: {
13- [key : string ]: {
14- text: string ;
15- variant: " note" | " danger" | " success" | " caution" | " tip" | " default" ;
16- };
17- } = {
18- new: { text: " New" , variant: " success" },
19- updated: { text: " Updated" , variant: " caution" },
20- };
2112---
2213
2314{
@@ -44,10 +35,7 @@ const badgeConfig: {
4435
4536 { link .badge &&
4637 (() => {
47- const config = badgeConfig [link .badge ] ?? {
48- text: link .badge ,
49- variant: " default" ,
50- };
38+ const config = getBadgeConfig (link .badge ) || {text: link .badge , variant: " default" };
5139
5240 return (
5341 <Badge
Original file line number Diff line number Diff line change 1+ export type BadgeVariant =
2+ | "note"
3+ | "danger"
4+ | "success"
5+ | "caution"
6+ | "tip"
7+ | "default" ;
8+
9+ export type BadgeType = "new" | "updated" ;
10+
11+ export const badgeConfig : Record <
12+ BadgeType ,
13+ {
14+ text : string ;
15+ variant : BadgeVariant ;
16+ }
17+ > = {
18+ new : {
19+ text : "New" ,
20+ variant : "success" ,
21+ } ,
22+ updated : {
23+ text : "Updated" ,
24+ variant : "caution" ,
25+ } ,
26+ } ;
27+
28+ export function getBadgeConfig ( type ?: string ) {
29+ if ( ! type ) return null ;
30+ return badgeConfig [ type as BadgeType ] ?? null ;
31+ }
You can’t perform that action at this time.
0 commit comments