Skip to content

Commit 3fe8e5b

Browse files
shhdgitlilin90yahonda
authored
feat: multi toc (#629)
* feat: refactor version selection component and update import paths - Introduced a new VersionSelect component to manage version selection in the navigation. - Updated LeftNav to import VersionSelect from the correct relative path. - Enhanced the version selection logic to improve user experience and maintainability. * feat: update HeaderAction and Search components with new icons and layout adjustments - Replaced TranslateIcon with a new globe SVG icon for improved visual representation. - Adjusted spacing in HeaderAction component for better alignment of elements. - Updated Search component to use a new search SVG icon and modified its width for a more compact design. - Enhanced styling in SearchPopper for improved layout and responsiveness. * feat: enhance Header component with conditional banners for auto-translation and archive builds - Added conditional rendering for a banner in the Header component based on auto-translation status and build type. - Improved the presentation of machine translation notices with updated styling and links. - Integrated an ArchiveBanner for archive builds, ensuring appropriate messaging for different build types. * feat: add outlined variant styling to theme - Introduced new styles for the outlined variant in the theme, including color, border, and background adjustments. - Enhanced hover effects for the outlined variant to improve user interaction and visual feedback. * refactor: simplify Header component structure and enhance banner logic - Introduced a HeaderProps interface for better type management in the Header component. - Refactored the banner rendering logic into a separate HeaderBanner component for improved readability and maintainability. - Streamlined the conditional rendering of banners based on auto-translation status and build type, ensuring clearer presentation of messages. * refactor: consolidate banner logic in Header component and remove ArchiveBanner - Merged the functionality of the ArchiveBanner into the Header component to streamline banner rendering. - Enhanced the logic for displaying banners based on build type and auto-translation status. - Removed the ArchiveBanner component to reduce complexity and improve maintainability. * feat: implement cloud mode navigation and enhance page generation - Added support for cloud mode navigation with starter and essential options, allowing users to switch between different cloud plans. - Introduced new navigation generation functions for starter and essential paths. - Enhanced the createDocs function to include starter and essential navigation URLs in the page creation process. - Updated the MDXContent component to utilize cloud mode for rendering appropriate navigation based on user selection. - Refactored various components to integrate cloud mode logic, improving user experience and maintainability. * fix: update URL generation logic for cloud mode navigation - Enhanced the createDocs function to generate URLs based on the presence of "starter" or "essential" in the file path, improving navigation structure. - Adjusted the URL format in the CloudVersionSelect component to include the selected version in the path, ensuring accurate navigation links for users. * refactor: enhance CloudVersionSelect and VersionSelect components for improved layout and styling - Updated the CloudVersionSelect and VersionSelect components to use Box for better layout control and styling consistency. - Increased padding in the menu list and adjusted item height for improved usability. - Enhanced the Starter label to include additional context for clarity. - Implemented sticky positioning for the version selection box to maintain visibility during scrolling. * refactor: integrate essential navigation into documentation home and update version selection components - Added essential navigation URL generation to the createDocHome function for improved documentation structure. - Refactored CloudVersionSelect and VersionSelect components to utilize a shared VersionSelectMenu for consistency and enhanced styling. - Adjusted layout properties in version selection components for better user experience and visual appeal. * refactor: improve layout and functionality of CloudVersionSelect and VersionSelect components - Integrated CheckIcon to visually indicate the selected cloud version in the CloudVersionSelect component. - Enhanced layout using Box for better alignment and spacing in version items. - Updated styling for FormLabel to improve clarity and visual consistency. - Adjusted justifyContent in VersionSelectMenu for improved item layout. * refactor: update useCloudMode hook and related components for improved functionality - Refactored the useCloudMode hook to accept a repo parameter, enhancing its flexibility for different contexts. - Updated Link and MDXComponents to remove unnecessary cloud mode logic, simplifying their implementation. - Adjusted CloudVersionSelect and DocTemplate components to utilize the new useCloudMode signature, ensuring consistent behavior across the application. * refactor: adjust layout of CloudVersionSelect for improved alignment - Updated the Box component in CloudVersionSelect to use flexbox for center alignment of version items. - Enhanced visual consistency by ensuring the CheckIcon is properly aligned with the version display. * fix: update version rendering logic in VersionSelect component - Modified the renderVersion function to return "Dev" for the "dev" version, improving clarity in version display. - Adjusted the VersionItems component to call renderVersion with the correct casing for consistency. * locale, src: update campaign banner for renaming serverless Revised the campaign section in English, Japanese, and Chinese translation files to reflect the new TiDB Cloud Starter branding and updated the link to the quickstart page. Changed the banner icon in Header.tsx from a rocket to a megaphone for better alignment with the new campaign. * locale: update link * Update links to tidbcloud.com * Apply suggestions from code review Co-authored-by: Yasuo Honda <[email protected]> * locale: update campaign banner translations and refactor Link component Revised the campaign section in English, Japanese, and Chinese translation files to reflect the new TiDB Cloud Starter branding. Refactored the Link component to introduce a new BlueAnchorLink variant for consistent styling across the application, enhancing the header banner with updated links and improved layout. * refactor: consolidate version selection components for improved reusability - Introduced a new SharedSelect component to encapsulate the VersionSelectButton and VersionSelectMenu, enhancing code reusability. - Updated CloudVersionSelect and VersionSelect components to utilize the new shared components, streamlining their implementation and improving layout consistency. - Refactored state management in version selection components for better clarity and performance. * locale: update translations and enhance Link component styling Revised English, Japanese, and Chinese translation files to standardize the "Try it out" text to "end" for consistency. Introduced a new CSS file for the Link component to manage styles, specifically for the new BlueAnchorLink variant, ensuring consistent text decoration across the application. * refactor: enhance layout of CloudVersionSelect to include version icon - Updated CloudVersionSelect to wrap the version label and icon in a flexbox for improved alignment and visual consistency. - This change enhances the user interface by displaying the version icon alongside the version label. * style: enforce text decoration for Link component - Updated Link component styles to ensure consistent text decoration by applying `text-decoration: none` to all link variants. - Modified CSS for the BlueAnchorLink to use `text-decoration: underline !important` on hover for better visibility. * feat: update HeaderAction and Search components for improved functionality and layout - Added a Search component to the HeaderAction for enhanced document searching capabilities. - Adjusted the Search component's width for better usability. - Updated button labels in the TiDBCloudBtnGroup for clarity, changing "Start for Free" to "Sign In" and vice versa. --------- Co-authored-by: lilin90 <[email protected]> Co-authored-by: Yasuo Honda <[email protected]>
1 parent 9303081 commit 3fe8e5b

30 files changed

+792
-335
lines changed

gatsby/create-pages.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import {
99
generateUrl,
1010
generateNav,
1111
generateDocHomeUrl,
12+
generateStarterNav,
13+
generateEssentialNav,
1214
} from "./path";
1315
import { docs as DOCS_CONFIG } from "../docs/docs.json";
1416
import { cpMarkdown } from "./cp-markdown";
17+
import { queryTOCs } from "./toc";
1518

1619
interface PageQueryData {
1720
allMdx: {
@@ -25,10 +28,11 @@ interface PageQueryData {
2528

2629
const DEFAULT_BUILD_TYPE: BuildType = "prod";
2730

28-
export const createDocs = async ({
29-
actions: { createPage, createRedirect },
30-
graphql,
31-
}: CreatePagesArgs) => {
31+
export const createDocs = async (createPagesArgs: CreatePagesArgs) => {
32+
const {
33+
actions: { createPage, createRedirect },
34+
graphql,
35+
} = createPagesArgs;
3236
// const template = resolve(__dirname, '../src/doc/index.tsx')
3337
const template = resolve(__dirname, "../src/templates/DocTemplate.tsx");
3438

@@ -96,8 +100,14 @@ export const createDocs = async ({
96100
return;
97101
}
98102

99-
const path = generateUrl(name, pathConfig);
103+
const path = filePath.includes("starter")
104+
? generateUrl(`starter/${name}`, pathConfig)
105+
: filePath.includes("essential")
106+
? generateUrl(`essential/${name}`, pathConfig)
107+
: generateUrl(name, pathConfig);
100108
const navUrl = generateNav(pathConfig);
109+
const starterNavUrl = generateStarterNav(pathConfig);
110+
const essentialNavUrl = generateEssentialNav(pathConfig);
101111

102112
const locale = [Locale.en, Locale.zh, Locale.ja]
103113
.map((l) =>
@@ -119,6 +129,8 @@ export const createDocs = async ({
119129
filePath,
120130
pageUrl: path,
121131
navUrl,
132+
starterNavUrl,
133+
essentialNavUrl,
122134
availIn: {
123135
locale,
124136
version: versionRecord[pathConfig.locale][pathConfig.repo][name],
@@ -254,7 +266,8 @@ export const createDocHome = async ({
254266
const { id, name, pathConfig, filePath, slug } = node;
255267
const path = generateDocHomeUrl(name, pathConfig);
256268
const navUrl = generateNav(pathConfig);
257-
269+
const starterNavUrl = generateStarterNav(pathConfig);
270+
const essentialNavUrl = generateEssentialNav(pathConfig);
258271
const locale =
259272
process.env.WEBSITE_BUILD_TYPE === "archive"
260273
? [Locale.en, Locale.zh]
@@ -270,6 +283,8 @@ export const createDocHome = async ({
270283
// use for edit in github
271284
filePath,
272285
navUrl,
286+
starterNavUrl,
287+
essentialNavUrl,
273288
pageUrl: path,
274289
availIn: {
275290
locale,

gatsby/create-types.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,84 @@ export const createExtraType = ({ actions }: CreatePagesArgs) => {
6565
};
6666
},
6767
});
68+
69+
createFieldExtension({
70+
name: "starterNavigation",
71+
extend() {
72+
return {
73+
async resolve(
74+
mdxNode: any,
75+
args: unknown,
76+
context: unknown,
77+
info: any
78+
) {
79+
if (mdxNode.starterNav) return mdxNode.starterNav;
80+
const types = info.schema.getType("Mdx").getFields();
81+
const slug = await types["slug"].resolve(mdxNode, args, context, {
82+
fieldName: "slug",
83+
});
84+
85+
const mdxAST: Root = await types["mdxAST"].resolve(
86+
mdxNode,
87+
args,
88+
context,
89+
{
90+
fieldName: "mdxAST",
91+
}
92+
);
93+
94+
if (!slug.endsWith("TOC-tidb-cloud-starter"))
95+
throw new Error(`unsupported query in ${slug}`);
96+
const { config } = generateConfig(slug);
97+
const res = mdxAstToToc(mdxAST.children, config);
98+
mdxNode.starterNav = res;
99+
return res;
100+
},
101+
};
102+
},
103+
});
104+
105+
createFieldExtension({
106+
name: "essentialNavigation",
107+
extend() {
108+
return {
109+
async resolve(
110+
mdxNode: any,
111+
args: unknown,
112+
context: unknown,
113+
info: any
114+
) {
115+
if (mdxNode.essentialNav) return mdxNode.essentialNav;
116+
const types = info.schema.getType("Mdx").getFields();
117+
const slug = await types["slug"].resolve(mdxNode, args, context, {
118+
fieldName: "slug",
119+
});
120+
121+
const mdxAST: Root = await types["mdxAST"].resolve(
122+
mdxNode,
123+
args,
124+
context,
125+
{
126+
fieldName: "mdxAST",
127+
}
128+
);
129+
130+
if (!slug.endsWith("TOC-tidb-cloud-essential"))
131+
throw new Error(`unsupported query in ${slug}`);
132+
const { config } = generateConfig(slug);
133+
const res = mdxAstToToc(mdxAST.children, config);
134+
mdxNode.essentialNav = res;
135+
return res;
136+
},
137+
};
138+
},
139+
});
140+
68141
createTypes(`
69142
type Mdx implements Node {
70143
navigation: JSON! @navigation
144+
starterNavigation: JSON! @starterNavigation
145+
essentialNavigation: JSON! @essentialNavigation
71146
}
72147
`);
73148
};

gatsby/path.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export function generatePdfUrl(config: PathConfig) {
2828
export function generateNav(config: PathConfig) {
2929
return `${config.locale}/${config.repo}/${config.branch}/TOC`;
3030
}
31+
export function generateStarterNav(config: PathConfig) {
32+
return `${config.locale}/${config.repo}/${config.branch}/TOC-tidb-cloud-starter`;
33+
}
34+
export function generateEssentialNav(config: PathConfig) {
35+
return `${config.locale}/${config.repo}/${config.branch}/TOC-tidb-cloud-essential`;
36+
}
3137

3238
export function generateConfig(slug: string): {
3339
config: PathConfig;

gatsby/toc.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,58 @@ import {
88
PhrasingContent,
99
Heading,
1010
} from "mdast";
11+
import sig from "signale";
1112

1213
import { RepoNav, RepoNavLink, PathConfig } from "../src/shared/interface";
13-
import { generateUrl } from "./path";
14+
import { generateConfig, generateUrl } from "./path";
15+
import { CreatePagesArgs } from "gatsby";
16+
17+
interface TocQueryData {
18+
allMdx: {
19+
nodes: {
20+
id: string;
21+
slug: string;
22+
mdxAST: any;
23+
parent: {
24+
relativePath: string;
25+
};
26+
}[];
27+
};
28+
}
29+
30+
export const queryTOCs = async ({ graphql }: CreatePagesArgs) => {
31+
const tocQuery = await graphql<TocQueryData>(`
32+
{
33+
allMdx(filter: { fileAbsolutePath: { regex: "/TOC.*md$/" } }) {
34+
nodes {
35+
id
36+
slug
37+
mdxAST
38+
parent {
39+
... on File {
40+
relativePath
41+
}
42+
}
43+
}
44+
}
45+
}
46+
`);
47+
48+
if (tocQuery.errors) {
49+
sig.error(tocQuery.errors);
50+
}
51+
52+
const tocNodes = tocQuery.data!.allMdx.nodes;
53+
const tocMap = new Map<string, RepoNav>();
54+
55+
tocNodes.forEach((node: TocQueryData["allMdx"]["nodes"][0]) => {
56+
const { config } = generateConfig(node.slug);
57+
const toc = mdxAstToToc(node.mdxAST.children, config);
58+
tocMap.set(node.slug, toc);
59+
});
60+
61+
return Object.fromEntries(tocMap);
62+
};
1463

1564
export function mdxAstToToc(
1665
ast: Content[],

locale/en/translation.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@
176176
"viewLatestLTSVersion": "View latest LTS version docs"
177177
},
178178
"campaign": {
179-
"link": "https://labs.tidb.io/?utm_source=docs&utm_medium=direct&utm_campaign=labs_lp_05",
180-
"title": "Explore the new TiDB Labs, learn distributed SQL database and build RAG apps directly from your browser.",
181-
"date": "",
182-
"intro": ""
179+
"link": "https://tidbcloud.com/",
180+
"titleBeforeStarter": "TiDB Cloud Serverless is now ",
181+
"titleAfterStarter": "! Same experience, new name.",
182+
"end": "Try it out →"
183183
}
184184
},
185185
"campaign": {

locale/ja/translation.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
"cannotswitchZh": "このページは中国語ではご利用いただけません",
99
"cannotswitchJa": "このページは日本語ではご利用いただけません",
1010
"cannotswitchtocloudJa": "TiDB Cloud 日本語ドキュメントは現在利用できません",
11-
"cannotswitchtocloudZh": "TiDB Cloud 中国語ドキュメントは現在利用できません",
12-
"machineTransNotice1": "このページは英語版のページを機械翻訳しています。",
13-
"machineTransNotice2": "原文はこちらからご覧ください",
14-
"machineTransNotice3": ""
11+
"cannotswitchtocloudZh": "TiDB Cloud 中国語ドキュメントは現在利用できません"
1512
},
1613
"meta": {
1714
"title": "TiDB Docs",
@@ -162,10 +159,15 @@
162159
"viewLatestLTSVersion": "最新の LTS バージョンのドキュメントを表示する"
163160
},
164161
"campaign": {
165-
"link": "https://labs.tidb.io/ja?utm_source=docs&utm_medium=direct&utm_campaign=labs_lp_05",
166-
"title": "新しい TiDB Labs を探索し、ブラウザから直接分散型 SQL データベースを学び、RAG アプリを構築しましょう。",
167-
"date": "",
168-
"intro": ""
162+
"link": "https://tidbcloud.com/",
163+
"titleBeforeStarter": "TiDB Cloud Serverless が ",
164+
"titleAfterStarter": " に変わりました!使いやすさはそのままに、名前が新しくなりました。",
165+
"end": "ぜひお試しください →"
166+
},
167+
"autoTrans": {
168+
"titleBeforeStarter": "TiDB Cloud Serverless が ",
169+
"titleAfterStarter": " に変わりました!このページは自動翻訳されたものです。",
170+
"end": "原文はこちらからご覧ください。"
169171
}
170172
},
171173
"campaign": {

locale/zh/translation.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
"ja": "日本語",
77
"cannotswitchEn": "本页面暂无英文版",
88
"cannotswitchZh": "本页面暂无中文版",
9-
"cannotswitchJa": "本页面暂无日文版",
10-
"machineTransNotice1": "此页面由 AI 自动翻译,英文原文请见",
11-
"machineTransNotice2": "此处",
12-
"machineTransNotice3": ""
9+
"cannotswitchJa": "本页面暂无日文版"
1310
},
1411
"meta": {
1512
"title": "TiDB 文档中心",
@@ -177,10 +174,15 @@
177174
"viewLatestLTSVersion": "查看最新 LTS 版本文档"
178175
},
179176
"campaign": {
180-
"link": "https://labs.pingcap.com/?utm_source=docs&utm_medium=direct&utm_campaign=labs_zh_lp_04",
181-
"title": "探索全新的 TiDB Labs,直接在浏览器中学习分布式 SQL 数据库并构建 RAG 应用。",
182-
"date": "",
183-
"intro": ""
177+
"link": "https://tidbcloud.com/",
178+
"titleBeforeStarter": "TiDB Cloud Serverless 现已更名为 ",
179+
"titleAfterStarter": "!体验不变,名字焕新。",
180+
"end": "立即试用 →"
181+
},
182+
"autoTrans": {
183+
"titleBeforeStarter": "TiDB Cloud Serverless 现已更名为 ",
184+
"titleAfterStarter": "!此页面由 AI 自动翻译,英文原文请见",
185+
"end": "此处。"
184186
}
185187
},
186188
"campaign": {

src/components/Layout/Banner/ArchiveBanner.tsx

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)