Skip to content

Commit

Permalink
Fix trailingSlash with new Astro versions
Browse files Browse the repository at this point in the history
  • Loading branch information
prototypa committed Mar 12, 2023
1 parent 8cca15e commit a608eff
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils/permalinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ export const CATEGORY_BASE = cleanSlug(BLOG?.category?.pathname || 'category');
export const TAG_BASE = cleanSlug(BLOG?.tag?.pathname) || 'tag';

/** */
export const getCanonical = (path = ''): string | URL => new URL(path, SITE.origin);
export const getCanonical = (path = ''): string | URL => {
const url = String(new URL(path, SITE.origin));
if (SITE.trailingSlash == false && path && url.endsWith('/')) {
return url.slice(0,-1)
}
else if (SITE.trailingSlash == true && path && !url.endsWith('/') ) {
return url + '/';
}
return url;
}

/** */
export const getPermalink = (slug = '', type = 'page'): string => {
Expand Down

0 comments on commit a608eff

Please sign in to comment.