Is it possible to define a script for each element of an array inside a map? I need to do this because I define variables for each element into the script like this:
{modes.map((mode) => {
<script define:vars={{ name: mode.name, path: mode.link }}>
function updateModeLinksWithHash() {
const links = document.querySelectorAll(
`.starlight-view-modes-switcher-a-${name}`
);
if (links.length > 0) {
const hash = window.location.hash;
links.forEach((link) => {
link.href = path + hash;
});
}
}
// Run on initial load
updateModeLinksWithHash();
// Update on hash change
window.addEventListener("hashchange", updateModeLinksWithHash);
</script>
})}