mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-29 15:10:06 +00:00
RSS 调整,支持开关、隐藏id
This commit is contained in:
36
lib/rss.js
36
lib/rss.js
@@ -5,21 +5,6 @@ import ReactDOMServer from 'react-dom/server'
|
||||
import { getPostBlocks } from './notion'
|
||||
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) {
|
||||
const year = new Date().getFullYear()
|
||||
const feed = new Feed({
|
||||
@@ -38,7 +23,6 @@ export async function generateRss(posts) {
|
||||
for (const post of posts) {
|
||||
feed.addItem({
|
||||
title: post.title,
|
||||
guid: `${post.id}`,
|
||||
link: `${BLOG.LINK}/${post.slug}`,
|
||||
description: post.summary,
|
||||
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/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, '')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user