Files
jiang13-bbs/frontend/lib/postMeta.ts
freefire 833bcd33a1 chore: 去掉未上线前的旧兼容垫片,板块流收口到首页
鉴权只认 cookie、SEO 只走 Next、sort 与推荐对齐;删除 Bearer、Go sitemap、post_type 回填等冗余路径。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 05:04:47 +08:00

90 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 帖子类型 / 可见性 / 展示文案(前后端共用约定) */
export const POST_TYPES = [
{ value: "discussion", label: "讨论", hint: "默认讨论帖" },
{ value: "question", label: "问答", hint: "提问求解" },
{ value: "poll", label: "投票", hint: "发起投票,读者可参与" },
{ value: "bounty", label: "悬赏", hint: "发布时托管积分,采纳后发放" },
{ value: "lottery", label: "抽奖", hint: "回帖即参与,截止自动开奖" },
] as const;
export type PostTypeValue = (typeof POST_TYPES)[number]["value"];
export const CONTENT_ACCESS = [
{ value: "public", label: "公开" },
{ value: "login", label: "登录可见" },
{ value: "reply", label: "回复可见" },
{ value: "points", label: "积分可见" },
] as const;
export type ContentAccessValue = (typeof CONTENT_ACCESS)[number]["value"];
export const BOUNTY_EXPIRE_DAYS = [3, 7, 14, 30] as const;
export const LOTTERY_EXPIRE_DAYS = [1, 3, 7, 14] as const;
export function normalizePostType(t?: string): PostTypeValue {
if (!t) return "discussion";
if (POST_TYPES.some((x) => x.value === t)) return t as PostTypeValue;
return "discussion";
}
export function postTypeLabel(t?: string): string {
const n = normalizePostType(t);
return POST_TYPES.find((x) => x.value === n)?.label || "讨论";
}
export function contentAccessLabel(a?: string): string {
const hit = CONTENT_ACCESS.find((x) => x.value === a);
return hit?.label || "公开";
}
/** 列表 type_status → 徽章文案 */
export function typeStatusLabel(postType?: string, typeStatus?: string): string {
const pt = normalizePostType(postType);
const s = (typeStatus || "").toLowerCase();
switch (pt) {
case "question":
return s === "solved" ? "已解决" : "未解决";
case "poll":
return s === "closed" ? "已结束" : "进行中";
case "bounty":
if (s === "solved") return "已采纳";
if (s === "expired") return "已过期";
return "进行中";
case "lottery":
if (s === "drawn") return "已开奖";
if (s === "closed") return "已截止";
return "进行中";
default:
return "";
}
}
/** 状态徽章 CSS class(浅色区分) */
export function typeStatusClass(postType?: string, typeStatus?: string): string {
const pt = normalizePostType(postType);
const s = (typeStatus || "").toLowerCase();
let kind = "open";
switch (pt) {
case "question":
kind = s === "solved" ? "solved" : "unsolved";
break;
case "poll":
kind = s === "closed" ? "closed" : "open";
break;
case "bounty":
if (s === "solved") kind = "solved";
else if (s === "expired") kind = "expired";
else kind = "open";
break;
case "lottery":
if (s === "drawn") kind = "drawn";
else if (s === "closed") kind = "closed";
else kind = "open";
break;
default:
return "";
}
return `badge-status badge-status-${kind}`;
}