From f568bc32ecd5ee2991c78bb8345399e5f970d66d Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Fri, 2 Feb 2024 11:32:27 +0800 Subject: [PATCH] fix build failed on post external slug --- lib/utils.js | 4 ++-- pages/[prefix]/[slug]/[...suffix].js | 5 ++++- pages/[prefix]/[slug]/index.js | 5 ++++- pages/[prefix]/index.js | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index a892c275..d632e1c3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -34,7 +34,7 @@ export const memorize = (Component) => { // 转换外链 export function sliceUrlFromHttp(str) { // 检查字符串是否包含http - if (str.includes('http')) { + if (str.includes('http:') || str.includes('https:')) { // 如果包含,找到http的位置 const index = str.indexOf('http'); // 返回http之后的部分 @@ -48,7 +48,7 @@ export function sliceUrlFromHttp(str) { // 检查是否外链 export function checkContainHttp(str) { // 检查字符串是否包含http - if (str.includes('http')) { + if (str.includes('http:') || str.includes('https:')) { // 如果包含,找到http的位置 return str.indexOf('http') > -1 } else { diff --git a/pages/[prefix]/[slug]/[...suffix].js b/pages/[prefix]/[slug]/[...suffix].js index 67f099d7..f33fe20f 100644 --- a/pages/[prefix]/[slug]/[...suffix].js +++ b/pages/[prefix]/[slug]/[...suffix].js @@ -5,6 +5,7 @@ import { idToUuid } from 'notion-utils' import { getNotion } from '@/lib/notion/getNotion' import Slug, { getRecommendPost } from '..' import { uploadDataToAlgolia } from '@/lib/algolia' +import { checkContainHttp } from '@/lib/utils' /** * 根据notion的slug访问页面 @@ -30,8 +31,10 @@ export async function getStaticPaths() { const from = 'slug-paths' const { allPages } = await getGlobalData({ from }) + return { - paths: allPages?.filter(row => hasMultipleSlashes(row.slug) && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1], suffix: row.slug.split('/').slice(1) } })), + paths: allPages?.filter(row => hasMultipleSlashes(row.slug) && row.type.indexOf('Menu') < 0 && !checkContainHttp(row.slug)) + .map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1], suffix: row.slug.split('/').slice(1) } })), fallback: true } } diff --git a/pages/[prefix]/[slug]/index.js b/pages/[prefix]/[slug]/index.js index 4571b791..0c8fbffb 100644 --- a/pages/[prefix]/[slug]/index.js +++ b/pages/[prefix]/[slug]/index.js @@ -5,6 +5,7 @@ import { idToUuid } from 'notion-utils' import { getNotion } from '@/lib/notion/getNotion' import Slug, { getRecommendPost } from '..' import { uploadDataToAlgolia } from '@/lib/algolia' +import { checkContainHttp } from '@/lib/utils' /** * 根据notion的slug访问页面 @@ -26,8 +27,10 @@ export async function getStaticPaths() { const from = 'slug-paths' const { allPages } = await getGlobalData({ from }) + const paths = allPages?.filter(row => row.slug.indexOf('/') > 0 && !checkContainHttp(row.slug) && row.type.indexOf('Menu') < 0) + .map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1] } })) return { - paths: allPages?.filter(row => row.slug.indexOf('/') > 0 && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1] } })), + paths: paths, fallback: true } } diff --git a/pages/[prefix]/index.js b/pages/[prefix]/index.js index 036f585b..f9827f9b 100644 --- a/pages/[prefix]/index.js +++ b/pages/[prefix]/index.js @@ -8,7 +8,7 @@ import { getNotion } from '@/lib/notion/getNotion' import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents' import { getLayoutByTheme } from '@/themes/theme' import md5 from 'js-md5' -import { isBrowser } from '@/lib/utils' +import { checkContainHttp, isBrowser } from '@/lib/utils' import { uploadDataToAlgolia } from '@/lib/algolia' import { siteConfig } from '@/lib/config' @@ -82,8 +82,10 @@ export async function getStaticPaths() { const from = 'slug-paths' const { allPages } = await getGlobalData({ from }) + const paths = allPages?.filter(row => row.slug.indexOf('/') > 0 && !checkContainHttp(row.slug) && row.type.indexOf('Menu') < 0) + .map(row => ({ params: { prefix: row.slug } })) return { - paths: allPages?.filter(row => row.slug.indexOf('/') < 0 && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug } })), + paths: paths, fallback: true } }