From a608eff456f7b67a527a3768585d4f2a4990b7d6 Mon Sep 17 00:00:00 2001 From: prototypa Date: Sun, 12 Mar 2023 01:38:49 -0500 Subject: [PATCH] Fix trailingSlash with new Astro versions --- src/utils/permalinks.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utils/permalinks.ts b/src/utils/permalinks.ts index 83576e4..c4d89f4 100644 --- a/src/utils/permalinks.ts +++ b/src/utils/permalinks.ts @@ -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 => {