Merge pull request #212 from shoelace-style/data-wa-relative

always convert data-webawesome urls to root-relative
This commit is contained in:
Cory LaViska
2024-11-14 13:19:48 -05:00
committed by GitHub

View File

@@ -25,9 +25,10 @@ export function getBasePath(subpath = '') {
// If we haven't set the base path yet, let's set it now
const el = document.querySelector('[data-webawesome]');
if (el) {
// Use the data-webawesome attribute
setBasePath(el.getAttribute('data-webawesome') || '');
if (el?.hasAttribute('data-webawesome')) {
// Use data-webawesome
const rootRelativeUrl = new URL(el.getAttribute('data-webawesome') ?? '', window.location.href).pathname;
setBasePath(rootRelativeUrl);
} else {
// Look for webawesome.js or webawesome.loader.js
const scripts = [...document.getElementsByTagName('script')] as HTMLScriptElement[];