function rewriteAttribute()

in _includes/resources/playlist/PlaylistLayout.11ty.tsx [37:59]


	function rewriteAttribute(element: HTMLElement, attribute: string) {
		const href = element.attrs[attribute];
		// no value
		if (!href) return;
		// already good
		if (href.startsWith(prefix)) return;
		// data URI
		if (href.startsWith("data:")) return;
		// absolute urls
		if (href.startsWith("http://") || href.startsWith("https://")) return;
		// relative paths
		if (href.startsWith(".") && !href.startsWith("../")) return;
		// root link
		if (href.startsWith("/")) return;
		//anchor link
		if (href.startsWith("#")) return;
		// ignore VITE ASSETS
		if (href.startsWith("__VITE_ASSET__")) return;

		if (prefix && href) {
			element.setAttribute(attribute, path.join(prefix, href));
		}
	}