From b35b6cb10b323955d716686ecf9ee31b16681393 Mon Sep 17 00:00:00 2001 From: Yifei Ding Date: Sat, 19 Mar 2022 13:57:56 -0700 Subject: [PATCH] _klipper3d: New language translation deployment Signed-off-by: Yifei Ding Signed-off-by: Kevin O'Connor --- .github/workflows/klipper3d-deploy.yaml | 12 +++-- docs/_klipper3d/README | 14 ++++++ docs/_klipper3d/build-translations.sh | 58 +++++++++++++++++++++++++ docs/_klipper3d/mkdocs.yml | 7 ++- 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100755 docs/_klipper3d/build-translations.sh diff --git a/.github/workflows/klipper3d-deploy.yaml b/.github/workflows/klipper3d-deploy.yaml index 812931c7..ba6c157b 100644 --- a/.github/workflows/klipper3d-deploy.yaml +++ b/.github/workflows/klipper3d-deploy.yaml @@ -1,5 +1,7 @@ name: klipper3d deploy on: + schedule: + - cron: "0 0 * * *" push: branches: - master @@ -24,6 +26,10 @@ jobs: ${{ runner.os }}-pip- - name: Install dependencies run: pip install -r docs/_klipper3d/mkdocs-requirements.txt - - name: Build and deploy klipper3d - run: | - mkdocs gh-deploy --config-file docs/_klipper3d/mkdocs.yml --remote-branch gh-pages --force --verbose + - name: Build MkDocs Pages + run: docs/_klipper3d/build-translations.sh + - name: Deploy + uses: JamesIves/github-pages-deploy-action@v4.2.5 + with: + branch: gh-pages # The branch the action should deploy to. + folder: site # The folder the action should deploy. diff --git a/docs/_klipper3d/README b/docs/_klipper3d/README index 3f291c88..b3fec47a 100644 --- a/docs/_klipper3d/README +++ b/docs/_klipper3d/README @@ -4,3 +4,17 @@ site is hosted using "github pages". The https://www.mkdocs.org/ ) to automatically convert the markdown files in the docs/ directory to html. In addition to the files in this directory, the docs/CNAME file also controls the website generation. + +To test deploy the main English site locally one can use commands +similar to the following: + +virtualenv ~/mkdocs-env && ~/python-env/bin/pip install -r ~/klipper/docs/_klipper3d/mkdocs-requirements.txt +cd ~/klipper && ~/mkdocs-env/bin/mkdocs serve --config-file ~/klipper/docs/_klipper3d/mkdocs.yml -a 0.0.0.0:8000 + +To test deploy the multi-language site locally one can use commands +similar to the following: + +virtualenv ~/mkdocs-env && ~/python-env/bin/pip install -r ~/klipper/docs/_klipper3d/mkdocs-requirements.txt +source ~/mkdocs-env/bin/activate +cd ~/klipper && ./docs/_klipper3d/build-translations.sh +cd ~/klipper/site/ && python3 -m http.server 8000 diff --git a/docs/_klipper3d/build-translations.sh b/docs/_klipper3d/build-translations.sh new file mode 100755 index 00000000..3da409db --- /dev/null +++ b/docs/_klipper3d/build-translations.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# This script extracts the Klipper translations and builds multiple +# mdocs sites - one for each supported language. See the README file +# for additional details. + +MKDOCS_DIR="docs/_klipper3d/" +WORK_DIR="work/" +TRANS_DIR="${WORK_DIR}klipper-translations/" +TRANS_FILE="${TRANS_DIR}active_translations" +MKDOCS_MAIN="${MKDOCS_DIR}mkdocs-main.yml" + +# Fetch translations +git clone --depth 1 https://github.com/Klipper3d/klipper-translations ${TRANS_DIR} + +# Create new mkdocs-main.yml with language links +cp ${MKDOCS_DIR}mkdocs.yml ${MKDOCS_MAIN} +while IFS="," read dirname langsite langdesc langsearch; do + sed -i "s%^.*# Alternate language links automatically added here$% - name: ${langdesc}\n link: /${langsite}/\n\0%" ${MKDOCS_MAIN} +done < <(egrep -v '^ *(#|$)' ${TRANS_FILE}) + +# Build main English website +echo "building site for en" +mkdocs build -f ${MKDOCS_MAIN} + +# Build each additional language website +while IFS="," read dirname langsite langdesc langsearch; do + new_docs_dir="${WORK_DIR}lang/${langsite}/docs/" + locale_dir="${TRANS_DIR}/docs/locales/${dirname}" + + # Copy markdown files to new_docs_dir + echo "Copying $dirname to $langsite" + mkdir -p "${new_docs_dir}" + cp "${locale_dir}"/*.md "${new_docs_dir}" + echo "copy resources" + cp -r docs/img "${new_docs_dir}" + cp -r docs/prints "${new_docs_dir}" + cp -r docs/_klipper3d "${new_docs_dir}" + + # manually replace index.md if a manual-index.md exist + manual_index="${new_docs_dir}manual-index.md" + if [[ -f "${manual_index}" ]]; then + mv -f "${manual_index}" "${new_docs_dir}index.md" + echo "replaced index.md with manual_index.md for $langsite" + else + echo "Manually translated index file for $langsite not found!" + fi + + # Create language specific mkdocs-lang-xxx.yml file + echo "create language specific mkdocs configurations for ${langsite}" + new_mkdocs_file="${new_docs_dir}_klipper3d/mkdocs-lang-${langsite}.yml" + cp "${MKDOCS_MAIN}" "${new_mkdocs_file}" + + # Build site + echo "building site for ${langsite}" + mkdir -p "${PWD}/site/${langsite}/" + ln -sf "${PWD}/site/${langsite}/" "${WORK_DIR}lang/${langsite}/site" + mkdocs build -f "${new_mkdocs_file}" +done < <(egrep -v '^ *(#|$)' ${TRANS_FILE}) diff --git a/docs/_klipper3d/mkdocs.yml b/docs/_klipper3d/mkdocs.yml index e6bbe1bf..24015851 100644 --- a/docs/_klipper3d/mkdocs.yml +++ b/docs/_klipper3d/mkdocs.yml @@ -9,7 +9,7 @@ use_directory_urls: False docs_dir: '../' site_dir: '../../site/' -# Markdown document translation settings +# Custom markdown dialect settings markdown_extensions: - toc: permalink: True @@ -67,6 +67,11 @@ extra: analytics: provider: google property: UA-138371409-1 + # Language Selection + alternate: + - name: English + link: / + # Alternate language links automatically added here # Navigation hierarchy (this should mimic the layout of Overview.md) nav: