import { writable } from 'svelte/store';

export const base = writable<string>('');

export function initializeBase() {
    if (typeof document !== 'undefined') {
        const baseElement = document.querySelector('base');
        if (baseElement) {
            let href = baseElement.getAttribute('href');
            if (href) {
                href = href.slice(0, -1); /* remove last slash */
                base.set(href);
            }
        }
    }
}