mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-06 23:16:52 +00:00
@@ -214,6 +214,9 @@ const BLOG = {
|
|||||||
icon: process.env.NEXT_PUBLIC_NOTION_PROPERTY_ICON || 'icon'
|
icon: process.env.NEXT_PUBLIC_NOTION_PROPERTY_ICON || 'icon'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// RSS
|
||||||
|
ENABLE_RSS: process.env.NEXT_PUBLIC_ENABLE_RSS || true, // 是否开启RSS订阅功能
|
||||||
|
|
||||||
// 作废配置
|
// 作废配置
|
||||||
AVATAR: process.env.NEXT_PUBLIC_AVATAR || '/avatar.png', // 作者头像,被notion中的ICON覆盖。若无ICON则取public目录下的avatar.png
|
AVATAR: process.env.NEXT_PUBLIC_AVATAR || '/avatar.png', // 作者头像,被notion中的ICON覆盖。若无ICON则取public目录下的avatar.png
|
||||||
TITLE: process.env.NEXT_PUBLIC_TITLE || 'NotionNext BLOG', // 站点标题 ,被notion中的页面标题覆盖
|
TITLE: process.env.NEXT_PUBLIC_TITLE || 'NotionNext BLOG', // 站点标题 ,被notion中的页面标题覆盖
|
||||||
|
|||||||
36
lib/rss.js
36
lib/rss.js
@@ -5,21 +5,6 @@ import ReactDOMServer from 'react-dom/server'
|
|||||||
import { getPostBlocks } from './notion'
|
import { getPostBlocks } from './notion'
|
||||||
import NotionPage from '@/components/NotionPage'
|
import NotionPage from '@/components/NotionPage'
|
||||||
|
|
||||||
const createFeedContent = async post => {
|
|
||||||
// 加密的文章内容只返回摘要
|
|
||||||
if (post.password && post.password !== '') {
|
|
||||||
return post.summary
|
|
||||||
}
|
|
||||||
const blockMap = await getPostBlocks(post.id, 'rss-content')
|
|
||||||
if (blockMap) {
|
|
||||||
post.blockMap = blockMap
|
|
||||||
const content = ReactDOMServer.renderToString(<NotionPage post={post} />)
|
|
||||||
const regexExp =
|
|
||||||
/<div class="notion-collection-row"><div class="notion-collection-row-body"><div class="notion-collection-row-property"><div class="notion-collection-column-title"><svg.*?class="notion-collection-column-title-icon">.*?<\/svg><div class="notion-collection-column-title-body">.*?<\/div><\/div><div class="notion-collection-row-value">.*?<\/div><\/div><\/div><\/div>/g
|
|
||||||
return content.replace(regexExp, '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function generateRss(posts) {
|
export async function generateRss(posts) {
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
const feed = new Feed({
|
const feed = new Feed({
|
||||||
@@ -38,7 +23,6 @@ export async function generateRss(posts) {
|
|||||||
for (const post of posts) {
|
for (const post of posts) {
|
||||||
feed.addItem({
|
feed.addItem({
|
||||||
title: post.title,
|
title: post.title,
|
||||||
guid: `${post.id}`,
|
|
||||||
link: `${BLOG.LINK}/${post.slug}`,
|
link: `${BLOG.LINK}/${post.slug}`,
|
||||||
description: post.summary,
|
description: post.summary,
|
||||||
content: await createFeedContent(post),
|
content: await createFeedContent(post),
|
||||||
@@ -51,3 +35,23 @@ export async function generateRss(posts) {
|
|||||||
fs.writeFileSync('./public/rss/atom.xml', feed.atom1())
|
fs.writeFileSync('./public/rss/atom.xml', feed.atom1())
|
||||||
fs.writeFileSync('./public/rss/feed.json', feed.json1())
|
fs.writeFileSync('./public/rss/feed.json', feed.json1())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成RSS内容
|
||||||
|
* @param {*} post
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const createFeedContent = async post => {
|
||||||
|
// 加密的文章内容只返回摘要
|
||||||
|
if (post.password && post.password !== '') {
|
||||||
|
return post.summary
|
||||||
|
}
|
||||||
|
const blockMap = await getPostBlocks(post.id, 'rss-content')
|
||||||
|
if (blockMap) {
|
||||||
|
post.blockMap = blockMap
|
||||||
|
const content = ReactDOMServer.renderToString(<NotionPage post={post} />)
|
||||||
|
const regexExp =
|
||||||
|
/<div class="notion-collection-row"><div class="notion-collection-row-body"><div class="notion-collection-row-property"><div class="notion-collection-column-title"><svg.*?class="notion-collection-column-title-icon">.*?<\/svg><div class="notion-collection-column-title-body">.*?<\/div><\/div><div class="notion-collection-row-value">.*?<\/div><\/div><\/div><\/div>/g
|
||||||
|
return content.replace(regexExp, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ export async function getStaticProps() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 异步生成Feed订阅
|
// 生成Feed订阅
|
||||||
generateRss(props?.latestPosts || [])
|
if (JSON.parse(BLOG.ENABLE_RSS)) {
|
||||||
|
generateRss(props?.latestPosts || [])
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ const NavBar = props => {
|
|||||||
|
|
||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
let links = [
|
let links = [
|
||||||
{ id: 2, name: locale.NAV.RSS, to: '/feed', show: CONFIG_NOBELIUM.MENU_RSS, target: '_blank' },
|
{ id: 2, name: locale.NAV.RSS, to: '/feed', show: BLOG.ENABLE_RSS && CONFIG_NOBELIUM.MENU_RSS, target: '_blank' },
|
||||||
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_NOBELIUM.MENU_SEARCH },
|
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_NOBELIUM.MENU_SEARCH },
|
||||||
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_NOBELIUM.MENU_ARCHIVE },
|
{ icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG_NOBELIUM.MENU_ARCHIVE },
|
||||||
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_NOBELIUM.MENU_CATEGORY },
|
{ icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG_NOBELIUM.MENU_CATEGORY },
|
||||||
|
|||||||
Reference in New Issue
Block a user