-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #81 from RedSparr0w/gh-pages-non-base-dir
Allow for serving GitHub pages from non root directory
Showing
7 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Run tests | ||
on: push | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Run tests | ||
run: | | ||
set -e | ||
for testscript in test/test-*.sh; do | ||
bash $testscript | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
help() { | ||
echo "" | ||
echo "Removes a base path from the start of another path." | ||
echo "Usage: $0 -b base_path -o original_path" | ||
echo -e "\t-b Base path to remove" | ||
echo -e "\t-o Path to remove base path from; must start with base path" | ||
exit 1 | ||
} >&2 | ||
|
||
while getopts "b:o:" opt; do | ||
case "$opt" in | ||
b) base_path="$OPTARG" ;; | ||
o) original_path="$OPTARG" ;; | ||
?) help ;; | ||
esac | ||
done | ||
|
||
# Remove leading dotslash, leading/trailing slash; collapse multiple slashes | ||
normalise_path() { | ||
echo "$1" | sed -e 's|^\./||g' -e 's|^/||g' -e 's|/*$||g' -e 's|//*|/|g' | ||
} | ||
|
||
base_path=$(normalise_path "$base_path") | ||
original_path=$(normalise_path "$original_path") | ||
|
||
echo "${original_path#"$base_path"/}" | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
echo >&2 "$0: start" | ||
|
||
testscript=$(dirname "$0")/../lib/remove-prefix-path.sh | ||
|
||
assert() { | ||
echo >&2 "$1" = "$2" | ||
if [ "$1" != "$2" ]; then | ||
echo >&2 "$0: fail" | ||
exit 1 | ||
fi | ||
} | ||
|
||
assert "$($testscript -b "" -o "")" "" | ||
assert "$($testscript -b "" -o a/b/c/d)" a/b/c/d | ||
assert "$($testscript -b "/" -o a/b/c/d)" a/b/c/d | ||
assert "$($testscript -b "/" -o /a/b/c/d)" a/b/c/d | ||
assert "$($testscript -b "//" -o /a/b/c/d)" a/b/c/d | ||
assert "$($testscript -b a/b -o a/b/c/d)" c/d | ||
assert "$($testscript -b ./a/b/ -o a/b/c/d)" c/d | ||
assert "$($testscript -b a/b -o ./a/b/c/d/)" c/d | ||
assert "$($testscript -b ./a//b// -o ./a//b//c//d/)" c/d | ||
assert "$($testscript -b .//a/b -o ./a/b/c/d)" c/d | ||
assert "$($testscript -b /a/b -o a/b/c/d)" c/d | ||
assert "$($testscript -b /a/b/ -o /a/b/c/d/)" c/d | ||
assert "$($testscript -b a/b -o /a/b/c/d)" c/d | ||
assert "$($testscript -b a/b -o c/d/a/b)" c/d/a/b | ||
|
||
# If there is no match, replacement with nothing should return the same result | ||
assert "$($testscript -b "e/f" -o a/b/c/d)" "$($testscript -b "" -o a/b/c/d)" | ||
|
||
echo >&2 "$0: ok" |