From d1ee0c156cee86e05bb9bd83884de7bb49585c06 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 21 Feb 2023 12:43:57 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B0=83=E6=95=B4RSS=E6=96=B9=E6=A1=88?= =?UTF-8?q?=EF=BC=8C=E8=8A=82=E7=9C=81=E6=B5=81=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- lib/rss.js | 7 ++++++- next.config.js | 10 ++++++++++ pages/feed/index.js | 17 ----------------- pages/index.js | 6 ++++++ 5 files changed, 24 insertions(+), 19 deletions(-) delete mode 100644 pages/feed/index.js 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/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, From 784baed739afb6cbe27fc62041ab4e14803b67a4 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 21 Feb 2023 13:09:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Nobelium=20=E6=94=AF=E6=8C=81=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/nobelium/components/Nav.js | 40 +++++++-------------------- themes/nobelium/components/SvgIcon.js | 29 +++++++++++++++++++ themes/nobelium/config_nobelium.js | 5 +++- 3 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 themes/nobelium/components/SvgIcon.js 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 From 1b5c603a3e325e135f0594ef1051ec70862389eb Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 21 Feb 2023 13:10:39 +0800 Subject: [PATCH 3/3] 3.11.0 --- .env.local | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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": {