diff options
Diffstat (limited to 'packages/astro-rss/src/util.ts')
| -rw-r--r-- | packages/astro-rss/src/util.ts | 10 | 
1 files changed, 7 insertions, 3 deletions
| diff --git a/packages/astro-rss/src/util.ts b/packages/astro-rss/src/util.ts index 0dad6b239..7218cc934 100644 --- a/packages/astro-rss/src/util.ts +++ b/packages/astro-rss/src/util.ts @@ -1,10 +1,8 @@ -import npath from 'path-browserify'; -  /** Normalize URL to its canonical form */  export function createCanonicalURL(url: string, base?: string): URL {  	let pathname = url.replace(/\/index.html$/, ''); // index.html is not canonical  	pathname = pathname.replace(/\/1\/?$/, ''); // neither is a trailing /1/ (impl. detail of collections) -	if (!npath.extname(pathname)) pathname = pathname.replace(/(\/+)?$/, '/'); // add trailing slash if there’s no extension +	if (!getUrlExtension(url)) pathname = pathname.replace(/(\/+)?$/, '/'); // add trailing slash if there’s no extension  	pathname = pathname.replace(/\/+/g, '/'); // remove duplicate slashes (URL() won’t)  	return new URL(pathname, base);  } @@ -17,3 +15,9 @@ export function isValidURL(url: string): boolean {  	} catch (e) {}  	return false;  } + +function getUrlExtension(url: string) { +	const lastDot = url.lastIndexOf('.'); +	const lastSlash = url.lastIndexOf('/'); +	return lastDot > lastSlash ? url.slice(lastDot + 1) : ''; +} | 
