diff --git a/.env.local b/.env.local index 6c7c4fca..490200b3 100644 --- a/.env.local +++ b/.env.local @@ -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 diff --git a/.gitignore b/.gitignore index a1a007c3..332741bc 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,5 @@ yarn-error.log* # sitemap /public/robots.txt -/public/sitemap.xml \ No newline at end of file +/public/sitemap.xml +/public/rss/* \ No newline at end of file diff --git a/lib/rss.js b/lib/rss.js index 9019f061..68214659 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -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()) } diff --git a/next.config.js b/next.config.js index fb92a754..33b66908 100644 --- a/next.config.js +++ b/next.config.js @@ -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 [ { diff --git a/package.json b/package.json index 798a5ca0..d3d82615 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pages/feed/index.js b/pages/feed/index.js deleted file mode 100644 index 127f9402..00000000 --- a/pages/feed/index.js +++ /dev/null @@ -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 diff --git a/pages/index.js b/pages/index.js index 952eadb6..a26d57bd 100644 --- a/pages/index.js +++ b/pages/index.js @@ -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, diff --git a/themes/nobelium/components/Nav.js b/themes/nobelium/components/Nav.js index f35b60b1..6c6951ea 100644 --- a/themes/nobelium/components/Nav.js +++ b/themes/nobelium/components/Nav.js @@ -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 => {
- - - - - - - - - - + {/* */} + {CONFIG_NOBELIUM.NAV_NOTION_ICON + /* eslint-disable-next-line @next/next/no-img-element */ + ? {BLOG.AUTHOR}/ + : } +
@@ -80,8 +60,8 @@ const Nav = props => { ) : (

- {BLOG.title},{' '} - {BLOG.description} + {siteInfo?.title} + {/* ,{' '}{siteInfo?.description} */}

)} diff --git a/themes/nobelium/components/SvgIcon.js b/themes/nobelium/components/SvgIcon.js new file mode 100644 index 00000000..1ae326ca --- /dev/null +++ b/themes/nobelium/components/SvgIcon.js @@ -0,0 +1,29 @@ +export const SvgIcon = () => { + return + + + + + + + + + +} diff --git a/themes/nobelium/config_nobelium.js b/themes/nobelium/config_nobelium.js index 5ceff76c..0385e9d7 100644 --- a/themes/nobelium/config_nobelium.js +++ b/themes/nobelium/config_nobelium.js @@ -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