build: 修复预编译

This commit is contained in:
tangly1024
2022-01-12 09:59:32 +08:00
parent ff76a126b8
commit f4fb879852
3 changed files with 18 additions and 20 deletions

View File

@@ -57,7 +57,7 @@ const BlogPostCard = ({ post, showSummary }) => {
/>
</div> }
<div className='article-cover'>
<div className='article-cover pointer-events-none'>
<Link href={`${BLOG.path}/article/${post.slug}`} passHref>
<a className='hover:bg-opacity-100 hover:scale-105 transform duration-300 rounded-md p-2 text-red-500 cursor-pointer'>
{locale.COMMON.ARTICLE_DETAIL}

View File

@@ -4,7 +4,7 @@ import Live2D from '@/components/Live2D'
import TocDrawer from '@/components/TocDrawer'
import TocDrawerButton from '@/components/TocDrawerButton'
import BaseLayout from '@/layouts/BaseLayout'
import { getAllPosts, getPostBlocks } from '@/lib/notion'
import { getPostBlocks } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
import Custom404 from '@/pages/404'
import { getPageTableOfContents } from 'notion-utils'
@@ -69,12 +69,17 @@ const Slug = ({
}
export async function getStaticPaths () {
let posts = []
if (BLOG.isProd) {
posts = await getAllPosts({ from: 'slug - paths', includePage: false })
if (!BLOG.isProd) {
return {
paths: [],
fallback: true
}
}
const from = '[slug-paths'
const { allPosts } = await getGlobalNotionData({ from, includePage: false })
return {
paths: posts.map(row => ({ params: { slug: row.slug } })),
paths: allPosts.map(row => ({ params: { slug: row.slug } })),
fallback: true
}
}

View File

@@ -4,7 +4,6 @@ import StickyBar from '@/components/StickyBar'
import TagList from '@/components/TagList'
import BaseLayout from '@/layouts/BaseLayout'
import { useGlobal } from '@/lib/global'
import { getAllPosts } from '@/lib/notion'
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
export default function Tag ({ tags, posts, tag, categories, postCount, latestPosts }) {
@@ -56,27 +55,21 @@ export async function getStaticProps ({ params }) {
* @param {*}} allPosts
* @returns
*/
function getTagNames (allPosts) {
const tags = allPosts.map(p => p.tags).flat()
const tagObj = {}
function getTagNames (tags) {
const tagNames = []
tags.forEach(tag => {
if (tag in tagObj) {
tagObj[tag]++
} else {
tagObj[tag] = 1
}
tagNames.push(tag.name)
})
return tagObj
return tagNames
}
export async function getStaticPaths () {
const from = 'tag-static-path'
const posts = await getAllPosts({ from })
const tagNames = getTagNames(posts)
const { tags } = await getGlobalNotionData({ from, tagsCount: 0 })
const tagNames = getTagNames(tags)
return {
paths: Object.keys(tagNames).map(tag => ({ params: { tag } })),
paths: Object.keys(tagNames).map(index => ({ params: { tag: tagNames[index] } })),
fallback: true
}
}