Fix trailingSlash with new Astro versions

This commit is contained in:
prototypa
2023-03-12 01:38:49 -05:00
parent 8cca15e431
commit a608eff456

View File

@ -27,7 +27,16 @@ export const CATEGORY_BASE = cleanSlug(BLOG?.category?.pathname || 'category');
export const TAG_BASE = cleanSlug(BLOG?.tag?.pathname) || 'tag'; 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 => { export const getPermalink = (slug = '', type = 'page'): string => {