Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/components/HotDocsPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { useEffect, useState } from "react";
import Link from "next/link";
import { useTranslations } from "next-intl";
import { useLocale, useTranslations } from "next-intl";
import { topDocHref } from "@/lib/top-doc-href";

interface TopDocDto {
path: string;
Expand Down Expand Up @@ -56,6 +57,7 @@ export function HotDocsPreviewSkeleton() {
*/
export function HotDocsPreview() {
const t = useTranslations("hotDocs");
const locale = useLocale();
const [docs, setDocs] = useState<TopDocDto[] | null>(null);

useEffect(() => {
Expand Down Expand Up @@ -114,7 +116,7 @@ export function HotDocsPreview() {
</span>
<div className="flex-1 min-w-0">
<Link
href={doc.path}
href={topDocHref(locale, doc.path)}
className="font-serif text-sm font-bold uppercase text-[var(--foreground)] hover:text-[#CC0000] transition-colors leading-tight line-clamp-2 block"
data-umami-event="navigation_click"
data-umami-event-region="hot_docs_preview"
Expand Down
5 changes: 4 additions & 1 deletion app/components/rank/HotDocsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { useReducer, useEffect } from "react";
import Link from "next/link";
import { useLocale } from "next-intl";
import { topDocHref } from "@/lib/top-doc-href";

type HotDoc = {
path: string;
Expand Down Expand Up @@ -38,6 +40,7 @@ function reducer(_: State, action: Action): State {
// 从根拔掉逃生门,同源代理永远成立;想 curl 测后端就直连 api 域名。

export function HotDocsTab({ initialWindow }: { initialWindow: WindowParam }) {
const locale = useLocale();
const [windowParam, setWindowParam] = useReducer(
(_: WindowParam, next: WindowParam) => next,
initialWindow,
Expand Down Expand Up @@ -165,7 +168,7 @@ export function HotDocsTab({ initialWindow }: { initialWindow: WindowParam }) {
{state.docs.map((doc, idx) => (
<Link
key={doc.path}
href={doc.path}
href={topDocHref(locale, doc.path)}
className="group w-full flex items-center gap-4 border border-[var(--foreground)] p-4 bg-[var(--background)] hard-shadow-hover transition-all"
>
<div className="font-mono text-2xl font-bold w-12 text-center text-[var(--foreground)] shrink-0">
Expand Down
11 changes: 11 additions & 0 deletions lib/top-doc-href.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* top-docs(热门文档榜)后端返回的 path 是无 locale 的 canonical(形如 /docs/learn/ai)。
* 拼上当前 locale 前缀得到可点击 URL。
*
* 防御性归一化:剥掉可能残留的 content/ 前缀和多余前导斜杠,避免后端某次回退到
* 旧格式(content/docs/...)时前端直接拼出 /en/content/docs/... 死链。
*/
export function topDocHref(locale: string, path: string): string {
const clean = "/" + path.replace(/^\/+/, "").replace(/^content\//, "");
return `/${locale}${clean}`;
}
Loading