Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Redirect to BaseURL in CI deployments#87

Draft
cswimr wants to merge 2 commits into
Galaxypedia-Wiki:mainfrom
cswimr:redirect-to-baseurl
Draft

Redirect to BaseURL in CI deployments#87
cswimr wants to merge 2 commits into
Galaxypedia-Wiki:mainfrom
cswimr:redirect-to-baseurl

Conversation

@cswimr
Copy link
Copy Markdown
Member

@cswimr cswimr commented Jan 2, 2025

Currently, if you go on any PR and click on a link from the GitHub Deployments bot, it'll take you to the wrong URL. Normally it'd work fine, but because Hugo depends on BaseURL being correct, it breaks. This PR fixes that issue by automatically redirecting to BaseURL if you access the site from another domain, only when building in CI.

@cswimr cswimr requested a review from a team as a code owner January 2, 2025 13:58
@github-actions github-actions Bot added site:platform Issues concerning the platform (hugo) site:partials Concerns partials labels Jan 2, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 2, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
galaxypedia ✅ Ready (View Log) Visit Preview 549c506

@cswimr
Copy link
Copy Markdown
Member Author

cswimr commented Jan 2, 2025

Regarding this using the CI environment variable instead of hugo.IsProduction, this issue only exists in CI deployments, and only when deploying to Cloudflare Pages with our workflow. As such, I think it makes the most sense to check the CI environment variable instead.

@cswimr
Copy link
Copy Markdown
Member Author

cswimr commented Jan 2, 2025

sigh

@github-actions github-actions Bot added the site:platform Issues concerning the platform (hugo) label Jan 2, 2025
@cswimr
Copy link
Copy Markdown
Member Author

cswimr commented Jan 2, 2025

i suppose that is one way to do a rebase 😭

Comment thread assets/js/redirect.js
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

im sorta scared about feeding unfiltered and unsanitized stuff into the regex engine. this entire file is a bit scary and gives me some unease. dynamic redirects like this can end up being an easy attack vector

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes an issue where links from the GitHub Deployments bot are pointing to an incorrect URL during CI deployments by redirecting the URL to the correct BaseURL.

  • Added a JavaScript redirect script that recalculates URLs based on a provided BaseURL.
  • Updated hugo.yaml to include caching configuration for the new JavaScript assets.

Reviewed Changes

File Description
assets/js/redirect.js New script to handle URL redirection in CI builds
hugo.yaml Updated cachebusters configuration

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread assets/js/redirect.js
const newUrl = new URL(url.pathname.replace(baseUrl, ""), baseUrl);
window.location.href = newUrl.toString();
}
})("@params");
Copy link

Copilot AI Feb 27, 2025

Choose a reason for hiding this comment

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

The self-invoking function is being passed the string "@params" instead of an object with a baseUrl property, which may lead to a runtime error. Ensure that a valid object is passed to correctly provide the baseUrl.

Suggested change
})("@params");
})({ baseUrl: "https://example.com" });

Copilot uses AI. Check for mistakes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

site:partials Concerns partials site:platform Issues concerning the platform (hugo) size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants