1- import Link from "next/link" ;
2- import {
3- getTopicsByCategory ,
4- REPO_DOCS_BASE ,
5- type DocTopic ,
6- } from "@/lib/docs-map" ;
1+ import { DocsSearch } from "@/components/docs-search" ;
72import { buildPageMetadata } from "@/lib/page-meta" ;
83
94export async function generateMetadata ( { params } : { params : Promise < { locale : string } > } ) {
@@ -19,94 +14,7 @@ export async function generateMetadata({ params }: { params: Promise<{ locale: s
1914 } ) ;
2015}
2116
22- /* ------------------------------------------------------------------ */
23- /* Locale-aware strings */
24- /* ------------------------------------------------------------------ */
25-
26- const CATEGORY_LABELS : Record < string , { en : string ; zh : string } > = {
27- "getting-started" : { en : "Getting started" , zh : "入门" } ,
28- "core-concepts" : { en : "Core concepts" , zh : "核心概念" } ,
29- reference : { en : "Reference" , zh : "参考" } ,
30- extending : { en : "Extending" , zh : "扩展" } ,
31- operations : { en : "Operations & community" , zh : "运维与社区" } ,
32- } ;
33-
34- /* ------------------------------------------------------------------ */
35-
36- function topicHref ( topic : DocTopic , locale : string ) : string {
37- if ( topic . hasPage ) {
38- return `/${ locale } /docs/${ topic . slug } ` ;
39- }
40- const src = Array . isArray ( topic . repoSource ) ? topic . repoSource [ 0 ] : topic . repoSource ;
41- return `${ REPO_DOCS_BASE } /${ src } ` ;
42- }
43-
44- function topicSources ( topic : DocTopic ) : string [ ] {
45- return Array . isArray ( topic . repoSource ) ? topic . repoSource : [ topic . repoSource ] ;
46- }
47-
48- /* ------------------------------------------------------------------ */
49-
5017export default async function DocsHubPage ( { params } : { params : Promise < { locale : string } > } ) {
5118 const { locale } = await params ;
52- const isZh = locale === "zh" ;
53- const byCategory = getTopicsByCategory ( ) ;
54-
55- const body = (
56- < div className = "space-y-12" >
57- { [ ...byCategory . entries ( ) ] . map ( ( [ cat , topics ] ) => (
58- < section key = { cat } id = { cat } >
59- < h2 className = "font-display text-2xl mb-1" >
60- { isZh ? CATEGORY_LABELS [ cat ] ?. zh ?? cat : CATEGORY_LABELS [ cat ] ?. en ?? cat }
61- </ h2 >
62- < div className = "grid sm:grid-cols-2 gap-4 mt-4" >
63- { topics . map ( ( t ) => {
64- const href = topicHref ( t , locale ) ;
65- const sources = topicSources ( t ) ;
66- const isExternal = ! t . hasPage ;
67- return (
68- < Link
69- key = { t . id }
70- href = { href }
71- target = { isExternal ? "_blank" : undefined }
72- className = "hairline-t hairline-b hairline-l hairline-r p-4 hover:bg-paper-deep transition-colors group block"
73- >
74- < div className = "flex items-center gap-2 mb-1.5" >
75- < span className = "font-mono text-[0.62rem] uppercase tracking-widest text-ink-mute" >
76- { isZh ? t . label . zh : t . label . en }
77- </ span >
78- { isExternal && (
79- < span className = "font-mono text-[0.6rem] text-ink-mute" > ↗</ span >
80- ) }
81- </ div >
82- < p className = "text-sm text-ink-soft leading-relaxed" >
83- { isZh ? t . description . zh : t . description . en }
84- </ p >
85- < div className = "mt-2 font-mono text-[0.62rem] text-ink-mute truncate" >
86- { sources . map ( ( s , i ) => (
87- < span key = { s } >
88- { i > 0 && ", " }
89- { s }
90- </ span >
91- ) ) }
92- </ div >
93- </ Link >
94- ) ;
95- } ) }
96- </ div >
97- </ section >
98- ) ) }
99-
100- { /* Parapgraph about the docs approach */ }
101- < section className = "hairline-t pt-8" >
102- < p className = "text-sm text-ink-mute leading-relaxed max-w-2xl" >
103- { isZh
104- ? "§ 标记的条目在 CodeWhale 网站上有独立页面;↗ 标记的条目链接到 GitHub 仓库中的源文档。所有内容来源于 docs/ 目录下的 40+ 篇 Markdown 文档,通过 docs-map.ts 注册表维护。"
105- : "Entries marked § have dedicated pages on codewhale.net; entries marked ↗ link to source documents in the GitHub repository. All content is sourced from 40+ Markdown documents in the docs/ directory, maintained through the docs-map.ts registry." }
106- </ p >
107- </ section >
108- </ div >
109- ) ;
110-
111- return body ;
19+ return < DocsSearch locale = { locale } /> ;
11220}
0 commit comments