Files
aiameiba_com_new/frontend/src/lib/articles.ts
T

32 lines
933 B
TypeScript

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}`;