Skip to content

Commit

Permalink
chore: sed invocations for docs build to work on macOS (harttle#615)
Browse files Browse the repository at this point in the history
* fix: sed invocations to work out of the box on macOS

These fixes make the sed invocations run on macOS but I am not sure if they will break the GNU sed invocations in return…

* fix: add macOS branches to the shell scripts

The sed command line was difficult (impossible?) to be made portable so I just added macOS conditions.

* Prototype the solution using an alias

It seems that this will not work because I keep getting "sedi: command not found".

* fix: use a Bash function instead of an alias to run sed portably

This seems to work on my local so let's see if it runs in the CI on GitHub.

* fix: use 2 spaces like the original scripts did

Not sure why VS Code went with 4.

* fix: use sedi for the build-changelog `1i\` part as well

I am curious if Ubuntu will handle the newline…
  • Loading branch information
TomasHubelbauer authored Jun 3, 2023
1 parent db67118 commit 2025561
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
17 changes: 14 additions & 3 deletions bin/build-changelog.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/env bash

# Run `sed` in a way that's compatible with both macOS (BSD) and Linux (GNU)
sedi() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}

cd docs
cp ../CHANGELOG.md source/tutorials/changelog.md
sed -i \
sedi \
-e 's/{%/{% raw %}{%{% endraw %}/g' \
-e 's/{{/{% raw %}{{{% endraw %}/g' \
-e '1 s/"/\"/g' \
Expand All @@ -11,5 +20,7 @@ sed -i \
source/tutorials/changelog.md
cp source/tutorials/changelog.md source/zh-cn/tutorials/changelog.md

sed -i '1i ---\ntitle: Changelog\nauto: true\n---\n' source/tutorials/changelog.md
sed -i '1i ---\ntitle: 更新日志\nauto: true\n---\n' source/zh-cn/tutorials/changelog.md
sedi -e '1i\
---\ntitle: Changelog\nauto: true\n---\n' source/tutorials/changelog.md
sedi -e '1i\
---\ntitle: 更新日志\nauto: true\n---\n' source/zh-cn/tutorials/changelog.md
19 changes: 14 additions & 5 deletions bin/build-contributors.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#!/usr/bin/env bash

# Run `sed` in a way that's compatible with both macOS (BSD) and Linux (GNU)
sedi() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}

cp .all-contributorsrc docs/.all-contributorsrc
sed -i \
-e 's/README.md/docs\/themes\/navy\/layout\/partial\/all-contributors.swig/g' \
-e 's/"contributorsPerLine": 7/"contributorsPerLine": 65535/g' \
docs/.all-contributorsrc
sedi \
-e 's/README.md/docs\/themes\/navy\/layout\/partial\/all-contributors.swig/g' \
-e 's/"contributorsPerLine": 7/"contributorsPerLine": 65535/g' \
docs/.all-contributorsrc

all-contributors --config docs/.all-contributorsrc generate
sed -i 's/<br \/>.*<\/td>/<\/a><\/td>/g' docs/themes/navy/layout/partial/all-contributors.swig
sedi 's/<br \/>.*<\/td>/<\/a><\/td>/g' docs/themes/navy/layout/partial/all-contributors.swig

0 comments on commit 2025561

Please sign in to comment.