Skip to content

Commit 4505cd9

Browse files
shhdgitlilin90wd0517
authored
Premium preview merge master (#655)
* fix: update TOC item access in DocTemplate component - Modified the condition for accessing TOC items to ensure it handles undefined cases correctly. - Updated the dependency array in the useMemo hook to include the entire toc object for better stability in TOC data generation. * feat: add support for premium slug in generateConfig function (#647) * feat: add support for premium slug in generateConfig function - Introduced a new condition to handle slugs that include "premium/", allowing for better categorization in the configuration generation process. * refactor: update CloudPlan import paths across components - Replaced imports of CloudPlan from "shared/useCloudPlan" to "shared/interface" for consistency and clarity. - Adjusted related components to ensure proper usage of the updated CloudPlan type definition. * feat: extend EXTENDS_FOLDERS to include premium plan - Updated the EXTENDS_FOLDERS constant to include "premium" as a valid CloudPlan option, enhancing the flexibility of the table of contents generation. - Adjusted the type definition to ensure consistency with the new CloudPlan import. * feat: add CloudPlan type to path.ts for enhanced configuration - Imported CloudPlan into path.ts to support additional configuration options. - Updated the prefix variable type to CloudPlan | undefined for improved type safety in the generateConfig function. * feat: restructure page creation logic by modularizing create-pages functionality - Removed the existing create-pages.ts file and replaced it with modular files for creating specific pages: create-docs, create-doc-home, create-cloud-api, create-search, and create-404. - Introduced an interface file to define common types and constants, enhancing code organization and maintainability. - Each new file encapsulates the logic for creating its respective page, improving clarity and separation of concerns in the page generation process. * refactor: simplify prefix determination in generateConfig function - Replaced multiple conditional checks for slug prefixes with a more concise approach using an array and the find method. - Maintained the existing logic for handling the dedicated prefix based on the presence of a name, improving code readability and maintainability. * fix: update template import paths in page creation files - Adjusted the import paths for template files in create-404, create-cloud-api, create-doc-home, create-docs, and create-search to ensure correct resolution. - Enhanced consistency across page creation logic by standardizing the path structure. * chore: add disk usage checks throughout production workflow - Introduced disk usage checks at various stages of the production workflow to monitor system resource usage. - Added checks after Docker image cleanup, node setup, dependency installation, cache restoration, and before/after deployment steps for better resource management. * chore: enhance production workflow by maximizing build space - Added a step to maximize build space using the easimon/maximize-build-space action, allowing for better resource management during builds. - Included additional disk usage checks to monitor space before and after the build process, improving overall workflow efficiency. * refactor: streamline production workflow commands for clarity - Consolidated multiple run commands into single block executions for installing dependencies and purging CDN cache, enhancing readability and maintainability of the workflow script. * chore: rename markdown source in gatsby-config for consistency - Updated the name of the markdown source from `markdown-pages1` to `markdown-pages` for improved clarity and consistency in the configuration. * refactor: optimize disk space management in production workflow - Removed redundant disk usage checks and consolidated cleanup commands into a single run step to streamline the production workflow. - Enhanced disk space management by directly removing unnecessary directories and pruning Docker images, improving build efficiency. * Update sentry sample rate (#650) * chore: adjust tracesSampleRate in Sentry configuration for improved performance * fix: improve node removal safety in useTotalContributors hook * fix: correct dependency array in TabContentDetector to ensure proper rendering behavior * fix: enhance TabContentDetector to prevent duplicate rendering of tabs - Added renderedTabs prop to SimpleTab and TabContentDetector components. - Updated useEffect in TabContentDetector to check if the tab has already been rendered, ensuring proper rendering behavior and preventing duplicate calls to onRendered. * feat: update HeaderNav to conditionally render cloud plan links - Integrated useCloudPlan hook to retrieve the current cloud plan. - Modified navigation links in HeaderNavStack and HeaderNavStackMobile to dynamically adjust the URL based on the cloud plan, enhancing user experience. * fix: correct optional chaining in filterRightToc function - Removed optional chaining for item.items to ensure proper filtering of nested items in the filterRightToc function, enhancing functionality. * fix: update HeaderNav links to handle undefined cloud plans - Modified the navigation links in HeaderNavStack and HeaderNavStackMobile to include a condition that allows for rendering the default URL when the cloud plan is undefined, improving user experience and navigation reliability. * src, static: update cn.pingcap.com links (#652) * tweak: remove pingcap account track script (#654) * Adjust TOC to support the same article linking from multiple locations (#653) * feat: enhance navigation state management with session storage - Updated the LeftNavTree component to support saving and retrieving navigation item IDs from session storage, improving user experience by maintaining state across sessions. - Modified the calcExpandedIds function to accept an optional targetId for more precise matching. - Implemented helper functions to handle session storage interactions for navigation items. * refactor: simplify navigation state management in LeftNavTree component - Removed session storage interactions for expanded and selected navigation items, streamlining state management. - Updated the calcExpandedIds function calls to eliminate unnecessary parameters, enhancing clarity and performance. * refactor: simplify scroll behavior in scrollToElementIfInView function - Updated the scrollToElementIfInView function to directly call scrollIntoView with a "center" block option, removing unnecessary viewport checks and improving code clarity. * refactor: reorganize imports and streamline createDocs function - Updated import paths for clarity and consistency. - Removed unused navigation URL generation functions to simplify the createDocs logic. - Introduced a default value for inDefaultPlan to enhance code readability. * refactor: simplify HeaderNav links by removing cloud plan conditions - Removed cloud plan checks from navigation links in HeaderNavStack and HeaderNavStackMobile, streamlining the URL generation for the TiDB Cloud link. - Cleaned up unused imports related to cloud plan management for improved code clarity. * refactor: update createDocHome to target new documentation path - Changed the regex filter in createDocHome to point to the updated documentation file path for TiDB Cloud. - Removed unused navigation URL generation functions to streamline the code and improve clarity. --------- Co-authored-by: Lilian Lee <lilin@pingcap.com> Co-authored-by: WD <me@wangdi.ink>
1 parent 87d7b28 commit 4505cd9

29 files changed

+354
-309
lines changed

.github/workflows/production.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ jobs:
3636
runs-on: ubuntu-latest
3737
name: Build website
3838
steps:
39-
- name: Check disk usage
40-
run: df -h
41-
- name: Remove unused Docker images
42-
run: docker system prune -af
39+
- name: Maximize build space
40+
run: |
41+
df -h
42+
sudo rm -rf /usr/share/dotnet
43+
sudo rm -rf /usr/local/lib/android
44+
sudo rm -rf /opt/ghc
45+
sudo rm -rf /opt/hostedtoolcache/CodeQL
46+
sudo docker image prune --all --force
47+
sudo docker builder prune -a
48+
df -h
4349
4450
- uses: actions/checkout@v3
4551
with:
@@ -63,7 +69,9 @@ jobs:
6369
echo "build_date=$(date)" >> $GITHUB_OUTPUT
6470
6571
- name: Install deps
66-
run: yarn
72+
run: |
73+
yarn
74+
df -h
6775
6876
- name: Calc gatsby cache key
6977
id: calc-cache-key
@@ -195,7 +203,8 @@ jobs:
195203
architecture: "x64"
196204

197205
- name: Install Tencent Cloud CLI
198-
run: pipx install tccli
206+
run: |
207+
pipx install tccli
199208
200209
- name: Purge production CDN cache
201210
run: tccli cdn PurgePathCache --Paths '["https://docs-preview.pingcap.com/"]' --FlushType flush

docs

Submodule docs updated 2679 files

gatsby-browser.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import "./src/styles/global.css";
22

3-
import { pageView } from "./scripts/track";
4-
53
export { default as wrapRootElement } from "./src/state/wrap-with-provider";
64

75
export const onClientEntry = () => {
@@ -19,9 +17,3 @@ export const onClientEntry = () => {
1917
=====================================
2018
`);
2119
};
22-
23-
export const onRouteUpdate = ({ location, prevLocation }) => {
24-
if (process.env.NODE_ENV === "production") {
25-
pageView();
26-
}
27-
};

gatsby/cloud-plan.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mdxAstToToc, TocQueryData } from "./toc";
22
import { generateConfig } from "./path";
33
import { extractFilesFromToc } from "./toc-filter";
4-
import { CloudPlan } from "shared/useCloudPlan";
4+
import { CloudPlan } from "shared/interface";
55

66
type TocMap = Map<
77
string,

gatsby/create-pages/create-404.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { resolve } from "path";
2+
import type { CreatePagesArgs } from "gatsby";
3+
import { DEFAULT_BUILD_TYPE } from "./interface";
4+
import { BuildType } from "../../src/shared/interface";
5+
6+
export const create404 = async ({
7+
actions: { createPage },
8+
}: CreatePagesArgs) => {
9+
const template = resolve(__dirname, "../../src/templates/404Template.tsx");
10+
11+
createPage({
12+
path: "/404/",
13+
component: template,
14+
context: {
15+
buildType: (process.env.WEBSITE_BUILD_TYPE ??
16+
DEFAULT_BUILD_TYPE) as BuildType,
17+
feature: {
18+
banner: false,
19+
},
20+
},
21+
});
22+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { resolve } from "path";
2+
3+
import type { CreatePagesArgs } from "gatsby";
4+
5+
import { Locale, BuildType } from "../../src/shared/interface";
6+
import { docs as DOCS_CONFIG } from "../../docs/docs.json";
7+
import { DEFAULT_BUILD_TYPE } from "./interface";
8+
9+
export const createCloudAPIReference = async ({
10+
actions: { createPage },
11+
}: CreatePagesArgs) => {
12+
const template = resolve(
13+
__dirname,
14+
"../../src/templates/CloudAPIReferenceTemplate.tsx"
15+
);
16+
const pageCfg = DOCS_CONFIG.tidbcloud.openAPI;
17+
const pageList = pageCfg.data;
18+
const locale = [Locale.en];
19+
20+
pageList.forEach((page) => {
21+
const path = `/tidbcloud/${pageCfg.path}/${page.pathname}`;
22+
const isProduction = process.env.CI === "true";
23+
createPage({
24+
path,
25+
component: template,
26+
context: {
27+
...page,
28+
isProduction,
29+
availIn: {
30+
locale,
31+
version: [],
32+
},
33+
buildType: (process.env.WEBSITE_BUILD_TYPE ??
34+
DEFAULT_BUILD_TYPE) as BuildType,
35+
feature: {
36+
banner: false,
37+
},
38+
},
39+
});
40+
});
41+
};
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { resolve } from "path";
2+
3+
import type { CreatePagesArgs } from "gatsby";
4+
import sig from "signale";
5+
6+
import { Locale, BuildType } from "../../src/shared/interface";
7+
import {
8+
generateConfig,
9+
generateNav,
10+
generateDocHomeUrl,
11+
} from "../../gatsby/path";
12+
import { DEFAULT_BUILD_TYPE, PageQueryData } from "./interface";
13+
14+
export const createDocHome = async ({
15+
actions: { createPage },
16+
graphql,
17+
}: CreatePagesArgs) => {
18+
// const template = resolve(__dirname, "../src/doc/index.tsx");
19+
const template = resolve(__dirname, "../../src/templates/DocTemplate.tsx");
20+
21+
const prodQueryStr = `
22+
{
23+
allMdx(
24+
filter: {
25+
fileAbsolutePath: { regex: "/tidbcloud/master/_docHome.md$/" }
26+
frontmatter: { draft: { ne: true } }
27+
}
28+
) {
29+
nodes {
30+
id
31+
frontmatter {
32+
aliases
33+
}
34+
slug
35+
parent {
36+
... on File {
37+
relativePath
38+
}
39+
}
40+
}
41+
}
42+
}
43+
`;
44+
45+
const archiveQueryStr = `
46+
{
47+
allMdx(
48+
filter: {
49+
fileAbsolutePath: { regex: "/tidb/_docHome.md$/" }
50+
frontmatter: { draft: { ne: true } }
51+
}
52+
) {
53+
nodes {
54+
id
55+
frontmatter {
56+
aliases
57+
}
58+
slug
59+
parent {
60+
... on File {
61+
relativePath
62+
}
63+
}
64+
}
65+
}
66+
}
67+
`;
68+
69+
const docs = await graphql<PageQueryData>(
70+
process.env.WEBSITE_BUILD_TYPE === "archive"
71+
? archiveQueryStr
72+
: prodQueryStr
73+
);
74+
75+
if (docs.errors) {
76+
sig.error(docs.errors);
77+
}
78+
79+
const nodes = docs.data!.allMdx.nodes.map((node) => {
80+
const { config, name, filePath } = generateConfig(node.slug);
81+
return { ...node, pathConfig: config, name, filePath };
82+
});
83+
84+
nodes.forEach((node) => {
85+
const { id, name, pathConfig, filePath, slug } = node;
86+
const path = generateDocHomeUrl(name, pathConfig);
87+
const navUrl = generateNav(pathConfig);
88+
const locale =
89+
process.env.WEBSITE_BUILD_TYPE === "archive"
90+
? [Locale.en, Locale.zh]
91+
: [Locale.en, Locale.zh, Locale.ja];
92+
93+
createPage({
94+
path,
95+
component: template,
96+
context: {
97+
id,
98+
name,
99+
pathConfig,
100+
// use for edit in github
101+
filePath,
102+
navUrl,
103+
pageUrl: path,
104+
availIn: {
105+
locale,
106+
version: [],
107+
},
108+
buildType: (process.env.WEBSITE_BUILD_TYPE ??
109+
DEFAULT_BUILD_TYPE) as BuildType,
110+
feature: {
111+
banner: true,
112+
feedback: true,
113+
globalHome: true,
114+
},
115+
},
116+
});
117+
});
118+
};

0 commit comments

Comments
 (0)