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+ // Use marked.parse with synchronous option to ensure it returns a string
16+ return marked . parse ( markdown , { async : false } ) as string ;
17+ } catch ( error ) {
18+ console . warn ( "Failed to convert markdown to HTML:" , error ) ;
19+ return markdown ;
20+ }
21+ }
22+
23+ // Process GitHub-specific markdown like PR references, commit SHAs, etc.
24+ function processGitHubMarkdown ( text : string , repoFullName : string ) : string {
25+ let processedText = text ;
26+
27+ // Replace PR references first (including those in parentheses)
28+ const prPattern = / (?: ^ | \s | [ ( [ ] ) # ( \d + ) (? = [ \s \n \] ) ] | $ ) / g;
29+ processedText = processedText . replace ( prPattern , ( match , issue ) => {
30+ const prefix = match . startsWith ( "(" ) || match . startsWith ( "[" ) ? match [ 0 ] : " " ;
31+ return `${ prefix } [#${ issue } ](https://github.com/${ repoFullName } /issues/${ issue } )` ;
32+ } ) ;
33+
34+ // Replace commit SHAs
35+ const shaPattern = / ( \s | ^ ) ( [ 0 - 9 a - f ] { 40 } ) (? = [ \s \n ] | $ ) / g;
36+ processedText = processedText . replace ( shaPattern , ( match , space , sha ) => {
37+ return `${ space } [${ sha } ](https://github.com/${ repoFullName } /commit/${ sha } )` ;
38+ } ) ;
39+
40+ // Replace user mentions
41+ const userPattern = / (?: ^ | \s ) @ ( [ a - z A - Z 0 - 9 - ] + ) (? = [ \s \n ] | $ ) / g;
42+ processedText = processedText . replace ( userPattern , ( match , username ) => {
43+ return ` [@${ username } ](https://github.com/${ username } )` ;
44+ } ) ;
45+
46+ // Replace repository references with issue numbers
47+ const repoPattern = / ( [ a - z A - Z 0 - 9 - ] + \/ [ a - z A - Z 0 - 9 - ._ - ] + ) # ( \d + ) (? = [ \s \n ] | $ ) / g;
48+ processedText = processedText . replace ( repoPattern , ( match , repo , issue ) => {
49+ return `[${ repo } #${ issue } ](https://github.com/${ repo } /issues/${ issue } )` ;
50+ } ) ;
51+
52+ return processedText ;
53+ }
54+
1155export async function GET ( ) {
1256 const entries = await getAllEntries ( ) ;
1357 const baseUrl =
@@ -23,13 +67,18 @@ export async function GET() {
2367 <language>en-US</language>
2468 ${ entries
2569 . map (
26- ( entry ) => `
70+ ( entry ) => {
71+ // Process GitHub markdown first, then convert to HTML
72+ const processedDescription = processGitHubMarkdown ( entry . description , entry . metadata . sourceRepo ) ;
73+ const htmlDescription = markdownToHtml ( processedDescription ) ;
74+
75+ return `
2776 <item>
2877 <title><![CDATA[${ entry . title } ]]></title>
2978 <link>${ baseUrl } /entry/${ entry . id } </link>
3079 <guid isPermaLink="false">${ entry . id } </guid>
3180 <pubDate>${ new Date ( entry . date ) . toUTCString ( ) } </pubDate>
32- <description><![CDATA[${ entry . description } ]]></description>
81+ <description><![CDATA[${ htmlDescription } ]]></description>
3382 ${
3483 entry . metadata . sourceRepo
3584 ? `
@@ -38,7 +87,7 @@ export async function GET() {
3887 : ""
3988 }
4089 </item>
41- ` ,
90+ ` }
4291 )
4392 . join ( "" ) }
4493 </channel>
0 commit comments