This commit is contained in:
1 parent
c1541b80df
commit
b4c7908029
97 files changed
+12403
-154
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import "server-only";
|
||||
|
||||
import {
|
||||
listAllPublishedPosts,
|
||||
getPostBySlug as getPostBySlugFromDb,
|
||||
getAdjacentPosts as getAdjacentPostsFromDb,
|
||||
listTags,
|
||||
getPostStats,
|
||||
} from "./repository";
|
||||
import type { Post, PostMeta } from "./types";
|
||||
|
||||
/**
|
||||
* 内容读取门面(服务端)。
|
||||
*
|
||||
* 页面层只依赖本模块,不直接接触仓储实现。这样做的价值:
|
||||
* 数据来源从「文件系统」切换到「PostgreSQL」时,**页面代码一行都不用改**。
|
||||
*
|
||||
* 所有函数默认只返回已发布文章(草稿在仓储层被过滤),
|
||||
* 因此草稿既不出现在列表里,也无法通过直接访问 URL 读到。
|
||||
*/
|
||||
|
||||
export type { Post, PostMeta } from "./types";
|
||||
|
||||
/** 全部已发布文章,按发布日期倒序 */
|
||||
export async function getAllPosts(): Promise<PostMeta[]> {
|
||||
return listAllPublishedPosts();
|
||||
}
|
||||
|
||||
/** 按 slug 读取单篇文章(含正文);草稿与不存在的 slug 均返回 null */
|
||||
export async function getPostBySlug(slug: string): Promise<Post | null> {
|
||||
const post = await getPostBySlugFromDb(slug);
|
||||
return post as Post | null;
|
||||
}
|
||||
|
||||
/** 相邻文章(详情页上下篇导航) */
|
||||
export async function getAdjacentPosts(slug: string) {
|
||||
return getAdjacentPostsFromDb(slug);
|
||||
}
|
||||
|
||||
/** 全部标签及其文章数 */
|
||||
export async function getAllTags(): Promise<{ tag: string; count: number }[]> {
|
||||
return listTags();
|
||||
}
|
||||
|
||||
/** 站点统计(已发布数 / 草稿数 / 标签数) */
|
||||
export async function getStats() {
|
||||
return getPostStats();
|
||||
}
|
||||
Reference in new issue
Block a user