44 */
55
66import { getAllEntries } from "@/lib/store" ;
7+ import { marked } from "marked" ;
78
89export const dynamic = "force-dynamic" ;
910export const revalidate = 60 ;
1011
12+ // Convert markdown to HTML for RSS feeds
13+ function markdownToHtml ( markdown : string ) : string {
14+ try {
15+ return marked . parse ( markdown ) ;
16+ } catch ( error ) {
17+ console . warn ( "Failed to convert markdown to HTML:" , error ) ;
18+ return markdown ;
19+ }
20+ }
21+
22+ // Process GitHub-specific markdown like PR references, commit SHAs, etc.
23+ function processGitHubMarkdown ( text : string , repoFullName : string ) : string {
24+ let processedText = text ;
25+
26+ // Replace PR references first (including those in parentheses)
27+ const prPattern = / (?: ^ | \s | [ ( [ ] ) # ( \d + ) (? = [ \s \n \] ) ] | $ ) / g;
28+ processedText = processedText . replace ( prPattern , ( match , issue ) => {
29+ const prefix = match . startsWith ( "(" ) || match . startsWith ( "[" ) ? match [ 0 ] : " " ;
30+ return `${ prefix } [#${ issue } ](https://github.com/${ repoFullName } /issues/${ issue } )` ;
31+ } ) ;
32+
33+ // Replace commit SHAs
34+ const shaPattern = / ( \s | ^ ) ( [ 0 - 9 a - f ] { 40 } ) (? = [ \s \n ] | $ ) / g;
35+ processedText = processedText . replace ( shaPattern , ( match , space , sha ) => {
36+ return `${ space } [${ sha } ](https://github.com/${ repoFullName } /commit/${ sha } )` ;
37+ } ) ;
38+
39+ // Replace user mentions
40+ const userPattern = / (?: ^ | \s ) @ ( [ a - z A - Z 0 - 9 - ] + ) (? = [ \s \n ] | $ ) / g;
41+ processedText = processedText . replace ( userPattern , ( match , username ) => {
42+ return ` [@${ username } ](https://github.com/${ username } )` ;
43+ } ) ;
44+
45+ // Replace repository references with issue numbers
46+ const repoPattern = / ( [ a - z A - Z 0 - 9 - ] + \/ [ a - z A - Z 0 - 9 - ._ - ] + ) # ( \d + ) (? = [ \s \n ] | $ ) / g;
47+ processedText = processedText . replace ( repoPattern , ( match , repo , issue ) => {
48+ return `[${ repo } #${ issue } ](https://github.com/${ repo } /issues/${ issue } )` ;
49+ } ) ;
50+
51+ return processedText ;
52+ }
53+
1154export async function GET ( ) {
1255 const entries = await getAllEntries ( ) ;
1356 const baseUrl =
@@ -23,13 +66,18 @@ export async function GET() {
2366 <language>en-US</language>
2467 ${ entries
2568 . map (
26- ( entry ) => `
69+ ( entry ) => {
70+ // Process GitHub markdown first, then convert to HTML
71+ const processedDescription = processGitHubMarkdown ( entry . description , entry . metadata . sourceRepo ) ;
72+ const htmlDescription = markdownToHtml ( processedDescription ) ;
73+
74+ return `
2775 <item>
2876 <title><![CDATA[${ entry . title } ]]></title>
2977 <link>${ baseUrl } /entry/${ entry . id } </link>
3078 <guid isPermaLink="false">${ entry . id } </guid>
3179 <pubDate>${ new Date ( entry . date ) . toUTCString ( ) } </pubDate>
32- <description><![CDATA[${ entry . description } ]]></description>
80+ <description><![CDATA[${ htmlDescription } ]]></description>
3381 ${
3482 entry . metadata . sourceRepo
3583 ? `
@@ -38,7 +86,7 @@ export async function GET() {
3886 : ""
3987 }
4088 </item>
41- ` ,
89+ ` }
4290 )
4391 . join ( "" ) }
4492 </channel>
0 commit comments