diff --git a/.dumirc.ts b/.dumirc.ts index 11a0c19a..739a35e8 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -1,12 +1,20 @@ // more config: https://d.umijs.org/config import { defineConfig } from 'dumi'; +const name = 'cssinjs'; + +const isProdSite = + // 不是预览模式 同时是生产环境 + process.env.PREVIEW !== 'true' && process.env.NODE_ENV === 'production'; + export default defineConfig({ favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], themeConfig: { - name: 'cssinjs', + name, logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', }, outputPath: '.doc', exportStatic: {}, + base: isProdSite ? `/${name}/` : '/', + publicPath: isProdSite ? `/${name}/` : '/', }); diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index d02059ae..c977add5 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -15,6 +15,6 @@ jobs: dist: .doc build: | npm install - npm run docs:build + npm run docs:preview - name: Get the preview_url run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" diff --git a/.github/workflows/site-deploy.yml b/.github/workflows/site-deploy.yml new file mode 100644 index 00000000..0c905004 --- /dev/null +++ b/.github/workflows/site-deploy.yml @@ -0,0 +1,39 @@ +name: Deploy website +on: + push: + tags: + - '*' + workflow_dispatch: + +permissions: + contents: write + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: setup node + uses: actions/setup-node@v1 + with: + node-version: 14 + + - name: create package-lock.json + run: npm i --package-lock-only --ignore-scripts + + - name: Install dependencies + run: npm ci + + - name: build Docs + run: npm run docs:build + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./.doc + force_orphan: true + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' diff --git a/package.json b/package.json index 5079514b..1343490d 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,9 @@ "start": "dumi dev", "docs:build": "dumi build", "docs:deploy": "gh-pages -d .doc", + "docs:preview": "PREVIEW=true npm run docs:build", "compile": "father build", - "gh-pages": "npm run docs:build && npm run docs:deploy", + "gh-pages": "npm run docs:build", "prepublishOnly": "npm run compile && np --yolo --no-publish", "postpublish": "npm run gh-pages", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",