新增内容引擎文章发布接口与详情页

This commit is contained in:
amb
2026-09-11 17:19:09 +08:00
parent ba6aab722e
commit 726485dccb
16 changed files with 958 additions and 102 deletions
+31
View File
@@ -0,0 +1,31 @@
import type { PublicArticle } from '@/types';
const API_URL = process.env.API_URL || 'http://localhost:24731';
export async function getPublishedArticles(): Promise<PublicArticle[]> {
try {
const response = await fetch(`${API_URL}/api/public/articles?pageSize=100`, {
next: { revalidate: 60 },
});
if (!response.ok) return [];
const data = await response.json();
return data.list || [];
} catch {
return [];
}
}
export async function getPublishedArticle(identifier: string): Promise<PublicArticle | null> {
try {
const response = await fetch(`${API_URL}/api/public/articles/${encodeURIComponent(identifier)}`, {
next: { revalidate: 60 },
});
if (!response.ok) return null;
return response.json();
} catch {
return null;
}
}
export const articleUrl = (article: Pick<PublicArticle, 'content_id' | 'slug'>) =>
`/knowledge/${article.slug || article.content_id}`;