|
@@ -14,21 +14,26 @@ import {
|
|
|
import fs from "node:fs";
|
|
|
import path from "node:path";
|
|
|
import { exec } from "child_process";
|
|
|
+import { buildSideBar } from "../utils/sideBar";
|
|
|
|
|
|
const DOC_BASE_PATH = "pages";
|
|
|
|
|
|
-// 执行 git restore 命令
|
|
|
-await new Promise((resolve, reject) =>
|
|
|
- exec(`git restore ${DOC_BASE_PATH}`, (error, stdout, stderr) => {
|
|
|
- if (error) {
|
|
|
- console.error(`执行 git restore 时出错: ${error.message}`);
|
|
|
- reject(stderr);
|
|
|
- }
|
|
|
- console.log(`git restore 输出结果: ${stdout}`);
|
|
|
- resolve(stdout);
|
|
|
- })
|
|
|
-);
|
|
|
-process.exit();
|
|
|
+if (process.env.NODE_ENV === "production") {
|
|
|
+ // 执行清理pages命令
|
|
|
+ await new Promise((resolve, reject) =>
|
|
|
+ exec(
|
|
|
+ `git checkout -- ${DOC_BASE_PATH} & git clean -df ${DOC_BASE_PATH}`,
|
|
|
+ (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ console.error(`清理pages时出错: ${error.message}`);
|
|
|
+ reject(stderr);
|
|
|
+ }
|
|
|
+ console.log(`清理pages结果: ${stdout}`);
|
|
|
+ resolve(stdout);
|
|
|
+ }
|
|
|
+ )
|
|
|
+ );
|
|
|
+}
|
|
|
|
|
|
// 从S3构建pages里面的markdown文件
|
|
|
const s3 = new S3Client({
|
|
@@ -42,9 +47,7 @@ const command = new ListObjectsCommand({
|
|
|
Bucket: process.env.VITE_DOCS_LIST_BUCKET,
|
|
|
});
|
|
|
const { Contents: contents } = await s3.send(command);
|
|
|
-console.log(contents);
|
|
|
-process.exit();
|
|
|
-await fs.emptyDir(DOC_BASE_PATH, { recursive: true });
|
|
|
+
|
|
|
await Promise.all(
|
|
|
contents!.map((content) => {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
@@ -69,6 +72,14 @@ await Promise.all(
|
|
|
);
|
|
|
|
|
|
// 构建sideBar数据
|
|
|
+let { rootSideBar, zhHKSideBar } = buildSideBar(contents);
|
|
|
+// rootSideBar = rootSideBar.map(sb => { sb.items = undefined;return sb })
|
|
|
+import util from "util";
|
|
|
+console.log(
|
|
|
+ util.inspect(rootSideBar, { showHidden: false, depth: null, colors: true }),
|
|
|
+ util.inspect(zhHKSideBar, { showHidden: false, depth: null, colors: true })
|
|
|
+);
|
|
|
+// process.exit();
|
|
|
|
|
|
// https://vitepress.dev/reference/site-config
|
|
|
export default defineConfig({
|
|
@@ -181,19 +192,22 @@ export default defineConfig({
|
|
|
// { text: 'Home', link: '/' },
|
|
|
// { text: 'Examples', link: '/markdown-examples' }
|
|
|
// ],
|
|
|
- sidebar: [
|
|
|
- { text: "关于CocoBlockly X", link: "/docs" },
|
|
|
- { text: "常见问题解答", link: "/docs/常见问题解答" },
|
|
|
- {
|
|
|
- text: "开始使用CocoBlockly X",
|
|
|
- link: "/docs/start-using-cocoblockly-x",
|
|
|
- },
|
|
|
- {
|
|
|
- text: "电子模块基本教学",
|
|
|
- collapsed: true,
|
|
|
- items: [{ text: "todo", link: "/docs" }],
|
|
|
- },
|
|
|
- ],
|
|
|
+ // sidebar: [
|
|
|
+ // { text: "关于CocoBlockly X", link: "/docs" },
|
|
|
+ // { text: "常见问题解答", link: "/docs/常见问题解答" },
|
|
|
+ // {
|
|
|
+ // text: "开始使用CocoBlockly X",
|
|
|
+ // link: "/docs/start-using-cocoblockly-x",
|
|
|
+ // collapsed: true,
|
|
|
+ // items: [],
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // text: "电子模块基本教学",
|
|
|
+ // collapsed: true,
|
|
|
+ // items: [{ text: "todo", link: "/docs" }],
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ sidebar: rootSideBar,
|
|
|
// socialLinks: [
|
|
|
// { icon: 'github', link: 'https://github.com/vuejs/vitepress' }
|
|
|
// ]
|