mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
fix build url page not found
This commit is contained in:
@@ -33,7 +33,7 @@ export async function getStaticPaths() {
|
||||
const { allPages } = await getGlobalData({ from })
|
||||
|
||||
return {
|
||||
paths: allPages?.filter(row => hasMultipleSlashes(row.slug) && row.type.indexOf('Menu') < 0 && !checkContainHttp(row.slug))
|
||||
paths: allPages?.filter(row => checkSlug(row))
|
||||
.map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1], suffix: row.slug.split('/').slice(1) } })),
|
||||
fallback: true
|
||||
}
|
||||
@@ -102,15 +102,12 @@ export async function getStaticProps({ params: { prefix, slug, suffix } }) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否包含两个以上的 /
|
||||
* @param {*} str
|
||||
* @returns
|
||||
*/
|
||||
function hasMultipleSlashes(str) {
|
||||
const regex = /\/+/g; // 创建正则表达式,匹配所有的斜杠符号
|
||||
const matches = str.match(regex); // 在字符串中找到所有匹配的斜杠符号
|
||||
return matches && matches.length >= 2; // 判断匹配的斜杠符号数量是否大于等于2
|
||||
function checkSlug(row) {
|
||||
let slug = row.slug
|
||||
if (slug.startsWith('/')) {
|
||||
slug = slug.substring(1)
|
||||
}
|
||||
return (slug.match(/\//g) || []).length >= 2 && row.type.indexOf('Menu') < 0 && !checkContainHttp(slug)
|
||||
}
|
||||
|
||||
export default PrefixSlug
|
||||
|
||||
@@ -27,7 +27,7 @@ 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)
|
||||
const paths = allPages?.filter(row => checkSlug(row))
|
||||
.map(row => ({ params: { prefix: row.slug.split('/')[0], slug: row.slug.split('/')[1] } }))
|
||||
return {
|
||||
paths: paths,
|
||||
@@ -92,5 +92,11 @@ export async function getStaticProps({ params: { prefix, slug } }) {
|
||||
revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND)
|
||||
}
|
||||
}
|
||||
|
||||
function checkSlug(row) {
|
||||
let slug = row.slug
|
||||
if (slug.startsWith('/')) {
|
||||
slug = slug.substring(1)
|
||||
}
|
||||
return (slug.match(/\//g) || []).length === 1 && !checkContainHttp(slug) && row.type.indexOf('Menu') < 0
|
||||
}
|
||||
export default PrefixSlug
|
||||
|
||||
@@ -82,7 +82,7 @@ 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)
|
||||
const paths = allPages?.filter(row => checkSlug(row))
|
||||
.map(row => ({ params: { prefix: row.slug } }))
|
||||
return {
|
||||
paths: paths,
|
||||
@@ -183,4 +183,12 @@ export function getRecommendPost(post, allPosts, count = 6) {
|
||||
return recommendPosts
|
||||
}
|
||||
|
||||
function checkSlug(row) {
|
||||
let slug = row.slug
|
||||
if (slug.startsWith('/')) {
|
||||
slug = slug.substring(1)
|
||||
}
|
||||
return ((slug.match(/\//g) || []).length === 0 && !checkContainHttp(slug)) && row.type.indexOf('Menu') < 0
|
||||
}
|
||||
|
||||
export default Slug
|
||||
|
||||
Reference in New Issue
Block a user