Files
gitea-docs/Makefile
HesterG 20c970682b Add Chinese support (#13)
# Main changes and Some notices

- Chines Docs should be put into corresponding versions' folders under `i18n/zh-cn/docusaurus-plugin-content-docs`. See [translate-markdown-files](https://docusaurus.io/docs/i18n/tutorial#translate-markdown-files) for reference. And also [srs-docs](https://github.com/ossrs/srs-docs) is a project that can be used as a reference. So changed the related paths in `loop_docs*` scripts.

- The markdown files under `docs/<version>` and `i18n/zh-cn/docusaurus-plugin-content-docs/<version>` must have the same name to be referred as translated. Files inside docs are corresponding to `current` version.
For example, `docs/administration/mail-templates.md` and `i18n/zh-cn/docusaurus-plugin-content-docs/current/administration/mail-templates.md`.  Filename of `mail-templates.md` must be the same (cannot be `mail-templates.zh-cn.md` and `mail-templates.us-en.md`)
So trim the `.en-us.md` and `.zh-cn.md` to `.md` to ensure the same names inside `loop_docs*` scripts.

- Used `npx docusaurus write-translations --locale zh-cn` to do sidebar, footer, and header translations, so no need to keep `sideBarCN` anymore. [reference](https://docusaurus.io/docs/cli#docusaurus-write-translations-sitedir)

- Local Tests for `en` and `zh-cn` are separeted, run the following on local respectly to test them

    ```bash
    # test en version
    npm run start
    # test zh-cn version
    npm run start -- --locale zh-cn
    ```

- If wants to test `en` and `zh-cn` both at the same time, run build and serve

    ```
    npm run build
    npm run serve
    ```

- Added some indexed page, for example:

![Screen Shot 2023-05-26 at 13.49.34](/attachments/9eeb3d38-c309-457d-9015-053b9c5ca8d6)

![Screen Shot 2023-05-26 at 13.49.49](/attachments/fc348d17-ce4c-4c4d-9240-b69add4ef06e)

Reviewed-on: https://gitea.com/gitea/gitea-docusaurus/pulls/13
Co-authored-by: HesterG <hestergong@gmail.com>
Co-committed-by: HesterG <hestergong@gmail.com>
2023-05-26 14:30:13 +08:00

84 lines
3.0 KiB
Makefile

ifeq ($(shell sed --version 2>/dev/null | grep -q GNU && echo gnu),gnu)
SED_INPLACE := sed -i
else
SED_INPLACE := sed -i ''
endif
.PHONY: all
all: build
.PHONY: create_dir
create_dir:
mkdir -p .tmp docs versioned_docs
.PHONY: clone_main
clone_main: create_dir
git clone --depth=1 --branch=main https://github.com/go-gitea/gitea.git .tmp/upstream-docs-latest
cur_path=`pwd`
cd .tmp/upstream-docs-latest/docs && make trans-copy
cd $(cur_path)
.PHONY: prepare-latest
prepare-latest: clone_main
cp -r .tmp/upstream-docs-latest/docs/static/* static/
rsync -avz --prune-empty-dirs --include '*/' --include='*.en-us.md' --exclude '*' .tmp/upstream-docs-latest/docs/content/doc/ docs/
cp .tmp/upstream-docs-latest/docs/content/page/index.en-us.md docs/intro.md
cp .tmp/upstream-docs-latest/templates/swagger/v1_json.tmpl static/latest-swagger.json
bash loop_docs.sh
.PHONY: prepare-latest-zh-cn
prepare-latest-zh-cn:
# clone_main
# cp -r .tmp/upstream-docs-latest/docs/static/* static/
mkdir -p i18n/zh-cn/docusaurus-plugin-content-docs/current
rsync -avz --prune-empty-dirs --include '*/' --include='*.zh-cn.md' --exclude '*' .tmp/upstream-docs-latest/docs/content/doc/ i18n/zh-cn/docusaurus-plugin-content-docs/current/
cp .tmp/upstream-docs-latest/docs/content/page/index.zh-cn.md i18n/zh-cn/docusaurus-plugin-content-docs/current/intro.md
bash loop_docs-zh-cn.sh
.PHONY: clone_\#%
clone_\#%: create_dir
git clone --depth=1 --branch=release/v1.$* https://github.com/go-gitea/gitea.git .tmp/upstream-docs-$*
cur_path=`pwd`
cd .tmp/upstream-docs-$*/docs && make trans-copy
cd $(cur_path)
.PHONY: prepare\#%
prepare\#%: clone_\#%
cp -r .tmp/upstream-docs-$*/docs/static/* static/
rsync -a --prune-empty-dirs --include '*/' --include='*.en-us.md' --exclude '*' .tmp/upstream-docs-$*/docs/content/doc/ versioned_docs/version-1.$*/
cp .tmp/upstream-docs-$*/docs/content/page/index.en-us.md versioned_docs/version-1.$*/intro.md
cp .tmp/upstream-docs-$*/templates/swagger/v1_json.tmpl static/$*-swagger.json
bash loop_docs-$*.sh
rm versioned_docs/version-1.$*/help/search.md || true
.PHONY: prepare-zh-cn\#%
prepare-zh-cn\#%:
# clone_\#%
# cp -r .tmp/upstream-docs-$*/docs/static/* static/
mkdir -p i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$*
rsync -avz --prune-empty-dirs --include '*/' --include='*.zh-cn.md' --exclude '*' .tmp/upstream-docs-$*/docs/content/doc/ i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$*/
cp .tmp/upstream-docs-19/docs/content/page/index.zh-cn.md i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$*/intro.md
bash loop_docs-$*-zh-cn.sh
rm i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$*/help/search.md || true
.PHONY: install
install:
npm install
.PHONY: build
build: install prepare-latest prepare\#19 prepare-latest-zh-cn prepare-zh-cn\#19
npm ci
npm run build
.PHONY: serve
serve: install prepare-latest prepare\#19 prepare-latest-zh-cn prepare-zh-cn\#19
npm run start
.PHONY: clean
clean:
rm -rf .tmp
rm -rf docs
rm -rf versioned_docs/
rm -rf static/_*
rm -rf static/latest-swagger.json
rm -rf static/19-swagger.json