Files
docs/loop_docs.sh
T

105 lines
3.5 KiB
Bash
Raw Normal View History

2023-02-02 23:30:20 -05:00
#!/bin/bash
2023-07-05 17:35:59 +00:00
# The script takes two params:
2023-06-14 07:05:13 +00:00
# version: "latest" or a specific version number
# locale
2023-02-02 23:30:20 -05:00
set -xe
2023-06-20 14:47:10 +00:00
SED_INPLACE() {
if sed --version 2>/dev/null | grep -q GNU; then
sed -i "$@"
else
sed -i '' "$@"
fi
}
2023-02-02 23:30:20 -05:00
2023-06-14 07:05:13 +00:00
version="$1"
2023-07-05 03:54:54 +00:00
if [ "$version" != "latest" ]; then
2023-06-14 07:05:13 +00:00
version="1.$1"
fi
locale="$2"
minNodeVer="16"
minGoVer="1.20"
goVer="1.20"
minorVer="main-nightly"
2023-07-19 13:38:32 -04:00
if [ "$version" == "1.19" ]; then
minorVer="1.19.4"
minGoVer="1.19"
elif [ "$version" == "1.20" ]; then
2023-07-19 13:40:14 -04:00
minorVer="1.20.0"
2023-06-14 07:05:13 +00:00
fi
2023-03-26 01:22:34 -04:00
2023-06-14 07:05:13 +00:00
docs_dir="versioned_docs/version-$version"
2023-07-05 03:54:54 +00:00
if [ "$version" == "latest" ]; then
2023-06-14 07:05:13 +00:00
if [ "$locale" == "en-us" ]; then
docs_dir="docs"
else
docs_dir="i18n/$locale/docusaurus-plugin-content-docs/current"
fi
else
if [ "$locale" != "en-us" ]; then
docs_dir="i18n/$locale/docusaurus-plugin-content-docs/version-$version"
fi
fi
2023-02-02 23:30:20 -05:00
2023-06-14 07:05:13 +00:00
if [ -f "$docs_dir/installation/with-docker.$locale.md" ]; then
2023-06-20 14:47:10 +00:00
SED_INPLACE 's/\\<empty>/<empty\\>/' "$docs_dir/installation/with-docker.$locale.md"
2023-06-14 07:05:13 +00:00
fi
2023-06-20 14:47:10 +00:00
SED_INPLACE 's/\\<empty/<empty/' "$docs_dir/administration/config-cheat-sheet.$locale.md"
SED_INPLACE 's/<empty>/<empty\\>/' "$docs_dir/administration/config-cheat-sheet.$locale.md"
SED_INPLACE 's/^url:.*//' "$docs_dir/intro.md"
SED_INPLACE 's/^slug:.*/slug: \//' "$docs_dir/intro.md"
SED_INPLACE "s/{{< min-node-version >}}/$minNodeVer/" "$docs_dir/development/hacking-on-gitea.$locale.md"
SED_INPLACE "s/{{< min-go-version >}}/$minGoVer/" "$docs_dir/development/hacking-on-gitea.$locale.md"
SED_INPLACE "s/{{< go-version >}}/$goVer/" "$docs_dir/development/hacking-on-gitea.$locale.md"
SED_INPLACE "s/{{< min-node-version >}}/$minNodeVer/" "$docs_dir/installation/from-source.$locale.md"
SED_INPLACE "s/{{< min-go-version >}}/$minGoVer/" "$docs_dir/installation/from-source.$locale.md"
2023-06-14 07:05:13 +00:00
# TODO: improve this sed
# need confirmation
2023-07-05 03:54:54 +00:00
if [ "$version" == "latest" ]; then
SED_INPLACE 's/"version": "{{AppVer | JSEscape | Safe}}"/"version": "1.21-dev"/' static/swagger-latest.json
2023-06-14 07:05:13 +00:00
elif [ "$version" == "1.20" ]; then
2023-07-05 03:54:54 +00:00
SED_INPLACE 's/"version": "{{AppVer | JSEscape | Safe}}"/"version": "1.20.0-rc2"/' static/swagger-20.json
2023-07-19 13:38:32 -04:00
elif [ "$version" == "1.19" ]; then
SED_INPLACE 's/"version": "{{AppVer | JSEscape | Safe}}"/"version": "1.19.4"/' static/swagger-19.json
2023-06-14 07:05:13 +00:00
fi
2023-07-05 03:54:54 +00:00
SED_INPLACE 's/"basePath": "{{AppSubUrl | JSEscape | Safe}}/"basePath": "https:\/\/gitea.com/' static/swagger-"$1".json
2023-06-14 07:05:13 +00:00
for file in `find ./"$docs_dir" -name "*.md"`; do
2023-02-02 23:30:20 -05:00
# hide hugo toc
2023-06-20 14:47:10 +00:00
SED_INPLACE 's/{{< toc >}}//' $file
2023-06-29 18:37:17 +00:00
if [ "$version" == "lastest" ]; then
2023-06-29 18:55:46 +00:00
SED_INPLACE 's/dl.gitea.com\/gitea\/{{< version >}}/dl.gitea.com\/gitea\/main/g' $file
2023-06-29 18:37:17 +00:00
SED_INPLACE 's/gitea\/gitea\:{{< version >}}/gitea\/gitea\:nightly/g' $file
fi
2023-06-29 18:47:46 +00:00
SED_INPLACE "s/{{< version >}}/$version/g" $file
2023-06-20 14:47:10 +00:00
SED_INPLACE 's/{{< relref "doc\///g' $file
SED_INPLACE "s/.$locale.md/.md/g" $file
SED_INPLACE 's/" >}}//g' $file
SED_INPLACE 's/\*\*Table of Contents\*\*//' $file
SED_INPLACE 's/weight:/sidebar_position:/g' $file
2023-03-26 00:57:39 -04:00
#sed -i 's/^slug:.*//' $file
2023-02-02 23:30:20 -05:00
done
2023-06-14 07:05:13 +00:00
for file in "$docs_dir"/*; do
2023-02-02 23:30:20 -05:00
if [ -d $file ]; then
continue
fi
2023-06-14 07:05:13 +00:00
if [ "$file" == "$docs_dir/intro.md" ]; then
2023-02-02 23:30:20 -05:00
continue
fi
2023-04-30 10:59:00 +08:00
rm $file || true
2023-02-02 23:30:20 -05:00
done
2023-05-26 14:30:13 +08:00
2023-07-05 17:35:59 +00:00
# file names under docs/ and i18n/zh-cn/docusaurus-plugin-content-docs/current/ should be the same for docusaurus
# to recognize them as tanslated.
2023-06-14 07:05:13 +00:00
for file in `find "$docs_dir" -name "*.$locale.md"`; do
mv "${file}" "${file/.$locale/}"
2023-05-26 14:30:13 +08:00
done
2023-06-14 07:05:13 +00:00
if [ -f "$docs_dir/help/search.md" ]; then
rm "$docs_dir/help/search.md"
fi