diff --git a/.env.local b/.env.local index fabac875..9770227a 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.0 +NEXT_PUBLIC_VERSION=3.10.1 diff --git a/components/NotionPage.js b/components/NotionPage.js index 4b7f2808..8328598e 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -3,11 +3,10 @@ import dynamic from 'next/dynamic' import mediumZoom from '@fisch0920/medium-zoom' import React from 'react' import { isBrowser } from '@/lib/utils' -import Image from 'next/image' -import Link from 'next/link' import { Code } from 'react-notion-x/build/third-party/code' import 'katex/dist/katex.min.css' +import { mapImgUrl } from '@/lib/notion/mapImage' const Equation = dynamic(() => import('@/components/Equation').then(async (m) => { @@ -84,14 +83,13 @@ const NotionPage = ({ post, className }) => { diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 2ea7d518..444de1d4 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -2,12 +2,12 @@ import BLOG from '@/blog.config' import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager' import { getPostBlocks } from '@/lib/notion/getPostBlocks' import { idToUuid } from 'notion-utils' -import { defaultMapImageUrl } from 'react-notion-x' import { deepClone } from '../utils' import { getAllCategories } from './getAllCategories' import getAllPageIds from './getAllPageIds' import { getAllTags } from './getAllTags' import getPageProperties from './getPageProperties' +import { mapImgUrl } from './mapImage' /** * 获取博客数据 @@ -129,46 +129,15 @@ function getBlogInfo({ collection, block }) { const title = collection?.name?.[0][0] || BLOG.TITLE const description = collection?.description ? Object.assign(collection).description[0][0] : BLOG.DESCRIPTION const pageCover = collection?.cover ? (mapImgUrl(collection?.cover, block[idToUuid(BLOG.NOTION_PAGE_ID)]?.value)) : BLOG.HOME_BANNER_IMAGE - const icon = collection?.icon ? (mapCollectionImg(collection?.icon, collection)) : BLOG.AVATAR + let icon = collection?.icon ? (mapImgUrl(collection?.icon, collection)) : BLOG.AVATAR + // 站点图标不能是emoji情 + const emojiPattern = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g + if (emojiPattern.test(icon)) { + icon = BLOG.AVATAR + } return { title, description, pageCover, icon } } -/** - * Notion图片映射 - * @param pageCover - * @returns {string} - */ -const mapImgUrl = (img, value) => { - if (img) { - if (img.startsWith('/')) return 'https://www.notion.so' + img - if (img.startsWith('http')) return defaultMapImageUrl(img, value) - } -} - -/** - * collection 图片映射 - * @param {*} img - * @param {*} value - * @returns - */ -const mapCollectionImg = (img, value) => { - if (img) { - if (img.startsWith('/')) return 'https://www.notion.so' + img - if (img.startsWith('http')) { - return 'https://www.notion.so/image/' + encodeURIComponent(img) + '?table=collection&id=' + value.id - } - // 判断是否含有emoji表情 - const emojiPattern = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g - if (emojiPattern.test(img)) { - console.error('请不要使用emoji作为站点图标', img) - return BLOG.AVATAR - } - - console.error('非法的站点图标', img) - return BLOG.AVATAR - } -} - async function getNotice(post) { if (!post) { return null diff --git a/lib/notion/mapImage.js b/lib/notion/mapImage.js new file mode 100644 index 00000000..856a0806 --- /dev/null +++ b/lib/notion/mapImage.js @@ -0,0 +1,33 @@ +/** + * Notion图片映射处理有emjji的图标 + * @param {*} img + * @param {*} value + * @returns + */ +const mapImgUrl = (img, block) => { + let ret = null + if (!img) { + return ret + } + // 相对目录,则视为notion的自带图片 + if (img.startsWith('/')) ret = 'https://www.notion.so' + img + + // 书签的地址本身就是永久链接,无需处理 + if (!ret && block?.type === 'bookmark') { + ret = img + } + + // notion永久图床地址 + if (!ret && img.indexOf('secure.notion-static.com') > 0) { + ret = 'https://www.notion.so/image/' + encodeURIComponent(img) + '?table=block&id=' + block.id + } + + // 剩余的是第三方图片url或emoji + if (!ret) { + ret = img + } + + return ret +} + +export { mapImgUrl } diff --git a/package.json b/package.json index 97f245a8..f30999c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "3.10.0", + "version": "3.10.1", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": { diff --git a/themes/example/components/Announcement.js b/themes/example/components/Announcement.js new file mode 100644 index 00000000..01ec60c3 --- /dev/null +++ b/themes/example/components/Announcement.js @@ -0,0 +1,20 @@ +import dynamic from 'next/dynamic' + +const NotionPage = dynamic(() => import('@/components/NotionPage')) + +const Announcement = ({ post, className }) => { + if (!post) { + return <> + } + return +} +export default Announcement diff --git a/themes/example/components/SideBar.js b/themes/example/components/SideBar.js index 574bf230..39ffead7 100644 --- a/themes/example/components/SideBar.js +++ b/themes/example/components/SideBar.js @@ -3,11 +3,12 @@ import Live2D from '@/components/Live2D' import { useGlobal } from '@/lib/global' import Link from 'next/link' import dynamic from 'next/dynamic' +import Announcement from './Announcement' const ExampleRecentComments = dynamic(() => import('./ExampleRecentComments')) export const SideBar = (props) => { const { locale } = useGlobal() - const { latestPosts, categoryOptions } = props + const { latestPosts, categoryOptions, notice } = props return (
@@ -48,6 +49,8 @@ export const SideBar = (props) => {
+ + {BLOG.COMMENT_WALINE_SERVER_URL && BLOG.COMMENT_WALINE_RECENT &&