Skip to content

Commit 6478436

Browse files
committed
feat: update docs
1 parent 77d8822 commit 6478436

6 files changed

Lines changed: 907 additions & 88 deletions

File tree

.dumi/theme/slots/LangSwitch/index.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,41 @@ const LangSwitch: React.FC = () => {
2323
const { hostname, href } = window.location;
2424

2525
const languages = [
26-
{ code: 'en', label: 'English', hostname: 'docs.nocobase.com' },
27-
{ code: 'cn', label: '简体中文', hostname: 'docs-cn.nocobase.com' },
28-
{ code: 'ja', label: '日本語', hostname: 'docs-jp.nocobase.com' },
29-
{ code: 'ru', label: 'Русский', hostname: 'docs-ru.nocobase.com' },
26+
{ code: 'en', label: 'English', pathPrefix: '/' },
27+
{ code: 'cn', label: '简体中文', pathPrefix: '/zh-CN' },
28+
{ code: 'ja', label: '日本語', pathPrefix: '/ja-JP' },
29+
{ code: 'ru', label: 'Русский', pathPrefix: '/ru-RU' },
30+
{ code: 'fr', label: 'Français', pathPrefix: '/fr-FR' },
3031
];
3132

32-
const currentLang = languages.find(lang => lang.hostname === hostname);
33+
const { pathname } = window.location;
34+
// Match non-default languages first, English is the fallback
35+
const nonDefaultLangs = languages.filter(lang => lang.pathPrefix !== '/');
36+
const currentLang = nonDefaultLangs.find(lang => pathname.startsWith(lang.pathPrefix)) || languages.find(lang => lang.code === 'en') || languages[0];
3337

3438
const handleMenuClick = ({ key }: { key: string }) => {
3539
const selectedLang = languages.find(lang => lang.code === key);
36-
if (selectedLang && selectedLang.hostname !== hostname) {
40+
if (selectedLang && selectedLang.code !== currentLang.code) {
3741
const url = new URL(href);
38-
url.hostname = selectedLang.hostname;
39-
url.port = ''; // 移除端口号
42+
// Strip current language prefix from pathname
43+
let cleanPath = pathname;
44+
if (currentLang.pathPrefix !== '/') {
45+
cleanPath = pathname.slice(currentLang.pathPrefix.length) || '/';
46+
}
47+
// For English (default), use path as-is; for others, add prefix
48+
if (selectedLang.pathPrefix === '/') {
49+
url.pathname = cleanPath;
50+
} else {
51+
url.pathname = selectedLang.pathPrefix + cleanPath;
52+
}
4053
window.location.href = url.toString();
4154
}
4255
};
4356

4457
const menu = (
4558
<Menu onClick={handleMenuClick}>
4659
{languages.map(lang => (
47-
<Menu.Item key={lang.code} disabled={lang.hostname === hostname}>
60+
<Menu.Item key={lang.code} disabled={lang.code === currentLang.code}>
4861
{lang.label}
4962
</Menu.Item>
5063
))}

.dumirc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export default defineConfig({
7979
footer: '© 2020-2024 NocoBase. All rights reserved.',
8080
alert:
8181
lang === 'zh-CN'
82-
? '<a target="_blank" style="color: inherit;" href="https://v2.docs.nocobase.com/cn/">V2 文档已发布,点此查看。</a>'
83-
: '<a target="_blank" style="color: inherit;" href="https://v2.docs.nocobase.com/">V2 documentation is now live — click here to view.</a>',
82+
? '<a target="_blank" style="color: inherit;" href="https://docs.nocobase.com/cn/">V2 文档已发布,点此查看。</a>'
83+
: '<a target="_blank" style="color: inherit;" href="https://docs.nocobase.com/">V2 documentation is now live — click here to view.</a>',
8484
localesEnhance: [
8585
{ id: 'zh-CN', switchPrefix: '中', hostname: 'docs-cn.nocobase.com' },
8686
{ id: 'en-US', switchPrefix: 'en', hostname: 'docs.nocobase.com' },

.github/workflows/deploy-docs.yml

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,80 @@ name: scp files
33
on:
44
push:
55
branches:
6-
- 'main'
6+
- "main"
77
paths:
8-
- 'docs/**'
9-
- '.github/workflows/deploy-docs.yml'
10-
- 'package.json'
11-
- '.dumi/theme/**'
12-
- '.dumirc.ts'
8+
- "docs/**"
9+
- ".github/workflows/deploy-docs.yml"
10+
- "package.json"
11+
- ".dumi/theme/**"
12+
- ".dumirc.ts"
1313
pull_request:
1414
branches:
15-
- '**'
15+
- "**"
1616
paths:
17-
- 'docs/**'
18-
- '.github/workflows/deploy-docs.yml'
19-
- 'package.json'
20-
- '.dumi/theme/**'
21-
- '.dumirc.ts'
17+
- "docs/**"
18+
- ".github/workflows/deploy-docs.yml"
19+
- "package.json"
20+
- ".dumi/theme/**"
21+
- ".dumirc.ts"
2222

2323
jobs:
2424
build:
2525
name: Build
2626
runs-on: ubuntu-latest
2727
steps:
28-
- uses: actions/checkout@v3
29-
- uses: actions/setup-node@v3
30-
with:
31-
node-version: "18"
32-
- run: yarn install
33-
- name: Build en-US
34-
env:
35-
DOC_LANG: en-US
36-
run: yarn build
37-
- name: Build zh-CN
38-
env:
39-
DOC_LANG: zh-CN
40-
run: yarn build
41-
- name: Build ja-JP
42-
env:
43-
DOC_LANG: ja-JP
44-
run: yarn build
45-
- name: Build ru-RU
46-
env:
47-
DOC_LANG: ru-RU
48-
run: yarn build
49-
- name: Build fr-FR
50-
env:
51-
DOC_LANG: fr-FR
52-
run: yarn build
53-
- name: Set tags
54-
id: set-tags
55-
run: |
56-
if [[ "${{ github.ref_name }}" == "main" ]]; then
57-
echo "::set-output name=tags::${{ github.ref_name }}"
58-
else
59-
echo "::set-output name=tags::pr-${{ github.event.pull_request.number }}"
60-
fi
61-
- name: copy files via ssh - ${{ steps.set-tags.outputs.tags }}
62-
uses: appleboy/scp-action@v0.1.4
63-
with:
64-
host: ${{ secrets.CN_HOST }}
65-
username: ${{ secrets.CN_USERNAME }}
66-
key: ${{ secrets.CN_KEY }}
67-
port: ${{ secrets.CN_PORT }}
68-
source: "dist/*"
69-
target: ${{ secrets.CN_TARGET }}/${{ steps.set-tags.outputs.tags }}
70-
- name: Push gh-pages
71-
if: ${{ github.ref_name == 'main' }}
72-
uses: peaceiris/actions-gh-pages@v3
73-
with:
74-
github_token: ${{ secrets.GITHUB_TOKEN }}
75-
publish_dir: ./dist/en-US
28+
- uses: actions/checkout@v3
29+
- uses: actions/setup-node@v3
30+
with:
31+
node-version: "22"
32+
- run: yarn install
33+
- name: Build en-US
34+
env:
35+
DOC_LANG: en-US
36+
run: yarn build
37+
- name: Build zh-CN
38+
env:
39+
DOC_LANG: zh-CN
40+
run: yarn build
41+
- name: Build ja-JP
42+
env:
43+
DOC_LANG: ja-JP
44+
run: yarn build
45+
- name: Build ru-RU
46+
env:
47+
DOC_LANG: ru-RU
48+
run: yarn build
49+
- name: Build fr-FR
50+
env:
51+
DOC_LANG: fr-FR
52+
run: yarn build
53+
- name: Upload docs to OSS and update CDN
54+
if: ${{ github.ref_name == 'main' }}
55+
env:
56+
DOCS_ALI_OSS_ACCESS_KEY_ID: ${{ secrets.DOCS_ALI_OSS_ACCESS_KEY_ID }}
57+
DOCS_ALI_OSS_ACCESS_KEY_SECRET: ${{ secrets.DOCS_ALI_OSS_ACCESS_KEY_SECRET }}
58+
DOCS_ALI_OSS_BUCKET: ${{ secrets.DOCS_ALI_OSS_BUCKET }}
59+
DOCS_ALI_OSS_REGION: ${{ secrets.DOCS_ALI_OSS_REGION }}
60+
DOCS_ALI_CDN_DOMAIN: ${{ secrets.DOCS_ALI_CDN_DOMAIN }}
61+
run: node scripts/upload-docs.js --dir ./dist
62+
- name: Set tags
63+
if: ${{ github.ref_name != 'main' }}
64+
id: set-tags
65+
run: |
66+
echo "tags=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
67+
- name: copy files via ssh - ${{ steps.set-tags.outputs.tags }}
68+
if: ${{ github.ref_name != 'main' }}
69+
uses: appleboy/scp-action@v0.1.4
70+
with:
71+
host: ${{ secrets.CN_HOST }}
72+
username: ${{ secrets.CN_USERNAME }}
73+
key: ${{ secrets.CN_KEY }}
74+
port: ${{ secrets.CN_PORT }}
75+
source: "dist/*"
76+
target: ${{ secrets.CN_TARGET }}/${{ steps.set-tags.outputs.tags }}
77+
- name: Push gh-pages
78+
if: ${{ github.ref_name == 'main' }}
79+
uses: peaceiris/actions-gh-pages@v3
80+
with:
81+
github_token: ${{ secrets.GITHUB_TOKEN }}
82+
publish_dir: ./dist/en-US

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
]
3030
},
3131
"devDependencies": {
32+
"@alicloud/cdn20180510": "^4.2.2",
3233
"@commitlint/cli": "^18.2.0",
3334
"@commitlint/config-conventional": "^18.1.0",
35+
"ali-oss": "^6.1.0",
3436
"cross-env": "^7.0.3",
3537
"dumi": "^2.2.14",
3638
"husky": "^8.0.3",

0 commit comments

Comments
 (0)