File tree 5 files changed +24
-19
lines changed
5 files changed +24
-19
lines changed Original file line number Diff line number Diff line change @@ -43,4 +43,5 @@ yarn-error.log*
43
43
44
44
# sitemap
45
45
/public /robots.txt
46
- /public /sitemap.xml
46
+ /public /sitemap.xml
47
+ /public /rss /*
Original file line number Diff line number Diff line change
1
+ import fs from 'fs'
1
2
import { Feed } from 'feed'
2
3
import BLOG from '@/blog.config'
3
4
import ReactDOMServer from 'react-dom/server'
@@ -44,5 +45,9 @@ export async function generateRss(posts) {
44
45
date : new Date ( post ?. date ?. start_date || post ?. createdTime )
45
46
} )
46
47
}
47
- return feed . atom1 ( )
48
+
49
+ fs . mkdirSync ( './public/rss' , { recursive : true } )
50
+ fs . writeFileSync ( './public/rss/feed.xml' , feed . rss2 ( ) )
51
+ fs . writeFileSync ( './public/rss/atom.xml' , feed . atom1 ( ) )
52
+ fs . writeFileSync ( './public/rss/feed.json' , feed . json1 ( ) )
48
53
}
Original file line number Diff line number Diff line change @@ -14,6 +14,16 @@ module.exports = withBundleAnalyzer({
14
14
'images.unsplash.com'
15
15
]
16
16
} ,
17
+ // 默认将feed重定向至 /public/rss/feed.xml
18
+ async redirects ( ) {
19
+ return [
20
+ {
21
+ source : '/feed' ,
22
+ destination : '/rss/feed.xml' ,
23
+ permanent : true
24
+ }
25
+ ]
26
+ } ,
17
27
async rewrites ( ) {
18
28
return [
19
29
{
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { getPostBlocks } from '@/lib/notion'
3
3
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
4
4
import * as ThemeMap from '@/themes'
5
5
import { useGlobal } from '@/lib/global'
6
+ import { generateRss } from '@/lib/rss'
6
7
const Index = props => {
7
8
const { theme } = useGlobal ( )
8
9
const ThemeComponents = ThemeMap [ theme ]
@@ -12,8 +13,10 @@ const Index = props => {
12
13
export async function getStaticProps ( ) {
13
14
const from = 'index'
14
15
const props = await getGlobalNotionData ( { from } )
16
+
15
17
const { siteInfo } = props
16
18
props . posts = props . allPages . filter ( page => page . type === 'Post' && page . status === 'Published' )
19
+
17
20
delete props . allPages
18
21
const meta = {
19
22
title : `${ siteInfo ?. title } | ${ siteInfo ?. description } ` ,
@@ -40,6 +43,9 @@ export async function getStaticProps() {
40
43
}
41
44
}
42
45
46
+ // 异步生成Feed订阅
47
+ generateRss ( props ?. latestPosts || [ ] )
48
+
43
49
return {
44
50
props : {
45
51
meta,
You can’t perform that action at this time.
0 commit comments