Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
21 changes: 15 additions & 6 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ jobs:
runs-on: ubuntu-latest
name: Build website
steps:
- name: Check disk usage
run: df -h
- name: Remove unused Docker images
run: docker system prune -af
- name: Maximize build space
run: |
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
sudo docker builder prune -a
df -h

- uses: actions/checkout@v3
with:
Expand All @@ -63,7 +69,9 @@ jobs:
echo "build_date=$(date)" >> $GITHUB_OUTPUT

- name: Install deps
run: yarn
run: |
yarn
df -h

- name: Calc gatsby cache key
id: calc-cache-key
Expand Down Expand Up @@ -195,7 +203,8 @@ jobs:
architecture: "x64"

- name: Install Tencent Cloud CLI
run: pipx install tccli
run: |
pipx install tccli

- name: Purge production CDN cache
run: tccli cdn PurgePathCache --Paths '["https://docs-preview.pingcap.com/"]' --FlushType flush
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 2679 files
8 changes: 0 additions & 8 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import "./src/styles/global.css";

import { pageView } from "./scripts/track";

export { default as wrapRootElement } from "./src/state/wrap-with-provider";

export const onClientEntry = () => {
Expand All @@ -19,9 +17,3 @@ export const onClientEntry = () => {
=====================================
`);
};

export const onRouteUpdate = ({ location, prevLocation }) => {
if (process.env.NODE_ENV === "production") {
pageView();
}
};
2 changes: 1 addition & 1 deletion gatsby/cloud-plan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mdxAstToToc, TocQueryData } from "./toc";
import { generateConfig } from "./path";
import { extractFilesFromToc } from "./toc-filter";
import { CloudPlan } from "shared/useCloudPlan";
import { CloudPlan } from "shared/interface";

type TocMap = Map<
string,
Expand Down
22 changes: 22 additions & 0 deletions gatsby/create-pages/create-404.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { resolve } from "path";
import type { CreatePagesArgs } from "gatsby";
import { DEFAULT_BUILD_TYPE } from "./interface";
import { BuildType } from "../../src/shared/interface";

export const create404 = async ({
actions: { createPage },
}: CreatePagesArgs) => {
const template = resolve(__dirname, "../../src/templates/404Template.tsx");

createPage({
path: "/404/",
component: template,
context: {
buildType: (process.env.WEBSITE_BUILD_TYPE ??
DEFAULT_BUILD_TYPE) as BuildType,
feature: {
banner: false,
},
},
});
};
41 changes: 41 additions & 0 deletions gatsby/create-pages/create-cloud-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { resolve } from "path";

import type { CreatePagesArgs } from "gatsby";

import { Locale, BuildType } from "../../src/shared/interface";
import { docs as DOCS_CONFIG } from "../../docs/docs.json";
import { DEFAULT_BUILD_TYPE } from "./interface";

export const createCloudAPIReference = async ({
actions: { createPage },
}: CreatePagesArgs) => {
const template = resolve(
__dirname,
"../../src/templates/CloudAPIReferenceTemplate.tsx"
);
const pageCfg = DOCS_CONFIG.tidbcloud.openAPI;
const pageList = pageCfg.data;
const locale = [Locale.en];

pageList.forEach((page) => {
const path = `/tidbcloud/${pageCfg.path}/${page.pathname}`;
const isProduction = process.env.CI === "true";
createPage({
path,
component: template,
context: {
...page,
isProduction,
availIn: {
locale,
version: [],
},
buildType: (process.env.WEBSITE_BUILD_TYPE ??
DEFAULT_BUILD_TYPE) as BuildType,
feature: {
banner: false,
},
},
});
});
};
118 changes: 118 additions & 0 deletions gatsby/create-pages/create-doc-home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { resolve } from "path";

import type { CreatePagesArgs } from "gatsby";
import sig from "signale";

import { Locale, BuildType } from "../../src/shared/interface";
import {
generateConfig,
generateNav,
generateDocHomeUrl,
} from "../../gatsby/path";
import { DEFAULT_BUILD_TYPE, PageQueryData } from "./interface";

export const createDocHome = async ({
actions: { createPage },
graphql,
}: CreatePagesArgs) => {
// const template = resolve(__dirname, "../src/doc/index.tsx");
const template = resolve(__dirname, "../../src/templates/DocTemplate.tsx");

const prodQueryStr = `
{
allMdx(
filter: {
fileAbsolutePath: { regex: "/tidbcloud/master/_docHome.md$/" }
frontmatter: { draft: { ne: true } }
}
) {
nodes {
id
frontmatter {
aliases
}
slug
parent {
... on File {
relativePath
}
}
}
}
}
`;

const archiveQueryStr = `
{
allMdx(
filter: {
fileAbsolutePath: { regex: "/tidb/_docHome.md$/" }
frontmatter: { draft: { ne: true } }
}
) {
nodes {
id
frontmatter {
aliases
}
slug
parent {
... on File {
relativePath
}
}
}
}
}
`;

const docs = await graphql<PageQueryData>(
process.env.WEBSITE_BUILD_TYPE === "archive"
? archiveQueryStr
: prodQueryStr
);

if (docs.errors) {
sig.error(docs.errors);
}

const nodes = docs.data!.allMdx.nodes.map((node) => {
const { config, name, filePath } = generateConfig(node.slug);
return { ...node, pathConfig: config, name, filePath };
});

nodes.forEach((node) => {
const { id, name, pathConfig, filePath, slug } = node;
const path = generateDocHomeUrl(name, pathConfig);
const navUrl = generateNav(pathConfig);
const locale =
process.env.WEBSITE_BUILD_TYPE === "archive"
? [Locale.en, Locale.zh]
: [Locale.en, Locale.zh, Locale.ja];

createPage({
path,
component: template,
context: {
id,
name,
pathConfig,
// use for edit in github
filePath,
navUrl,
pageUrl: path,
availIn: {
locale,
version: [],
},
buildType: (process.env.WEBSITE_BUILD_TYPE ??
DEFAULT_BUILD_TYPE) as BuildType,
feature: {
banner: true,
feedback: true,
globalHome: true,
},
},
});
});
};
Loading