From d698965203307439310c84b52569ca3736900d54 Mon Sep 17 00:00:00 2001
From: hmol233 <82594500+hmol233@users.noreply.github.com>
Date: Wed, 15 Sep 2021 18:28:06 +0800
Subject: [PATCH] action: build for main repository

---
 .github/workflows/build.yml | 14 ++++++++++++++
 docs/.vuepress/config.ts    | 13 +++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 38ef41c..be0a557 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -25,6 +25,8 @@ jobs:
           restore-keys: |
             ${{ runner.os }}-yarn-
       - name: Install and Build
+        env:
+          XRAY_DOCS_USE_VITE: "true"
         run: |
           yarn install
           yarn docs:build
@@ -33,3 +35,15 @@ jobs:
         with:
           github_token: ${{ secrets.GITHUB_TOKEN }}
           publish_dir: docs/.vuepress/dist
+      - name: Build for Main Repository
+        env:
+          XRAY_DOCS_MAIN_REPO: "true"
+        run: |
+          yarn docs:build
+      - name: Deploy to main Repository
+        uses: peaceiris/actions-gh-pages@v3
+        with:
+          github_token: ${{ secrets.GITHUB_TOKEN }}
+          publish_dir: docs/.vuepress/dist
+          external_repository: XTLS/XTLS.github.io
+          publish_branch: gh-pages-next
diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts
index 5d0056a..293b0d3 100644
--- a/docs/.vuepress/config.ts
+++ b/docs/.vuepress/config.ts
@@ -5,6 +5,15 @@ import * as navbar from "./config/navbar";
 import * as path from "path";
 
 const isProduction = process.env.NODE_ENV === "production";
+const forMainRepo = process.env.XRAY_DOCS_MAIN_REPO === "true";
+const useVite = process.env.XRAY_DOCS_USE_VITE === "true";
+
+console.log("environment: \n", process.env);
+console.log("base:", forMainRepo ? "/" : "/Xray-docs-next/");
+console.log(
+  "bundler:",
+  isProduction && !useVite ? "@vuepress/webpack" : "@vuepress/vite"
+);
 
 export default defineUserConfig<DefaultThemeOptions>({
   theme: path.join(__dirname, "./theme"),
@@ -21,7 +30,7 @@ export default defineUserConfig<DefaultThemeOptions>({
     ],
     ["@vuepress/plugin-debug", !isProduction],
   ],
-  base: "/Xray-docs-next/",
+  base: forMainRepo ? "/" : "/Xray-docs-next/",
   locales: {
     "/": {
       lang: "zh-CN",
@@ -130,5 +139,5 @@ export default defineUserConfig<DefaultThemeOptions>({
   extendsMarkdown: (md) => {
     md.use(require("markdown-it-footnote"));
   },
-  bundler: isProduction ? "@vuepress/webpack" : "@vuepress/vite",
+  bundler: isProduction && !useVite ? "@vuepress/webpack" : "@vuepress/vite",
 });