mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-09-03 06:24:24 +08:00
feat(article): 添加静态参数生成以优化文章页面加载速度
- 引入 getArticlePagingCacheAPI 以提前下载前80篇文章,提升页面加载性能。 - 更新 generateStaticParams 函数,确保在获取文章数据时处理异常情况。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { getArticleDataAPI, recordViewAPI } from '@/api/article';
|
||||
import { getWebConfigCacheAPI } from '@/lib/config';
|
||||
import { getArticleCacheAPI } from '@/lib/article';
|
||||
import { getArticleCacheAPI, getArticlePagingCacheAPI } from '@/lib/article';
|
||||
import { getThemeConfigCacheAPI } from '@/lib/theme';
|
||||
import { getStableImage } from '@/utils';
|
||||
import { Metadata } from 'next';
|
||||
@@ -35,6 +35,18 @@ interface Props {
|
||||
searchParams: Promise<{ password: string }>;
|
||||
}
|
||||
|
||||
// 提前下载好前80篇文章,提高页面加载速度
|
||||
export async function generateStaticParams() {
|
||||
try {
|
||||
const { data } = await getArticlePagingCacheAPI({ pageNum: 1, pageSize: 80 });
|
||||
return (data?.result ?? [])
|
||||
.filter((article) => article.id != null)
|
||||
.map((article) => ({ id: String(article.id) }));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 生成文章页面的 metadata
|
||||
export async function generateMetadata(props: Props): Promise<Metadata> {
|
||||
const params = await props.params;
|
||||
|
||||
Reference in New Issue
Block a user