mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-29 23:16:51 +00:00
修复部分NOTION_CONFIG读取问题
This commit is contained in:
@@ -14,15 +14,38 @@ import { deepClone } from './utils'
|
||||
* @param {*} extendConfig ; 参考配置对象{key:val},如果notion中找不到优先尝试在这里面查找
|
||||
* @returns
|
||||
*/
|
||||
export const siteConfig = (key, defaultVal = null, extendConfig = null) => {
|
||||
let global = null
|
||||
export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
|
||||
if (!key) {
|
||||
return null
|
||||
}
|
||||
|
||||
// 特殊配置处理;某些配置只在服务端生效;而Global的NOTION_CONFIG仅限前端组件使用,因此需要从extendConfig中读取
|
||||
switch (key) {
|
||||
case 'NEXT_REVALIDATE_SECOND':
|
||||
case 'POST_RECOMMEND_COUNT':
|
||||
case 'IMAGE_COMPRESS_WIDTH':
|
||||
case 'PSEUDO_STATIC':
|
||||
case 'POSTS_SORT_BY':
|
||||
case 'POSTS_PER_PAGE':
|
||||
case 'POST_PREVIEW_LINES':
|
||||
case 'POST_URL_PREFIX':
|
||||
case 'POST_LIST_STYLE':
|
||||
case 'POST_LIST_PREVIEW':
|
||||
case 'POST_URL_PREFIX_MAPPING_CATEGORY':
|
||||
return convertVal(extendConfig[key] || defaultVal || BLOG[key])
|
||||
default:
|
||||
}
|
||||
|
||||
let global = {}
|
||||
try {
|
||||
const isClient = typeof window !== 'undefined'
|
||||
// const isClient = typeof window !== 'undefined'
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
global = isClient ? useGlobal() : {}
|
||||
global = useGlobal()
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
// global = useGlobal()
|
||||
} catch (error) {}
|
||||
} catch (error) {
|
||||
console.warn('SiteConfig警告', key, error)
|
||||
}
|
||||
|
||||
// 首先 配置最优先读取NOTION中的表格配置
|
||||
let val = null
|
||||
@@ -66,6 +89,16 @@ export const siteConfig = (key, defaultVal = null, extendConfig = null) => {
|
||||
}
|
||||
|
||||
// 从Notion_CONFIG读取的配置通常都是字符串,适当转义
|
||||
return convertVal(val)
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置默认都是string类型;
|
||||
* 识别配置的值是否数字、布尔、[]数组,若是则转成对应类型
|
||||
* @param {*} val
|
||||
* @returns
|
||||
*/
|
||||
export const convertVal = val => {
|
||||
if (typeof val === 'string') {
|
||||
// 解析布尔
|
||||
if (val === 'true' || val === 'false') {
|
||||
|
||||
@@ -236,12 +236,13 @@ function getCategoryOptions(schema) {
|
||||
* @param from
|
||||
* @returns {Promise<{title,description,pageCover,icon}>}
|
||||
*/
|
||||
function getSiteInfo({ collection, block, NOTION_CONFIG, pageId }) {
|
||||
const defaultTitle = siteConfig('TITLE', '', NOTION_CONFIG)
|
||||
const defaultDescription = siteConfig('DESCRIPTION', '', NOTION_CONFIG)
|
||||
const defaultPageCover = siteConfig('HOME_BANNER_IMAGE', '', NOTION_CONFIG)
|
||||
const defaultIcon = siteConfig('AVATAR', '', NOTION_CONFIG)
|
||||
const defaultLink = siteConfig('LINK', '', NOTION_CONFIG)
|
||||
function getSiteInfo({ collection, block, NOTION_CONFIG }) {
|
||||
const defaultTitle = NOTION_CONFIG?.TITLE || BLOG.TITLE
|
||||
const defaultDescription = NOTION_CONFIG?.DESCRIPTION || BLOG.DESCRIPTION
|
||||
const defaultPageCover =
|
||||
NOTION_CONFIG?.HOME_BANNER_IMAGE || BLOG.HOME_BANNER_IMAGE
|
||||
const defaultIcon = NOTION_CONFIG?.AVATAR || BLOG.AVATAR
|
||||
const defaultLink = NOTION_CONFIG?.LINK || BLOG.LINK
|
||||
if (!collection && !block) {
|
||||
return {
|
||||
title: defaultTitle,
|
||||
|
||||
@@ -186,7 +186,7 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
|
||||
}
|
||||
|
||||
// 开启伪静态路径
|
||||
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
|
||||
if (JSON.parse(NOTION_CONFIG?.PSEUDO_STATIC || BLOG.PSEUDO_STATIC)) {
|
||||
if (
|
||||
!properties?.href?.endsWith('.html') &&
|
||||
!properties?.href?.startsWith('http')
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import fs from 'fs'
|
||||
import { siteConfig } from './config'
|
||||
|
||||
export async function generateRobotsTxt(NOTION_CONFIG) {
|
||||
const LINK = siteConfig('LINK', '', NOTION_CONFIG)
|
||||
export async function generateRobotsTxt(props) {
|
||||
const { siteInfo } = props
|
||||
const LINK = siteInfo?.link
|
||||
const content = `
|
||||
# *
|
||||
User-agent: *
|
||||
|
||||
39
lib/rss.js
39
lib/rss.js
@@ -1,9 +1,9 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import NotionPage from '@/components/NotionPage'
|
||||
import { getPostBlocks } from '@/lib/db/getSiteData'
|
||||
import { Feed } from 'feed'
|
||||
import fs from 'fs'
|
||||
import ReactDOMServer from 'react-dom/server'
|
||||
import { siteConfig } from './config'
|
||||
|
||||
/**
|
||||
* 生成RSS内容
|
||||
@@ -25,30 +25,33 @@ const createFeedContent = async post => {
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateRss(NOTION_CONFIG, posts) {
|
||||
const link = siteConfig('LINK', '', NOTION_CONFIG)
|
||||
const author = siteConfig('AUTHOR', '', NOTION_CONFIG)
|
||||
const lang = siteConfig('LANG', '', NOTION_CONFIG)
|
||||
const subPath = siteConfig('SUB_PATH', '', NOTION_CONFIG)
|
||||
|
||||
export async function generateRss(props) {
|
||||
const { NOTION_CONFIG, siteInfo, latestPosts } = props
|
||||
const TITLE = siteInfo?.title
|
||||
const DESCRIPTION = siteInfo?.description
|
||||
const LINK = siteInfo?.link
|
||||
const AUTHOR = NOTION_CONFIG?.AUTHOR || BLOG.AUTHOR
|
||||
const LANG = NOTION_CONFIG?.LANG || BLOG.LANG
|
||||
const SUB_PATH = NOTION_CONFIG?.SUB_PATH || BLOG.SUB_PATH
|
||||
const CONTACT_EMAIL = NOTION_CONFIG?.CONTACT_EMAIL || BLOG.CONTACT_EMAIL
|
||||
const year = new Date().getFullYear()
|
||||
const feed = new Feed({
|
||||
title: siteConfig('TITLE', '', NOTION_CONFIG),
|
||||
description: siteConfig('DESCRIPTION', '', NOTION_CONFIG),
|
||||
link: `${link}/${subPath}`,
|
||||
language: lang,
|
||||
favicon: `${link}/favicon.png`,
|
||||
copyright: `All rights reserved ${year}, ${author}`,
|
||||
title: TITLE,
|
||||
description: DESCRIPTION,
|
||||
link: `${LINK}/${SUB_PATH}`,
|
||||
language: LANG,
|
||||
favicon: `${LINK}/favicon.png`,
|
||||
copyright: `All rights reserved ${year}, ${AUTHOR}`,
|
||||
author: {
|
||||
name: author,
|
||||
email: siteConfig('CONTACT_EMAIL', '', NOTION_CONFIG),
|
||||
link: link
|
||||
name: AUTHOR,
|
||||
email: CONTACT_EMAIL,
|
||||
link: LINK
|
||||
}
|
||||
})
|
||||
for (const post of posts) {
|
||||
for (const post of latestPosts) {
|
||||
feed.addItem({
|
||||
title: post.title,
|
||||
link: `${link}/${post.slug}`,
|
||||
link: `${LINK}/${post.slug}`,
|
||||
description: post.summary,
|
||||
content: await createFeedContent(post),
|
||||
date: new Date(post?.publishDay)
|
||||
|
||||
Reference in New Issue
Block a user