From 2bfbe54c4ff6e4ca8de0b4a7b64d07ec82c4c2ad Mon Sep 17 00:00:00 2001 From: samzong Date: Thu, 14 Nov 2024 15:30:11 +0800 Subject: [PATCH] support i18n switch Signed-off-by: samzong --- .github/workflows/auto-label-pr.yaml | 18 ----- .github/workflows/auto-size-pr.yaml | 33 -------- .github/workflows/corrupted-hyperlink.yml | 69 ----------------- .github/workflows/main.path.yml | 91 ---------------------- .github/workflows/main.yml | 92 ----------------------- .github/workflows/pull-request-test.yaml | 56 -------------- .github/workflows/sync_from_upstream.yml | 41 ---------- Dockerfile | 3 +- docs/zh/mkdocs.yml | 30 ++++---- docs/zh/navigation.yml | 18 +++++ 10 files changed, 36 insertions(+), 415 deletions(-) delete mode 100644 .github/workflows/auto-label-pr.yaml delete mode 100644 .github/workflows/auto-size-pr.yaml delete mode 100644 .github/workflows/corrupted-hyperlink.yml delete mode 100644 .github/workflows/main.path.yml delete mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/pull-request-test.yaml delete mode 100644 .github/workflows/sync_from_upstream.yml diff --git a/.github/workflows/auto-label-pr.yaml b/.github/workflows/auto-label-pr.yaml deleted file mode 100644 index fdbb119431..0000000000 --- a/.github/workflows/auto-label-pr.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: Auto Labels PR - -# how usage: https://github.com/marketplace/actions/labeler - -on: -- pull_request_target - -jobs: - triage: - permissions: - contents: read - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/labeler@v4 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" - configuration-path: .github/labeler.yml # update role in this file diff --git a/.github/workflows/auto-size-pr.yaml b/.github/workflows/auto-size-pr.yaml deleted file mode 100644 index fccc6825be..0000000000 --- a/.github/workflows/auto-size-pr.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: Size labeler - -on: -- pull_request_target - -jobs: - size-labeler: - permissions: - issues: write - pull-requests: write - runs-on: ubuntu-latest - name: Label the PR size - steps: - - uses: codelytv/pr-size-labeler@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - xs_label: "size/xs" - xs_max_size: "9" - s_label: "size/s" - s_max_size: "29" - m_label: "size/m" - m_max_size: "99" - l_label: "size/l" - l_max_size: "499" - xl_label: "size/xl" - xl_max_size: "999" - xll_label: "size/xll" - xll_max_size: "1999" - fail_if_xll: "false" - message_if_xll: > - This PR exceeds the recommended size of 2000 lines. - Please make sure you are NOT addressing multiple issues with one PR. - Note this PR might be rejected due to its size. diff --git a/.github/workflows/corrupted-hyperlink.yml b/.github/workflows/corrupted-hyperlink.yml deleted file mode 100644 index d0c3d00a2a..0000000000 --- a/.github/workflows/corrupted-hyperlink.yml +++ /dev/null @@ -1,69 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: find corrupted hyperlink - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build-test: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Required for mkdocs to be able to display pages last update info - - uses: actions/setup-python@v2 - with: - python-version: 3.x - - # Runs a single command using the runners shell - - run: pip install mkdocs-material \ - mkdocs-git-revision-date-plugin \ - mkdocs-mermaid2-plugin \ - mkdocs-rss-plugin \ - mkdocs-minify-plugin \ - mkdocs-macros-plugin \ - mkdocs-git-revision-date-localized-plugin \ - mkdocs-awesome-pages-plugin \ - mkdocs-redirects \ - mkdocs-print-site-plugin \ - mkdocs-swagger-ui-tag \ - pyyaml - - # add custom plugin with pdf support - - run: pip install git+https://github.com/SAMZONG/mkdocs-with-pdf-support-material-v8 - - # check corrupted hyperlink - - run: pwd - - run: mkdocs build -f docs/zh/mkdocs.yml -d ../../public/ >> zh_build.log - - run: mkdocs build -f docs/en/mkdocs.yml -d ../../public/en/ >> en_build.log - - run: ls -lha - - run: echo "# zh_build.log" >> issue-body.txt - - run: grep -e 'WARNING.*\.md.*contains a link to.*not found' zh_build.log >> issue-body.txt - - run: echo "# en_build.log" >> issue-body.txt - - run: grep -e 'WARNING.*\.md.*contains a link to.*not found' en_build.log >> issue-body.txt - - # Create an issue if there are any warnings - - name: Create issue - uses: peter-evans/create-issue-from-file@v2 - with: - title: 'Corrupted document hyperlink' - body: | - ${{ steps.get_issue_body.outputs.body }} - labels: | - bug - corrupted-hyperlink - assignees: | - windsonsea - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ISSUE_BODY_PATH: ./issue-body.txt - id: get_issue_body \ No newline at end of file diff --git a/.github/workflows/main.path.yml b/.github/workflows/main.path.yml deleted file mode 100644 index c5f9748681..0000000000 --- a/.github/workflows/main.path.yml +++ /dev/null @@ -1,91 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: deploy-for-main-path - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -env: - UCLOUD_PUBLICKEY : ${{ secrets.UCLOUD_PUBLICKEY }} - UCLOUD_PRIVATEKEY : ${{ secrets.UCLOUD_PRIVATEKEY }} - UCLOUD_REGION : ${{ secrets.UCLOUD_REGION }} - UCLOUD_BUCKET : ${{ secrets.UCLOUD_BUCKET }} - CI: 1 - PIP_CONSTRAINT: /home/runner/work/DaoCloud-docs/DaoCloud-docs/constraints.txt - -concurrency: - group: ${{ github.workflow_ref }} - cancel-in-progress: true - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - deploy: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Required for mkdocs to be able to display pages last update info - - # Clone - - name: Checkout public repository - uses: actions/checkout@v4 - with: - repository: daocloud/daocloud-api-docs - path: dao-openapi - fetch-depth: 0 # Required for mkdocs to be able to display pages last update info - - - uses: actions/setup-python@v5 - with: - python-version: 3.x -# cache: 'pip' - - # Add ssh private key - - name: Setup SSH - uses: MrSquaare/ssh-setup-action@v1 - with: - host: github.com - private-key: ${{ secrets.SSH_PRIVATE_KEY }} - -# - run: pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple - - # Install mkdocs-material-insiders - - run: git clone git@github.com:DaoCloud/mkdocs-material-insiders.git mkdocs-material - - run: pip install -e mkdocs-material - - # Runs a single command using the runners shell - - run: pip install -r requirements.txt -c $PIP_CONSTRAINT - - # add custom plugin with pdf support - - run: pip install git+https://github.com/SAMZONG/mkdocs-with-pdf-support-material-v8 - - # merged openapi docs - - run: cp -av dao-openapi/docs/openapi docs/zh/docs/ - - run: python scripts/merged_nav.py - - # build docs - - run: pwd - - run: mkdocs build -f docs/zh/mkdocs.path.yaml -d ../../public/ - - run: mkdocs build -f docs/en/mkdocs.path.yaml -d ../../public/en/ - - # upload to ucloud bucket - - run: cd public && pwd && python ../scripts/upload-ucloud.py \ - public_key=$UCLOUD_PUBLICKEY \ - private_key=$UCLOUD_PRIVATEKEY \ - region=$UCLOUD_REGION \ - bucket=$UCLOUD_BUCKET - - # refresh docs site cdn cache - - run: python scripts/refresh_cdn_cache.py \ - publickey=$UCLOUD_PUBLICKEY \ - privatekey=$UCLOUD_PRIVATEKEY diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index b8865754b5..0000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,92 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: deploy-for-main - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -env: - UCLOUD_PUBLICKEY : ${{ secrets.UCLOUD_PUBLICKEY }} - UCLOUD_PRIVATEKEY : ${{ secrets.UCLOUD_PRIVATEKEY }} - UCLOUD_REGION : ${{ secrets.UCLOUD_REGION }} - UCLOUD_BUCKET : ${{ secrets.UCLOUD_BUCKET }} - CI: 1 - PIP_CONSTRAINT: /home/runner/work/DaoCloud-docs/DaoCloud-docs/constraints.txt - -concurrency: - group: ${{ github.workflow_ref }} - cancel-in-progress: true - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - deploy: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Required for mkdocs to be able to display pages last update info - - # Clone - - name: Checkout public repository - uses: actions/checkout@v2 - with: - repository: daocloud/daocloud-api-docs - path: dao-openapi - fetch-depth: 0 # Required for mkdocs to be able to display pages last update info - - - uses: actions/setup-python@v2 -# - uses: actions/setup-python@v4 - with: - python-version: 3.x -# cache: 'pip' - - # Add ssh private key - - name: Setup SSH - uses: MrSquaare/ssh-setup-action@v1 - with: - host: github.com - private-key: ${{ secrets.SSH_PRIVATE_KEY }} - -# - run: pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple - - # Install mkdocs-material-insiders - - run: git clone git@github.com:DaoCloud/mkdocs-material-insiders.git mkdocs-material - - run: pip install -e mkdocs-material - - # Runs a single command using the runners shell - - run: pip install -r requirements.txt -c $PIP_CONSTRAINT - - # add custom plugin with pdf support - - run: pip install git+https://github.com/SAMZONG/mkdocs-with-pdf-support-material-v8 - - # merged openapi docs - - run: cp -av dao-openapi/docs/openapi docs/zh/docs/ - - run: python scripts/merged_nav.py - - # build docs - - run: pwd - - run: mkdocs build -f docs/zh/mkdocs.yml -d ../../public/ - - run: mkdocs build -f docs/en/mkdocs.yml -d ../../public/en/ - - # upload to ucloud bucket - - run: cd public && pwd && python ../scripts/upload-ucloud.py \ - public_key=$UCLOUD_PUBLICKEY \ - private_key=$UCLOUD_PRIVATEKEY \ - region=$UCLOUD_REGION \ - bucket=$UCLOUD_BUCKET - - # refresh docs site cdn cache - - run: python scripts/refresh_cdn_cache.py \ - publickey=$UCLOUD_PUBLICKEY \ - privatekey=$UCLOUD_PRIVATEKEY diff --git a/.github/workflows/pull-request-test.yaml b/.github/workflows/pull-request-test.yaml deleted file mode 100644 index f9051e9875..0000000000 --- a/.github/workflows/pull-request-test.yaml +++ /dev/null @@ -1,56 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: pull-request-test - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - pull_request: - branches: - - main - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -env: - PIP_CONSTRAINT: /home/runner/work/DaoCloud-docs/DaoCloud-docs/constraints.txt - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build-test: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Required for mkdocs to be able to display pages last update info - - uses: actions/setup-python@v5 - with: - python-version: 3.x - - # # Add ssh private key - # - name: Setup SSH - # uses: MrSquaare/ssh-setup-action@v1 - # with: - # host: github.com - # private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - # # Install mkdocs-material-insiders - # - run: git clone git@github.com:DaoCloud/mkdocs-material-insiders.git mkdocs-material - # - run: pip install -e mkdocs-material - - - # Runs a single command using the runners shell - - run: pip install -r requirements.txt -c $PIP_CONSTRAINT - - # add custom plugin with pdf support - - run: pip install git+https://github.com/SAMZONG/mkdocs-with-pdf-support-material-v8 - - # build docs - - run: pwd - - run: mkdocs build -f docs/zh/mkdocs.yml -d ../../public/ - - run: mkdocs build -f docs/en/mkdocs.yml -d ../../public/en/ diff --git a/.github/workflows/sync_from_upstream.yml b/.github/workflows/sync_from_upstream.yml deleted file mode 100644 index 3a2ff4d942..0000000000 --- a/.github/workflows/sync_from_upstream.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Upstream Sync - -permissions: - contents: write - -on: - schedule: - - cron: "0 * * * *" # every hour - workflow_dispatch: - -jobs: - sync_latest_from_upstream: - name: Sync latest commits from upstream repo - runs-on: ubuntu-latest - if: ${{ github.event.repository.fork }} - - steps: - # Step 1: run a standard checkout action - - name: Checkout target repo - uses: actions/checkout@v3 - - # Step 2: run the sync action - - name: Sync upstream changes - id: sync - uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 - with: - # set your upstream repo and branch - upstream_sync_repo: DaoCloud/DaoCloud-docs - upstream_sync_branch: main - target_sync_branch: main - target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set - - # Set test_mode true to run tests instead of the true action!! - test_mode: false - - - name: Sync check - if: failure() - run: | - echo "::error::由于权限不足,导致同步失败(这是预期的行为),请前往仓库首页手动执行[Sync fork]。" - echo "::error::Due to insufficient permissions, synchronization failed (as expected). Please go to the repository homepage and manually perform [Sync fork]." - exit 1 diff --git a/Dockerfile b/Dockerfile index 39c95b3ad7..32d99cc7b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,8 @@ RUN pip install --no-cache-dir \ mkdocs-material \ mkdocs-minify-plugin \ pymdown-extensions \ - mkdocs-swagger-ui-tag + mkdocs-swagger-ui-tag \ + mkdocs-static-i18n # 复制项目文件 COPY docs/zh/ /docs diff --git a/docs/zh/mkdocs.yml b/docs/zh/mkdocs.yml index e1936d5886..6b25328267 100644 --- a/docs/zh/mkdocs.yml +++ b/docs/zh/mkdocs.yml @@ -24,6 +24,7 @@ strict: false # enable strict mode, https://www.mkdocs.org/user-guide/configurat # Configuration theme: name: material + language: zh features: - content.code.annotate @@ -75,27 +76,28 @@ theme: # Plugins plugins: - - search: - jieba_dict: dict.txt.small - jieba_dict_user: dict.txt.daocloud - lang: - - zh - - en + search: + jieba_dict: dict.txt.small + jieba_dict_user: dict.txt.daocloud + lang: + zh + en - - swagger-ui-tag # enable swagger-ui-tag plugin + swagger-ui-tag: # enable swagger-ui-tag plugin # Customization extra: # homepage: / # switch language - alternate: - - link: / - name: 简体中文 - lang: zh - - link: /en/ - name: English - lang: en +# alternate: +# - link: / +# name: 简体中文 +# lang: zh +# - link: /en/ +# name: English +# lang: en + generator: false status: diff --git a/docs/zh/navigation.yml b/docs/zh/navigation.yml index aaa427e90d..813cc16627 100644 --- a/docs/zh/navigation.yml +++ b/docs/zh/navigation.yml @@ -544,3 +544,21 @@ nav: - 容器管理 OpenAPI 文档: openapi/kpanda/index.md - 可观测性 OpenAPI 文档: openapi/insight/index.md - 全局管理 OpenAPI 文档: openapi/ghippo/index.md + +# i18n +plugins: + i18n: + docs_structure: folder + reconfigure_material: true + reconfigure_search: true + languages: + - locale: zh + name: 中文 + default: true + build: true + - locale: en + name: English + build: true + nav_translations: + # 首页: Home + # 用户注册: User Register \ No newline at end of file