mirror of
https://gitea.com/gitea/docs.git
synced 2026-09-17 19:55:34 +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](https://github.com/pingcap/tipb/blob/aa19c2d12587e66b31069f790fc371b6be565504/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 <[email protected]> Co-authored-by: HesterG <[email protected]> Co-committed-by: HesterG <[email protected]>
This commit is contained in:
+28
-26
@@ -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