mirror of
https://gitea.com/gitea/docs.git
synced 2026-06-23 20:55:55 +00:00
fix sed for MacOS (#36)
Close #4
Right now on MacOS, sed will produce backup files, because on Mac, If do something like below using bash script
```
$SED_INPLACE '1s/---/---\nisOutdated: true/' $file
```
It will become the following on executed, and a backup file will be produced:
```
sed -i ''\'''\''' '1s/---/---\nisOutdated: true/' ./docs/content/doc/help/faq.zh-cn.md
```
The way to fix this in this PR is to change the `SED_INPLACE` to a function. [Reference](aa19c2d125/generate-cpp.sh (L4)) (Tested on my
Mac and backup files with suffix '' will not be produced after changing to function)
Reviewed-on: https://gitea.com/gitea/gitea-docusaurus/pulls/36
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: HesterG <hestergong@gmail.com>
Co-committed-by: HesterG <hestergong@gmail.com>
This commit is contained in:
@@ -9,11 +9,14 @@
|
||||
|
||||
set -xe
|
||||
|
||||
if sed --version 2>/dev/null | grep -q GNU; then
|
||||
SED_INPLACE="sed -i"
|
||||
else
|
||||
SED_INPLACE="sed -i ''"
|
||||
fi
|
||||
SED_INPLACE() {
|
||||
if sed --version 2>/dev/null | grep -q GNU; then
|
||||
sed -i "$@"
|
||||
else
|
||||
sed -i '' "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
version="$1"
|
||||
locale="$2"
|
||||
cur_path=`pwd`
|
||||
@@ -31,7 +34,7 @@ for file in `find ./docs/content/doc -name "*.${locale}.md"`; do
|
||||
fi
|
||||
if [[ "$latest_commit_time_en" -gt "$latest_commit_time_locale" ]]; then
|
||||
echo "file: $file, lastest commit timestamp: $latest_commit_time_en (en ver), $latest_commit_time_locale ($locale ver)"
|
||||
$SED_INPLACE '1s/---/---\nisOutdated: true/' $file
|
||||
SED_INPLACE '1s/---/---\nisOutdated: true/' $file
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
54
loop_docs.sh
54
loop_docs.sh
@@ -6,11 +6,13 @@
|
||||
|
||||
set -xe
|
||||
|
||||
if sed --version 2>/dev/null | grep -q GNU; then
|
||||
SED_INPLACE="sed -i"
|
||||
else
|
||||
SED_INPLACE="sed -i ''"
|
||||
fi
|
||||
SED_INPLACE() {
|
||||
if sed --version 2>/dev/null | grep -q GNU; then
|
||||
sed -i "$@"
|
||||
else
|
||||
sed -i '' "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
version="$1"
|
||||
if [ "$version" != "lastest" ]; then
|
||||
@@ -42,38 +44,38 @@ else
|
||||
fi
|
||||
|
||||
if [ -f "$docs_dir/installation/with-docker.$locale.md" ]; then
|
||||
$SED_INPLACE 's/\\<empty>/<empty\\>/' "$docs_dir/installation/with-docker.$locale.md"
|
||||
SED_INPLACE 's/\\<empty>/<empty\\>/' "$docs_dir/installation/with-docker.$locale.md"
|
||||
fi
|
||||
$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"
|
||||
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"
|
||||
|
||||
# TODO: improve this sed
|
||||
# need confirmation
|
||||
if [ "$version" == "lastest" ]; then
|
||||
$SED_INPLACE 's/"version":.*/"version":"1.21-dev"/' static/latest-swagger.json
|
||||
SED_INPLACE 's/"version":.*/"version":"1.21-dev"/' static/latest-swagger.json
|
||||
elif [ "$version" == "1.20" ]; then
|
||||
$SED_INPLACE 's/"version":.*/"version":"1.20.0-rc0"/' static/20-swagger.json
|
||||
SED_INPLACE 's/"version":.*/"version":"1.20.0-rc0"/' static/20-swagger.json
|
||||
elif [ "$version" == "1.19" ]; then
|
||||
$SED_INPLACE 's/"version":.*/"version":"1.19.3"/' static/19-swagger.json
|
||||
SED_INPLACE 's/"version":.*/"version":"1.19.3"/' static/19-swagger.json
|
||||
fi
|
||||
|
||||
for file in `find ./"$docs_dir" -name "*.md"`; do
|
||||
# hide hugo toc
|
||||
$SED_INPLACE 's/{{< toc >}}//' $file
|
||||
$SED_INPLACE 's/dl.gitea.com\/gitea\/{{< version >}}/dl.gitea.com\/gitea\/main/g' $file
|
||||
$SED_INPLACE "s/{{< version >}}/$minorVer/g" $file
|
||||
$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
|
||||
SED_INPLACE 's/{{< toc >}}//' $file
|
||||
SED_INPLACE 's/dl.gitea.com\/gitea\/{{< version >}}/dl.gitea.com\/gitea\/main/g' $file
|
||||
SED_INPLACE "s/{{< version >}}/$minorVer/g" $file
|
||||
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
|
||||
#sed -i 's/^slug:.*//' $file
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user