diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 32591d77..eb2fd85a 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -3,6 +3,7 @@ import UnoCSS from 'unocss/vite'; import AutoImport from 'unplugin-auto-import/vite'; import { resolve } from 'node:path'; import { existsSync, cpSync } from 'node:fs'; +import { simpleGit } from 'simple-git'; const Logo = ` @@ -31,8 +32,50 @@ if (process.env.NODE_ENV === 'production') { } } +const branchInfo = await simpleGit('.', {}).pull().branch({}); + +const { current, branches } = branchInfo; +const isMain = current === 'main'; +const base = isMain ? '/' : `/${current}/`; +const domian = '//docs.deepwisdom.ai'; +const versions = Object.keys(branches).reduce((vs, branchname) => { + const regex = /^remotes\/origin\/(v.*)$/; + const [, remotebn] = regex.exec(branchname) || []; + if (remotebn && remotebn !== current) { + vs.push(remotebn); + } + return vs; +}, [] as string[]); + +const getVersions = () => { + if (!versions.length && isMain) { + return []; + } + return [ + { + text: current, + items: [ + ...(!isMain + ? [{ text: 'latest', link: `${domian}`, target: '_blank' }] + : []), + ...versions.map((v) => ({ + text: v, + link: `${domian}/${v}/`, + target: '_blank', + })), + ], + }, + ]; +}; + +const blogAndRfcVisible = isMain; +const arrVisible = (arr: any[], visible: boolean) => { + return visible ? arr : []; +}; + // https://vitepress.dev/reference/site-config export default defineConfig({ + base, title: 'MetaGPT', description: 'The Multi-Agent Framework', srcDir: './src', @@ -49,16 +92,22 @@ export default defineConfig({ link: '/enus/guide/get_started/introduction', activeMatch: '/enus/guide/', }, - { - text: 'Blog', - link: '/enus/blog/agents', - activeMatch: '/enus/blog/', - }, - { - text: 'RFCs', - link: '/enus/rfcs/RFC-116-MetaGPT优化方案', - activeMatch: '/enus/rfcs/', - }, + ...arrVisible( + [ + { + text: 'Blog', + link: '/enus/blog/agents', + activeMatch: '/blog/', + }, + { + text: 'RFCs', + link: '/enus/rfcs/RFC-116-MetaGPT优化方案', + activeMatch: '/euns/rfcs/', + }, + ], + blogAndRfcVisible + ), + ...getVersions(), ], sidebar: { '/enus/guide/': { @@ -209,16 +258,22 @@ export default defineConfig({ link: '/zhcn/guide/get_started/introduction', activeMatch: '/zhcn/guide/', }, - { - text: '博客', - link: '/zhcn/blog/agents', - activeMatch: '/zhcn/blog/', - }, - { - text: 'RFCs', - link: '/zhcn/rfcs/RFC-116-MetaGPT优化方案', - activeMatch: '/zhcn/rfcs/', - }, + ...arrVisible( + [ + { + text: '博客', + link: '/zhcn/blog/agents', + activeMatch: '/zhcn/blog/', + }, + { + text: 'RFCs', + link: '/zhcn/rfcs/RFC-116-MetaGPT优化方案', + activeMatch: '/zhcn/rfcs/', + }, + ], + blogAndRfcVisible + ), + ...getVersions(), ], sidebar: { '/zhcn/guide/': { diff --git a/package.json b/package.json index 0e7552fd..93f5f3dc 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dayjs": "^1.11.10", "lint-staged": "^15.0.2", "prettier": "^3.0.3", + "simple-git": "^3.20.0", "simple-git-hooks": "^2.9.0", "unocss": "^0.57.1", "unplugin-auto-import": "^0.16.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 979f172a..ab296a11 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ dependencies: prettier: specifier: ^3.0.3 version: 3.0.3 + simple-git: + specifier: ^3.20.0 + version: 3.21.0 simple-git-hooks: specifier: ^2.9.0 version: 2.9.0 @@ -506,6 +509,18 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: false + /@kwsites/file-exists@1.1.1: + resolution: {integrity: sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==} + dependencies: + debug: 4.3.4 + transitivePeerDependencies: + - supports-color + dev: false + + /@kwsites/promise-deferred@1.1.1: + resolution: {integrity: sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==} + dev: false + /@nodelib/fs.scandir@2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -1754,6 +1769,16 @@ packages: requiresBuild: true dev: false + /simple-git@3.21.0: + resolution: {integrity: sha512-oTzw9248AF5bDTMk9MrxsRzEzivMlY+DWH0yWS4VYpMhNLhDWnN06pCtaUyPnqv/FpsdeNmRqmZugMABHRPdDA==} + dependencies: + '@kwsites/file-exists': 1.1.1 + '@kwsites/promise-deferred': 1.1.1 + debug: 4.3.4 + transitivePeerDependencies: + - supports-color + dev: false + /sirv@2.0.3: resolution: {integrity: sha512-O9jm9BsID1P+0HOi81VpXPoDxYP374pkOLzACAoyUQ/3OUVndNpsz6wMnY2z+yOxzbllCKZrM+9QrWsv4THnyA==} engines: {node: '>= 10'}