feature support: provide translation archives (#10555)

* Feature Support Download Of Individual Languages By Clients

Signed-off-by: Adam Henley <adamazing@gmail.com>

* Rename language archival step function

Co-authored-by: Jack Lin <blueskyson1401@gmail.com>

---------

Signed-off-by: Adam Henley <adamazing@gmail.com>
Co-authored-by: Jack Lin <blueskyson1401@gmail.com>
pull/23/head
Adam Henley 2023-08-16 17:09:53 +12:00 committed by GitHub
parent 03711dd140
commit 8aacd0800b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -9,6 +9,10 @@ function initialize {
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)} export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
fi fi
if [ -z "$TLDR_LANG_ARCHIVES_DIRECTORY" ]; then
export TLDR_LANG_ARCHIVES_DIRECTORY="${GITHUB_WORKSPACE:-$(pwd)}/language_archives"
fi
export TLDR_ARCHIVE="tldr.zip" export TLDR_ARCHIVE="tldr.zip"
} }
@ -24,6 +28,28 @@ function build_archive {
echo "Pages archive successfully built." echo "Pages archive successfully built."
} }
function build_translation_archives {
local source_directory="$TLDRHOME"
local target_directory="$TLDR_LANG_ARCHIVES_DIRECTORY"
mkdir -p "$target_directory"
rm -f "$target_directory/*"
for lang_dir in "$source_directory"/pages*; do
if [ -d "$lang_dir" ]; then
local lang=$(basename "$lang_dir")
local archive_name="tldr-$lang.zip"
# Create the zip archive
cd "$lang_dir"
zip -q -r "$target_directory/$archive_name" .
zip -q -j "$target_directory/$archive_name" "$source_directory/LICENSE.md"
echo "Pages archive of $archive_name successfully created."
fi
done
}
################################### ###################################
# MAIN # MAIN
################################### ###################################
@ -31,3 +57,4 @@ function build_archive {
initialize initialize
build_index build_index
build_archive build_archive
build_translation_archives

View File

@ -9,6 +9,7 @@ function initialize {
export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)} export TLDRHOME=${GITHUB_WORKSPACE:-$(pwd)}
fi fi
export TLDR_LANG_ARCHIVES_DIRECTORY="$TLDRHOME/language_archives"
export TLDR_ARCHIVE="tldr.zip" export TLDR_ARCHIVE="tldr.zip"
export SITE_HOME="$HOME/site" export SITE_HOME="$HOME/site"
export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io" export SITE_REPO_SLUG="tldr-pages/tldr-pages.github.io"
@ -29,12 +30,14 @@ function initialize {
function upload_assets { function upload_assets {
git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git "$SITE_HOME" git clone --quiet --depth 1 git@github.com:${SITE_REPO_SLUG}.git "$SITE_HOME"
mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/" mv -f "$TLDR_ARCHIVE" "$SITE_HOME/assets/"
mv -f "${TLDR_LANG_ARCHIVES_DIRECTORY}"/*.zip "$SITE_HOME/assets/"
rm -rf "$TLDR_LANG_ARCHIVES_DIRECTORY"
cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/" cp -f "$TLDRHOME/index.json" "$SITE_HOME/assets/"
cp -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" "${SITE_HOME}/assets/tldr-book.pdf" cp -f "${TLDRHOME}/scripts/pdf/tldr-pages.pdf" "${SITE_HOME}/assets/tldr-book.pdf"
sha256sum \ sha256sum \
"${SITE_HOME}/assets/index.json" \ "${SITE_HOME}/assets/index.json" \
"${SITE_HOME}/assets/${TLDR_ARCHIVE}" \ "${SITE_HOME}/assets/"*.zip \
"${SITE_HOME}/assets/tldr-book.pdf" \ "${SITE_HOME}/assets/tldr-book.pdf" \
> "${SITE_HOME}/assets/tldr.sha256sums" > "${SITE_HOME}/assets/tldr.sha256sums"