feat: 可配置站点 URL 风格
- 新增 urlStyle 工具与测试:postPath/userPath/sitePagePath 统一生成链接 - 管理端新增 UrlStylePanel 设置面板,settings 服务与 handler 适配 - 全站路由链接与 JSON-LD/sitemap 切换为统一 URL 生成 - middleware 与相关组件适配
This commit is contained in:
@@ -12,6 +12,8 @@ import { formatRelative } from "@/lib/format";
|
||||
import type {
|
||||
UserProfile, UserCommentsResponse, UserFavoritesResponse, UserFollowingResponse, PostListItem,
|
||||
} from "@/lib/api";
|
||||
import { postPath, userPath } from "@/lib/urlStyle";
|
||||
import { getPublicSettingsCached } from "@/lib/serverData";
|
||||
|
||||
/** 本页卡片统一阴影;用 color-mix 让暗色主题自动加深,避免写死浅色阴影 */
|
||||
const CARD_SHADOW = "0 1px 3px color-mix(in srgb, #000 18%, transparent)";
|
||||
@@ -26,11 +28,12 @@ const SORTS: { key: string; label: string }[] = [
|
||||
];
|
||||
|
||||
/** 帖子卡(发帖列表与收藏列表共用) */
|
||||
function PostCardItem({ post, allowComments }: { post: PostListItem; allowComments?: boolean }) {
|
||||
async function PostCardItem({ post, allowComments }: { post: PostListItem; allowComments?: boolean }) {
|
||||
const urlStyle = (await getPublicSettingsCached()).url_style;
|
||||
const pinned = post.pinned > 0;
|
||||
return (
|
||||
<Link
|
||||
href={`/post/${post.id}`}
|
||||
href={postPath(urlStyle, post.id)}
|
||||
className={`${ITEM_BASE} ${
|
||||
pinned
|
||||
? "bg-[color-mix(in_srgb,#fde68a_22%,var(--panel))] border-[color-mix(in_srgb,#fde68a_70%,var(--line))] hover:bg-[color-mix(in_srgb,#fde68a_30%,var(--panel))]"
|
||||
@@ -139,7 +142,7 @@ function ErrorState({ retryHref }: { retryHref: string }) {
|
||||
* tab 与分页全部走 URL(?tab=xxx&page=N&sort=xxx),刷新/后退/分享链接均保持一致。
|
||||
* Tab 切换栏已移至 page.tsx 统一渲染(含 settings / security),此组件仅负责列表类 tab。
|
||||
*/
|
||||
export default function UserProfileContent({
|
||||
export default async function UserProfileContent({
|
||||
userId,
|
||||
profile,
|
||||
tab,
|
||||
@@ -168,6 +171,7 @@ export default function UserProfileContent({
|
||||
isOwner: boolean;
|
||||
allowComments?: boolean;
|
||||
}) {
|
||||
const urlStyle = (await getPublicSettingsCached()).url_style;
|
||||
const displayName = profile.user.nickname || profile.user.username;
|
||||
const paginationQuery: Record<string, string> =
|
||||
tab === "comments" ? { tab: "comments" }
|
||||
@@ -189,7 +193,7 @@ export default function UserProfileContent({
|
||||
{SORTS.map((s) => (
|
||||
<Link
|
||||
key={s.key}
|
||||
href={s.key === "new" ? `/u/${userId}` : `/u/${userId}?sort=${s.key}`}
|
||||
href={s.key === "new" ? userPath(urlStyle, Number(userId)) : `${userPath(urlStyle, Number(userId))}?sort=${s.key}`}
|
||||
className="j13-chip"
|
||||
aria-current={sort === s.key ? "page" : undefined}
|
||||
>
|
||||
@@ -215,13 +219,13 @@ export default function UserProfileContent({
|
||||
total={profile.posts_total}
|
||||
page={page}
|
||||
size={20}
|
||||
basePath={`/u/${userId}`}
|
||||
basePath={userPath(urlStyle, Number(userId))}
|
||||
query={paginationQuery}
|
||||
/>
|
||||
</div>
|
||||
) : tab === "favorites" ? (
|
||||
favoriteError ? (
|
||||
<ErrorState retryHref={`/u/${userId}?tab=favorites`} />
|
||||
<ErrorState retryHref={`${userPath(urlStyle, Number(userId))}?tab=favorites`} />
|
||||
) : favoriteData && favoriteData.posts.length > 0 ? (
|
||||
<div>
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
@@ -238,7 +242,7 @@ export default function UserProfileContent({
|
||||
total={favoriteData.total}
|
||||
page={favoriteData.page}
|
||||
size={20}
|
||||
basePath={`/u/${userId}`}
|
||||
basePath={userPath(urlStyle, Number(userId))}
|
||||
query={paginationQuery}
|
||||
/>
|
||||
</div>
|
||||
@@ -250,7 +254,7 @@ export default function UserProfileContent({
|
||||
)
|
||||
) : tab === "following" ? (
|
||||
followingError ? (
|
||||
<ErrorState retryHref={`/u/${userId}?tab=following`} />
|
||||
<ErrorState retryHref={`${userPath(urlStyle, Number(userId))}?tab=following`} />
|
||||
) : followingData && followingData.users.length > 0 ? (
|
||||
<div>
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
@@ -265,7 +269,7 @@ export default function UserProfileContent({
|
||||
className="group flex items-center gap-3 rounded-xl border px-5 py-4 transition-[background-color,box-shadow,border-color] duration-150 bg-[var(--panel)] border-[var(--line)] hover:bg-[color-mix(in_srgb,var(--ink)_3.5%,var(--panel))]"
|
||||
style={{ boxShadow: CARD_SHADOW }}
|
||||
>
|
||||
<Link href={`/u/${fu.id}`} className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<Link href={userPath(urlStyle, fu.id)} className="flex min-w-0 flex-1 items-center gap-3">
|
||||
<Avatar name={fu.nickname || fu.username} src={fu.avatar || undefined} size={40} />
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-1.5">
|
||||
@@ -291,7 +295,7 @@ export default function UserProfileContent({
|
||||
total={followingData.total}
|
||||
page={followingData.page}
|
||||
size={20}
|
||||
basePath={`/u/${userId}`}
|
||||
basePath={userPath(urlStyle, Number(userId))}
|
||||
query={paginationQuery}
|
||||
/>
|
||||
</div>
|
||||
@@ -302,14 +306,14 @@ export default function UserProfileContent({
|
||||
/>
|
||||
)
|
||||
) : commentError ? (
|
||||
<ErrorState retryHref={`/u/${userId}?tab=comments`} />
|
||||
<ErrorState retryHref={`${userPath(urlStyle, Number(userId))}?tab=comments`} />
|
||||
) : commentData && (commentData.comments?.length ?? 0) > 0 ? (
|
||||
<div>
|
||||
<div className="panel overflow-hidden">
|
||||
{(commentData.comments ?? []).map((c) => (
|
||||
<Link
|
||||
key={c.id}
|
||||
href={`/post/${c.post_id}#comment-${c.id}`}
|
||||
href={`${postPath(urlStyle, c.post_id)}#comment-${c.id}`}
|
||||
className="group block px-4 sm:px-5 py-4 border-t transition-colors hover:bg-[var(--item-hover-bg)] focus-visible:bg-[var(--item-hover-bg)]"
|
||||
style={{ borderColor: "var(--line)" }}
|
||||
>
|
||||
@@ -335,7 +339,7 @@ export default function UserProfileContent({
|
||||
total={commentData.total}
|
||||
page={commentData.page}
|
||||
size={20}
|
||||
basePath={`/u/${userId}`}
|
||||
basePath={userPath(urlStyle, Number(userId))}
|
||||
query={paginationQuery}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user