1
+ import BLOG from '@/blog.config'
1
2
import NotionPage from '@/components/NotionPage'
2
3
import { getPostBlocks } from '@/lib/db/getSiteData'
3
4
import { Feed } from 'feed'
4
5
import fs from 'fs'
5
6
import ReactDOMServer from 'react-dom/server'
6
- import { siteConfig } from './config'
7
7
8
8
/**
9
9
* 生成RSS内容
@@ -25,30 +25,33 @@ const createFeedContent = async post => {
25
25
}
26
26
}
27
27
28
- export async function generateRss ( NOTION_CONFIG , posts ) {
29
- const link = siteConfig ( 'LINK' , '' , NOTION_CONFIG )
30
- const author = siteConfig ( 'AUTHOR' , '' , NOTION_CONFIG )
31
- const lang = siteConfig ( 'LANG' , '' , NOTION_CONFIG )
32
- const subPath = siteConfig ( 'SUB_PATH' , '' , NOTION_CONFIG )
33
-
28
+ export async function generateRss ( props ) {
29
+ const { NOTION_CONFIG , siteInfo, latestPosts } = props
30
+ const TITLE = siteInfo ?. title
31
+ const DESCRIPTION = siteInfo ?. description
32
+ const LINK = siteInfo ?. link
33
+ const AUTHOR = NOTION_CONFIG ?. AUTHOR || BLOG . AUTHOR
34
+ const LANG = NOTION_CONFIG ?. LANG || BLOG . LANG
35
+ const SUB_PATH = NOTION_CONFIG ?. SUB_PATH || BLOG . SUB_PATH
36
+ const CONTACT_EMAIL = NOTION_CONFIG ?. CONTACT_EMAIL || BLOG . CONTACT_EMAIL
34
37
const year = new Date ( ) . getFullYear ( )
35
38
const feed = new Feed ( {
36
- title : siteConfig ( ' TITLE' , '' , NOTION_CONFIG ) ,
37
- description : siteConfig ( ' DESCRIPTION' , '' , NOTION_CONFIG ) ,
38
- link : `${ link } /${ subPath } ` ,
39
- language : lang ,
40
- favicon : `${ link } /favicon.png` ,
41
- copyright : `All rights reserved ${ year } , ${ author } ` ,
39
+ title : TITLE ,
40
+ description : DESCRIPTION ,
41
+ link : `${ LINK } /${ SUB_PATH } ` ,
42
+ language : LANG ,
43
+ favicon : `${ LINK } /favicon.png` ,
44
+ copyright : `All rights reserved ${ year } , ${ AUTHOR } ` ,
42
45
author : {
43
- name : author ,
44
- email : siteConfig ( ' CONTACT_EMAIL' , '' , NOTION_CONFIG ) ,
45
- link : link
46
+ name : AUTHOR ,
47
+ email : CONTACT_EMAIL ,
48
+ link : LINK
46
49
}
47
50
} )
48
- for ( const post of posts ) {
51
+ for ( const post of latestPosts ) {
49
52
feed . addItem ( {
50
53
title : post . title ,
51
- link : `${ link } /${ post . slug } ` ,
54
+ link : `${ LINK } /${ post . slug } ` ,
52
55
description : post . summary ,
53
56
content : await createFeedContent ( post ) ,
54
57
date : new Date ( post ?. publishDay )
0 commit comments