调整RSS方案,节省流量

This commit is contained in:
tangly1024.com
2023-02-21 12:43:57 +08:00
parent 957b9c4cdb
commit d1ee0c156c
5 changed files with 24 additions and 19 deletions

View File

@@ -1,17 +0,0 @@
import { generateRss } from '@/lib/rss'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
export async function getServerSideProps ({ res }) {
res.setHeader('Content-Type', 'text/xml')
// 获取最新文章
const globalNotionData = await getGlobalNotionData({ from: 'rss' })
const xmlFeed = await generateRss(globalNotionData?.latestPosts || [])
res.write(xmlFeed)
res.end()
return {
props: {}
}
}
const feed = () => null
export default feed

View File

@@ -3,6 +3,7 @@ import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import * as ThemeMap from '@/themes'
import { useGlobal } from '@/lib/global'
import { generateRss } from '@/lib/rss'
const Index = props => {
const { theme } = useGlobal()
const ThemeComponents = ThemeMap[theme]
@@ -12,8 +13,10 @@ const Index = props => {
export async function getStaticProps() {
const from = 'index'
const props = await getGlobalNotionData({ from })
const { siteInfo } = props
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
delete props.allPages
const meta = {
title: `${siteInfo?.title} | ${siteInfo?.description}`,
@@ -40,6 +43,9 @@ export async function getStaticProps() {
}
}
// 异步生成Feed订阅
generateRss(props?.latestPosts || [])
return {
props: {
meta,