Skip to content

Commit

Permalink
Merge pull request #606 from thautwarm/main
Browse files Browse the repository at this point in the history
fix `redirects` plugin for html output
  • Loading branch information
oscarotero committed May 8, 2024
2 parents bc599e4 + 7dab044 commit 4824f1d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugins/redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export default function (userOptions?: Options) {
const oldUrls = Array.isArray(oldUrl) ? oldUrl : [oldUrl];

for (const old of oldUrls) {
const redirect = parseRedirection(url, old, options.defaultStatus);
const redirect = parseRedirection(
url,
old,
options.defaultStatus,
site,
);
if (redirect) {
redirects.push(redirect);
}
Expand Down Expand Up @@ -80,7 +85,11 @@ function parseRedirection(
newUrl: string,
oldUrl: string,
defaultCode: Status,
site: Site,
): [string, string, Status] | undefined {
// Resolve the full URL when the site's base URL is not at the root
const to = site.url(newUrl);

const [from, code] = oldUrl.split(/\s+/);
const parsedCode = code ? parseInt(code) : defaultCode;

Expand All @@ -91,7 +100,7 @@ function parseRedirection(
return;
}

return [from, newUrl, parsedCode as Status];
return [from, to, parsedCode as Status];
}

/** HTML redirect */
Expand Down

0 comments on commit 4824f1d

Please sign in to comment.