-
Notifications
You must be signed in to change notification settings - Fork 56
Allow for serving GitHub pages from non root directory #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
abf87f3
Allow for serving GitHub pages from non root directory
RedSparr0w e42785b
Update comment URL too
RedSparr0w a365445
Only replace from start of string
RedSparr0w 6f0bd3f
Include optional slash removal from start
RedSparr0w 662d1a4
Update documentation
RedSparr0w b4ac4a9
Update README.md
RedSparr0w f5014ad
Escape .
RedSparr0w 61f8a4a
Merge branch 'main' into gh-pages-non-base-dir
RedSparr0w b19438f
Rewrite pages-base-path docs
rossjrw 6279d7a
Extract path replacement to script for testing
rossjrw acfd584
Run tests on all commits
rossjrw 0b74570
Only run preview on root repo
rossjrw 253e355
Fix base path parameter name in example
rossjrw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.