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:
+9
-6
@@ -9,11 +9,14 @@
|
|||||||
|
|
||||||
set -xe
|
set -xe
|
||||||
|
|
||||||
if sed --version 2>/dev/null | grep -q GNU; then
|
SED_INPLACE() {
|
||||||
SED_INPLACE="sed -i"
|
if sed --version 2>/dev/null | grep -q GNU; then
|
||||||
else
|
sed -i "$@"
|
||||||
SED_INPLACE="sed -i ''"
|
else
|
||||||
fi
|
sed -i '' "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
version="$1"
|
version="$1"
|
||||||
locale="$2"
|
locale="$2"
|
||||||
cur_path=`pwd`
|
cur_path=`pwd`
|
||||||
@@ -31,7 +34,7 @@ for file in `find ./docs/content/doc -name "*.${locale}.md"`; do
|
|||||||
fi
|
fi
|
||||||
if [[ "$latest_commit_time_en" -gt "$latest_commit_time_locale" ]]; then
|
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)"
|
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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
+28
-26
@@ -6,11 +6,13 @@
|
|||||||
|
|
||||||
set -xe
|
set -xe
|
||||||
|
|
||||||
if sed --version 2>/dev/null | grep -q GNU; then
|
SED_INPLACE() {
|
||||||
SED_INPLACE="sed -i"
|
if sed --version 2>/dev/null | grep -q GNU; then
|
||||||
else
|
sed -i "$@"
|
||||||
SED_INPLACE="sed -i ''"
|
else
|
||||||
fi
|
sed -i '' "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
version="$1"
|
version="$1"
|
||||||
if [ "$version" != "lastest" ]; then
|
if [ "$version" != "lastest" ]; then
|
||||||
@@ -42,38 +44,38 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$docs_dir/installation/with-docker.$locale.md" ]; then
|
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
|
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/<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/^url:.*//' "$docs_dir/intro.md"
|
||||||
$SED_INPLACE 's/^slug:.*/slug: \//' "$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-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/{{< 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/{{< 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-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/{{< min-go-version >}}/$minGoVer/" "$docs_dir/installation/from-source.$locale.md"
|
||||||
|
|
||||||
# TODO: improve this sed
|
# TODO: improve this sed
|
||||||
# need confirmation
|
# need confirmation
|
||||||
if [ "$version" == "lastest" ]; then
|
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
|
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
|
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
|
fi
|
||||||
|
|
||||||
for file in `find ./"$docs_dir" -name "*.md"`; do
|
for file in `find ./"$docs_dir" -name "*.md"`; do
|
||||||
# hide hugo toc
|
# hide hugo toc
|
||||||
$SED_INPLACE 's/{{< toc >}}//' $file
|
SED_INPLACE 's/{{< toc >}}//' $file
|
||||||
$SED_INPLACE 's/dl.gitea.com\/gitea\/{{< version >}}/dl.gitea.com\/gitea\/main/g' $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/{{< version >}}/$minorVer/g" $file
|
||||||
$SED_INPLACE 's/{{< relref "doc\///g' $file
|
SED_INPLACE 's/{{< relref "doc\///g' $file
|
||||||
$SED_INPLACE "s/.$locale.md/.md/g" $file
|
SED_INPLACE "s/.$locale.md/.md/g" $file
|
||||||
$SED_INPLACE 's/" >}}//g' $file
|
SED_INPLACE 's/" >}}//g' $file
|
||||||
$SED_INPLACE 's/\*\*Table of Contents\*\*//' $file
|
SED_INPLACE 's/\*\*Table of Contents\*\*//' $file
|
||||||
$SED_INPLACE 's/weight:/sidebar_position:/g' $file
|
SED_INPLACE 's/weight:/sidebar_position:/g' $file
|
||||||
#sed -i 's/^slug:.*//' $file
|
#sed -i 's/^slug:.*//' $file
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user