diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2de9b3c..378335f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -74,4 +74,18 @@ jobs: uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2 with: args: --offline --no-progress --root-dir "${{ github.workspace }}" 'apps/rlark/docs/**/*.md' - lycheeVersion: v0.24.2 \ No newline at end of file + lycheeVersion: v0.24.2 + + - name: Build Chinese Read the Docs output + env: + READTHEDOCS_CANONICAL_URL: https://rlark.readthedocs.io/zh-cn/latest/ + READTHEDOCS_LANGUAGE: zh-cn + READTHEDOCS_VERSION: latest + run: | + python apps/rlark/docs/rtd_patch.py + mkdocs build --strict --config-file apps/rlark/mkdocs.yml --site-dir "$GITHUB_WORKSPACE/site-rtd-zh" + grep -F 'src="images/logo-zh.png"' site-rtd-zh/index.html + grep -F 'src="images/architecture-zh.svg"' site-rtd-zh/index.html + grep -F 'src="../images/architecture-zh.svg"' site-rtd-zh/architecture/index.html + test -f site-rtd-zh/images/logo-zh.png + test -f site-rtd-zh/images/architecture-zh.svg diff --git a/apps/rlark/docs/rtd_patch.py b/apps/rlark/docs/rtd_patch.py index e7298d2..3fd3d1d 100644 --- a/apps/rlark/docs/rtd_patch.py +++ b/apps/rlark/docs/rtd_patch.py @@ -2,6 +2,7 @@ import os import re +from pathlib import Path from urllib.parse import urlsplit, urlunsplit @@ -61,4 +62,20 @@ with open(config_path, "w", encoding="utf-8") as config_file: config_file.write(content) +if lang == "zh": + zh_docs = Path("apps/rlark/docs/zh") + for doc_path in zh_docs.rglob("*.md"): + relative_depth = len(doc_path.relative_to(zh_docs).parent.parts) + source_prefix = "../" * (relative_depth + 1) + "images/" + output_prefix = "../" * relative_depth + "images/" + + doc_content = doc_path.read_text(encoding="utf-8") + patched_content = re.sub( + rf"(?P\bsrc\s*=\s*[\"']){re.escape(source_prefix)}", + rf"\g{output_prefix}", + doc_content, + ) + if patched_content != doc_content: + doc_path.write_text(patched_content, encoding="utf-8") + print(f"[i18n] build_only_locale={lang}")