@@ -8,19 +8,14 @@ import { CDN_HOST } from '~/app.static.config'
8
8
import { AlertsRule as __AlertsRule } from '~/components/ui/markdown/parsers/alert'
9
9
import { ContainerRule as __ContainerRule } from '~/components/ui/markdown/parsers/container'
10
10
import { InsertRule } from '~/components/ui/markdown/parsers/ins'
11
- import {
12
- KateXBlockRule as __KateXBlockRule ,
13
- KateXRule as __KateXRule ,
14
- } from '~/components/ui/markdown/parsers/katex'
15
11
import { MarkRule } from '~/components/ui/markdown/parsers/mark'
16
12
import { MentionRule } from '~/components/ui/markdown/parsers/mention'
17
13
import { SpoilerRule } from '~/components/ui/markdown/parsers/spoiler'
14
+ import { get } from '~/lib/lodash'
18
15
import { apiClient } from '~/lib/request'
19
16
20
- import { fetchAggregationData } from '../(app)/api'
21
-
22
17
export const dynamic = 'force-dynamic'
23
- export const revalidate = 86400 // 1 day
18
+ export const revalidate = 60
24
19
25
20
interface RSSProps {
26
21
title : string
@@ -42,18 +37,39 @@ export async function GET() {
42
37
const ReactDOM = ( await import ( 'react-dom/server' ) ) . default
43
38
44
39
const [ { author, data, url } , agg ] = await Promise . all ( [
45
- fetch ( apiClient . aggregate . proxy . feed . toString ( true ) , {
46
- next : {
47
- revalidate : 86400 ,
48
- } ,
49
- } ) . then ( ( res ) => res . json ( ) as Promise < RSSProps > ) ,
50
-
51
- fetchAggregationData ( ) ,
40
+ apiClient . aggregate . proxy . feed . get < RSSProps > ( ) ,
41
+ apiClient . aggregate . getAggregateData < AppThemeConfig > ( 'shiro' ) ,
52
42
] )
53
43
54
44
const { title, description } = agg . seo
55
45
56
46
const now = new Date ( )
47
+ const custom_elements = get (
48
+ agg . $raw . theme as AppConfig ,
49
+ 'config.module.rss.custom_elements' ,
50
+ )
51
+
52
+ const followChallengeIndex = custom_elements
53
+ ? custom_elements . findIndex ( ( item : any ) => item . follow_challenge )
54
+ : - 1
55
+ if ( - ~ followChallengeIndex ) {
56
+ const map = { } as Record < string , string >
57
+
58
+ const { follow_challenge } = custom_elements [ followChallengeIndex ]
59
+ for ( const item of follow_challenge ) {
60
+ Object . assign ( map , item )
61
+ }
62
+
63
+ custom_elements [ followChallengeIndex ] . follow_challenge = [
64
+ {
65
+ feedId : map . feed_id ,
66
+ } ,
67
+ {
68
+ userId : map . user_id ,
69
+ } ,
70
+ ]
71
+ }
72
+
57
73
const feed = new RSS ( {
58
74
title,
59
75
description,
@@ -63,6 +79,8 @@ export async function GET() {
63
79
image_url : `${ url } ${ agg ?. theme ?. config ?. site ?. favicon } ` ,
64
80
generator : 'Shiro (https://github.com/Innei/Shiro)' ,
65
81
pubDate : now . toUTCString ( ) ,
82
+
83
+ custom_elements,
66
84
} )
67
85
68
86
data . forEach ( ( item ) => {
@@ -138,8 +156,8 @@ export async function GET() {
138
156
mark : MarkRule ,
139
157
ins : InsertRule ,
140
158
141
- kateX : KateXRule ,
142
- kateXBlock : KateXBlockRule ,
159
+ // kateX: KateXRule,
160
+ // kateXBlock: KateXBlockRule,
143
161
container : ContainerRule ,
144
162
alerts : AlertsRule ,
145
163
} ,
@@ -171,38 +189,54 @@ export async function GET() {
171
189
} )
172
190
} )
173
191
174
- return new Response ( feed . xml ( ) , {
192
+ return new Response ( ` ${ feed . xml ( ) } ` , {
175
193
headers : {
176
194
'Content-Type' : 'application/xml' ,
177
- 'Cache-Control' : ' max-age=60, s-maxage=86400' ,
178
- 'CDN-Cache-Control' : ' max-age=86400' ,
179
- 'Cloudflare-CDN-Cache-Control' : ' max-age=86400' ,
180
- 'Vercel-CDN-Cache-Control' : ' max-age=86400' ,
195
+ 'Cache-Control' : ` max-age=60, s-maxage=${ revalidate } ` ,
196
+ 'CDN-Cache-Control' : ` max-age=${ revalidate } ` ,
197
+ 'Cloudflare-CDN-Cache-Control' : ` max-age=${ revalidate } ` ,
198
+ 'Vercel-CDN-Cache-Control' : ` max-age=${ revalidate } ` ,
181
199
} ,
182
200
} )
183
201
}
184
202
185
203
const NotSupportRender = ( ) => {
186
- throw new Error ( 'Not support render in RSS' )
204
+ // throw new Error('Not support render in RSS')
205
+ return (
206
+ < p
207
+ style = { {
208
+ padding : '6px 12px' ,
209
+ borderLeft : '2px solid #33A6B8' ,
210
+ background : '#33A6B850' ,
211
+ fontStyle : 'italic' ,
212
+ fontWeight : 500 ,
213
+ } }
214
+ >
215
+ Not support render this content in RSS render
216
+ </ p >
217
+ )
187
218
}
188
219
189
- const KateXRule : MarkdownToJSX . Rule = {
190
- ...__KateXRule ,
191
- react ( node , _ , state ?) {
192
- return < NotSupportRender key = { state ?. key } />
193
- } ,
194
- }
195
- const KateXBlockRule : MarkdownToJSX . Rule = {
196
- ...__KateXBlockRule ,
197
- react ( node , _ , state ?) {
198
- return < NotSupportRender key = { state ?. key } />
199
- } ,
200
- }
220
+ // const KateXRule: MarkdownToJSX.Rule = {
221
+ // ...__KateXRule,
222
+ // react(node, _, state?) {
223
+ // return node
224
+ // },
225
+ // }
226
+ // const KateXBlockRule: MarkdownToJSX.Rule = {
227
+ // ...__KateXBlockRule,
228
+ // react(node, _, state?) {
229
+ // return <NotSupportRender key={state?.key} />
230
+ // },
231
+ // }
201
232
202
233
const AlertsRule : MarkdownToJSX . Rule = {
203
234
...__AlertsRule ,
204
235
react ( node , output , state ) {
205
- return < NotSupportRender key = { state ?. key } />
236
+ const { body } = node . parsed
237
+ const bodyClean = body . replaceAll ( / ^ > * / gm, '' ) . trim ( )
238
+
239
+ return < blockquote key = { state . key } > { compiler ( bodyClean ) } </ blockquote >
206
240
} ,
207
241
}
208
242
0 commit comments