Merge pull request #795 from tangly1024/feat_rss

3.11.0 Feat rss
This commit is contained in:
tangly1024
2023-02-21 13:11:12 +08:00
committed by GitHub
10 changed files with 69 additions and 52 deletions

View File

@@ -1,2 +1,2 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=3.10.2
NEXT_PUBLIC_VERSION=3.11.0

3
.gitignore vendored
View File

@@ -43,4 +43,5 @@ yarn-error.log*
# sitemap
/public/robots.txt
/public/sitemap.xml
/public/sitemap.xml
/public/rss/*

View File

@@ -1,3 +1,4 @@
import fs from 'fs'
import { Feed } from 'feed'
import BLOG from '@/blog.config'
import ReactDOMServer from 'react-dom/server'
@@ -44,5 +45,9 @@ export async function generateRss(posts) {
date: new Date(post?.date?.start_date || post?.createdTime)
})
}
return feed.atom1()
fs.mkdirSync('./public/rss', { recursive: true })
fs.writeFileSync('./public/rss/feed.xml', feed.rss2())
fs.writeFileSync('./public/rss/atom.xml', feed.atom1())
fs.writeFileSync('./public/rss/feed.json', feed.json1())
}

View File

@@ -14,6 +14,16 @@ module.exports = withBundleAnalyzer({
'images.unsplash.com'
]
},
// 默认将feed重定向至 /public/rss/feed.xml
async redirects() {
return [
{
source: '/feed',
destination: '/rss/feed.xml',
permanent: true
}
]
},
async rewrites() {
return [
{

View File

@@ -1,6 +1,6 @@
{
"name": "notion-next",
"version": "3.10.2",
"version": "3.11.0",
"homepage": "https://github.com/tangly1024/NotionNext.git",
"license": "MIT",
"repository": {

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,

View File

@@ -3,9 +3,10 @@ import Link from 'next/link'
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import CONFIG_NOBELIUM from '../config_nobelium'
import { SvgIcon } from './SvgIcon'
const Nav = props => {
const { navBarTitle, fullWidth } = props
const { navBarTitle, fullWidth, siteInfo } = props
const useSticky = !BLOG.autoCollapsedNavBar
const navRef = useRef(null)
const sentinalRef = useRef([])
@@ -42,33 +43,12 @@ const Nav = props => {
<Link href="/" aria-label={BLOG.title}>
<div className="h-6">
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<rect
width="24"
height="24"
className="fill-current text-black dark:text-white"
/>
<rect width="24" height="24" fill="url(#paint0_radial)" />
<defs>
<radialGradient
id="paint0_radial"
cx="0"
cy="0"
r="1"
gradientUnits="userSpaceOnUse"
gradientTransform="rotate(45) scale(39.598)"
>
<stop stopColor="#CFCFCF" stopOpacity="0.6" />
<stop offset="1" stopColor="#E9E9E9" stopOpacity="0" />
</radialGradient>
</defs>
</svg>
{/* <SvgIcon/> */}
{CONFIG_NOBELIUM.NAV_NOTION_ICON
/* eslint-disable-next-line @next/next/no-img-element */
? <img src={siteInfo?.icon} width={24} height={24} alt={BLOG.AUTHOR}/>
: <SvgIcon/>}
</div>
</Link>
@@ -80,8 +60,8 @@ const Nav = props => {
)
: (
<p className="ml-2 font-medium text-day dark:text-night header-name">
{BLOG.title},{' '}
<span className="font-normal">{BLOG.description}</span>
{siteInfo?.title}
{/* ,{' '}<span className="font-normal">{siteInfo?.description}</span> */}
</p>
)}
</div>

View File

@@ -0,0 +1,29 @@
export const SvgIcon = () => {
return <svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<rect
width="24"
height="24"
className="fill-current text-black dark:text-white"
/>
<rect width="24" height="24" fill="url(#paint0_radial)" />
<defs>
<radialGradient
id="paint0_radial"
cx="0"
cy="0"
r="1"
gradientUnits="userSpaceOnUse"
gradientTransform="rotate(45) scale(39.598)"
>
<stop stopColor="#CFCFCF" stopOpacity="0.6" />
<stop offset="1" stopColor="#E9E9E9" stopOpacity="0" />
</radialGradient>
</defs>
</svg>
}

View File

@@ -5,6 +5,9 @@ const CONFIG_NOBELIUM = {
MENU_TAG: true, // 显示标签
MENU_ARCHIVE: false, // 显示归档
MENU_SEARCH: true, // 显示搜索
MENU_RSS: false // 显示订阅
MENU_RSS: false, // 显示订阅
NAV_NOTION_ICON: true // 是否读取Notion图标作为站点头像
}
export default CONFIG_NOBELIUM