In a previous conversation with you, you created a custom DownloadButton component that gets passed a props ID to have a unique ID.
---
import Button from '~/components/Button.svelte'
const id = Astro.props.id
const href = '/downloads'
---
<script>
import { UAParser } from 'ua-parser-js'
import { latestLinks } from '~/config'
class DownloadButton extends HTMLElement {
constructor() {
super()
// Your existing script here, modified to use `this` instead of `document`
// to only affect this instance of the button.
const parser = UAParser(navigator.userAgent)
const os = parser.os.name.toLowerCase()
const isMacOS = ['macos'].includes(os)
const isWindows = ['windows'].includes(os)
const isLinux = ['ubuntu', 'linux', 'unix', 'gnu', 'fedora'].includes(os)
if (isMacOS) {
this.querySelector(`#${id}`)?.setAttribute('href', latestLinks.macOS())
} else if (isWindows) {
this.querySelector(`#${id}`)?.setAttribute('href', latestLinks.windows())
} else if (isLinux) {
this.querySelector(`#${id}`)?.setAttribute('href', latestLinks.linux())
}
}
}
customElements.define('download-button', DownloadButton)
</script>
<download-button {id} {href}>
<Button {href}>Download</Button></download-button
>
The site is static, and so the {id} querySelector won't work unless the <script> gets passed the id props. Can you do that? I assume maybe a Map needs to get used so that all the IDs get set?