From 87440ea140f9ca9a4914696a4ebf3a16315bf07c Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 25 Apr 2022 16:01:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E9=83=A8=E5=BC=95=E7=94=A8=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=AF=E4=BB=A5=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/NotionPage.js | 8 +++++++- lib/utils.js | 11 ++++++++++- pages/article/[slug].js | 7 +++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/components/NotionPage.js b/components/NotionPage.js index 0930eef4..03b1f1eb 100644 --- a/components/NotionPage.js +++ b/components/NotionPage.js @@ -75,8 +75,14 @@ const NotionPage = ({ post }) => { } +/** + * 将id映射成博文内部链接。 + * @param {*} id + * @returns + */ const mapPageUrl = id => { - return 'https://www.notion.so/' + id.replace(/-/g, '') + // return 'https://www.notion.so/' + id.replace(/-/g, '') + return '/article/' + id.replace(/-/g, '') } function getMediumZoomMargin() { diff --git a/lib/utils.js b/lib/utils.js index be47e17f..be9db197 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -64,10 +64,19 @@ export function mergeDeep(target, ...sources) { } /** - * 对象检查 + * 是否对象 * @param item * @returns {boolean} */ export function isObject(item) { return (item && typeof item === 'object' && !Array.isArray(item)) } + +/** + * 是否可迭代 + * @param {*} obj + * @returns + */ +export function isIterable(obj) { + return obj != null && typeof obj[Symbol.iterator] === 'function' +} diff --git a/pages/article/[slug].js b/pages/article/[slug].js index b190738d..538cbc90 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -5,6 +5,7 @@ import { useGlobal } from '@/lib/global' import * as ThemeMap from '@/themes' import { useEffect, useState } from 'react' import { useRouter } from 'next/router' +import { idToUuid } from 'notion-utils' /** * 根据notion的slug访问页面 @@ -30,7 +31,7 @@ const Slug = props => { } }, 3000) }) - const meta = { title: `${props?.siteInfo?.title} | loading` } + const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading` } return } @@ -92,7 +93,9 @@ export async function getStaticProps({ params: { slug } }) { const from = `slug-props-${slug}` const props = await getGlobalNotionData({ from, pageType: ['Post'] }) const allPosts = props.allPosts - props.post = props.allPosts.find(p => p.slug === slug) + props.post = props.allPosts.find((p) => { + return p.slug === slug || p.id === idToUuid(slug) + }) if (!props.post) { return { props, revalidate: 1 } }