新增内容引擎文章发布接口与详情页
This commit is contained in:
@@ -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}`;
|
||||
Reference in New Issue
Block a user