Skip to content
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

Allow for serving GitHub pages from non root directory #81

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

RedSparr0w
Copy link

Description:

Will allow for generating a URL to the correct preview when serving GitHub pages from any directory other than the root directory.

Adds a new optional param which will be removed from umbrella-dir to determine the correct path to the preview.

Related issues:

closes #42

Notes:

Let me know if you think there might be a better approach to this.

action.yml Outdated

targetdir="$umbrella/pr-$pr"
echo "targetdir=$targetdir" >> $GITHUB_ENV
echo "pagespath=${targetdir/"$pagesbase"/}" >> $GITHUB_ENV
Copy link
Owner

@rossjrw rossjrw Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If $pagesbase is e.g. docs/ and $targetdir is e.g. project-docs/pr-preview/pr-1, this would result in project-pr-preview/pr-1 which is not the intended result. (Would $pagesbase containing a slash character interfere with the replacement? My bash-fu isn't strong enough to instinctively know)

I think it's reasonable to assume that situation won't happen, because if the user is specifying a base dir you'd expect their path to start with that base dir. But it would also be nice to permit formats like docs, docs/, ./docs/, maybe even /docs/. I figure there must be some robust way to remove a path section in bash other than string substitution.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated it to make use of regex instead, will only replace if at the start of the string now.
Also made the end / optional to close off pages-base-dir.

umbrella-dir: ./docs/preview-docs
pages-base-dir: ./docs
# pagespath: preview-docs/pr-123

umbrella-dir: /docs/preview-docs
pages-base-dir: /docs
# pagespath: preview-docs/pr-123

umbrella-dir: docs/preview-docs
pages-base-dir: docs
# pagespath: preview-docs/pr-123

umbrella-dir: docs/preview-docs
pages-base-dir: docs/
# pagespath: preview-docs/pr-123

This does sort of depend on the user typing the beginning the same for umbrella-dir and pages-base-dir (both start with ./path, /path or path)

But I think majority of the time this would happen naturally anyway, but added it to the documentation as well.

@rossjrw rossjrw added the enhancement New feature or request label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Customize the directory to serve from
2 participants