@@ -14,6 +14,7 @@ export interface Guide {
1414 description ?: string ;
1515 image ?: string | { light : string ; dark : string } ;
1616 icon ?: IconName ;
17+ externalUrl ?: string ;
1718}
1819
1920export interface PluginData {
@@ -93,8 +94,39 @@ const recentGuidesPlugin: Plugin = function recentGuidesPlugin(
9394 : baseName ;
9495 const permalink = `/guides/${ slug === "index" ? "" : slug } ` ;
9596
97+ const externalUrl : string | undefined =
98+ ( data as any ) . externalUrl || ( data as any ) . external_url ;
99+
100+ const frontmatterDate : unknown = ( data as any ) . publishedAt ;
101+
102+ let lastUpdatedAt : number ;
103+ if ( frontmatterDate ) {
104+ let millis : number | null = null ;
105+ if ( typeof frontmatterDate === "string" ) {
106+ const parsed = Date . parse ( frontmatterDate ) ;
107+ if ( ! Number . isNaN ( parsed ) ) {
108+ millis = parsed ;
109+ }
110+ } else if ( frontmatterDate instanceof Date ) {
111+ millis = frontmatterDate . getTime ( ) ;
112+ } else if ( typeof frontmatterDate === "number" ) {
113+ millis =
114+ frontmatterDate > 1e12
115+ ? frontmatterDate
116+ : frontmatterDate * 1000 ;
117+ }
118+
119+ lastUpdatedAt = millis
120+ ? Math . floor ( millis / 1000 )
121+ : Math . floor ( stats . mtimeMs / 1000 ) ;
122+ } else {
123+ lastUpdatedAt = Math . floor ( stats . mtimeMs / 1000 ) ;
124+ }
125+
96126 let tags = data . tags || [ ] ;
97- if ( ! Array . isArray ( tags ) ) { tags = [ ] ; }
127+ if ( ! Array . isArray ( tags ) ) {
128+ tags = [ ] ;
129+ }
98130
99131 tags . forEach ( ( tag : string ) => {
100132 tagCounts [ tag ] = ( tagCounts [ tag ] || 0 ) + 1 ;
@@ -124,10 +156,11 @@ const recentGuidesPlugin: Plugin = function recentGuidesPlugin(
124156 path . basename ( filePath , path . extname ( filePath ) ) ,
125157 permalink : data . slug || permalink ,
126158 tags : formattedTags ,
127- lastUpdatedAt : Math . floor ( stats . mtimeMs / 1000 ) ,
159+ lastUpdatedAt,
128160 description : data . description ,
129161 image : data . image ,
130162 icon : data . icon ,
163+ externalUrl,
131164 } ;
132165 } ) ;
133166
0 commit comments