fix build failed on post external slug

This commit is contained in:
tangly1024.com
2024-02-02 11:32:27 +08:00
parent 464c3add92
commit f568bc32ec
4 changed files with 14 additions and 6 deletions

View File

@@ -34,7 +34,7 @@ export const memorize = (Component) => {
// 转换外链 // 转换外链
export function sliceUrlFromHttp(str) { export function sliceUrlFromHttp(str) {
// 检查字符串是否包含http // 检查字符串是否包含http
if (str.includes('http')) { if (str.includes('http:') || str.includes('https:')) {
// 如果包含找到http的位置 // 如果包含找到http的位置
const index = str.indexOf('http'); const index = str.indexOf('http');
// 返回http之后的部分 // 返回http之后的部分
@@ -48,7 +48,7 @@ export function sliceUrlFromHttp(str) {
// 检查是否外链 // 检查是否外链
export function checkContainHttp(str) { export function checkContainHttp(str) {
// 检查字符串是否包含http // 检查字符串是否包含http
if (str.includes('http')) { if (str.includes('http:') || str.includes('https:')) {
// 如果包含找到http的位置 // 如果包含找到http的位置
return str.indexOf('http') > -1 return str.indexOf('http') > -1
} else { } else {

View File

@@ -5,6 +5,7 @@ import { idToUuid } from 'notion-utils'
import { getNotion } from '@/lib/notion/getNotion' import { getNotion } from '@/lib/notion/getNotion'
import Slug, { getRecommendPost } from '..' import Slug, { getRecommendPost } from '..'
import { uploadDataToAlgolia } from '@/lib/algolia' import { uploadDataToAlgolia } from '@/lib/algolia'
import { checkContainHttp } from '@/lib/utils'
/** /**
* 根据notion的slug访问页面 * 根据notion的slug访问页面
@@ -30,8 +31,10 @@ export async function getStaticPaths() {
const from = 'slug-paths' const from = 'slug-paths'
const { allPages } = await getGlobalData({ from }) const { allPages } = await getGlobalData({ from })
return { 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 fallback: true
} }
} }

View File

@@ -5,6 +5,7 @@ import { idToUuid } from 'notion-utils'
import { getNotion } from '@/lib/notion/getNotion' import { getNotion } from '@/lib/notion/getNotion'
import Slug, { getRecommendPost } from '..' import Slug, { getRecommendPost } from '..'
import { uploadDataToAlgolia } from '@/lib/algolia' import { uploadDataToAlgolia } from '@/lib/algolia'
import { checkContainHttp } from '@/lib/utils'
/** /**
* 根据notion的slug访问页面 * 根据notion的slug访问页面
@@ -26,8 +27,10 @@ export async function getStaticPaths() {
const from = 'slug-paths' const from = 'slug-paths'
const { allPages } = await getGlobalData({ from }) 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 { 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 fallback: true
} }
} }

View File

@@ -8,7 +8,7 @@ import { getNotion } from '@/lib/notion/getNotion'
import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents' import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
import { getLayoutByTheme } from '@/themes/theme' import { getLayoutByTheme } from '@/themes/theme'
import md5 from 'js-md5' import md5 from 'js-md5'
import { isBrowser } from '@/lib/utils' import { checkContainHttp, isBrowser } from '@/lib/utils'
import { uploadDataToAlgolia } from '@/lib/algolia' import { uploadDataToAlgolia } from '@/lib/algolia'
import { siteConfig } from '@/lib/config' import { siteConfig } from '@/lib/config'
@@ -82,8 +82,10 @@ export async function getStaticPaths() {
const from = 'slug-paths' const from = 'slug-paths'
const { allPages } = await getGlobalData({ from }) 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 { return {
paths: allPages?.filter(row => row.slug.indexOf('/') < 0 && row.type.indexOf('Menu') < 0).map(row => ({ params: { prefix: row.slug } })), paths: paths,
fallback: true fallback: true
} }
} }