Skip to content

Commit

Permalink
Merge pull request #849 from shiyouganai/shiyouganai-slashocalypse
Browse files Browse the repository at this point in the history
Fix edge case with rehype-urls and trailing slashes in image file paths
  • Loading branch information
felixroos committed Dec 7, 2023
2 parents 2bd21df + 78b2b5c commit 5cac182
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ function relativeURLFix() {
newHref += `/${path}/${url.href}`;
} else if (url.href.startsWith('/')) {
// any other relative url starting with /
// NOTE: this does strip off serialized queries and fragments
newHref += url.pathname.endsWith('/') ? url.pathname : url.pathname + '/';
newHref += url.pathname;
if (url.pathname.indexOf('.') == -1) {
// append trailing slash to resource only if there is no file extension
newHref += url.pathname.endsWith('/') ? '' : '/';
}
newHref += url.search || '';
newHref += url.hash || '';
} else {
// leave this URL alone
Expand Down

0 comments on commit 5cac182

Please sign in to comment.