mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
56 lines
1.2 KiB
Templ
56 lines
1.2 KiB
Templ
package state
|
|
|
|
const (
|
|
CDNPath = "https://cdn.sonr.id"
|
|
)
|
|
|
|
var (
|
|
serviceWorkerHandle = templ.NewOnceHandle()
|
|
stylesHandle = templ.NewOnceHandle()
|
|
alpineHandle = templ.NewOnceHandle()
|
|
htmxHandle = templ.NewOnceHandle()
|
|
)
|
|
|
|
func cdnPath(path string, local bool) string {
|
|
if local {
|
|
return path
|
|
}
|
|
return CDNPath + path
|
|
}
|
|
|
|
templ RegisterServiceWorker() {
|
|
<script>
|
|
if ("serviceWorker" in navigator) {
|
|
window.addEventListener("load", function() {
|
|
navigator.serviceWorker
|
|
.register("/sw.js")
|
|
.then(function (registration) {
|
|
console.log("Service Worker registered with scope:", registration.scope);
|
|
})
|
|
.catch(function (error) {
|
|
console.log("Service Worker registration failed:", error);
|
|
});
|
|
});
|
|
}
|
|
</script>
|
|
}
|
|
|
|
templ Styles(local bool) {
|
|
@stylesHandle.Once() {
|
|
<link href={ cdnPath("/assets/css/styles.css", local) } rel="stylesheet"/>
|
|
}
|
|
}
|
|
|
|
templ Alpine(local bool) {
|
|
@alpineHandle.Once() {
|
|
<script src={ cdnPath("/js/alpine.min.js", local) } defer></script>
|
|
}
|
|
}
|
|
|
|
templ Htmx(local bool) {
|
|
@htmxHandle.Once() {
|
|
<script src={ cdnPath("/js/htmx.min.js", local) }></script>
|
|
}
|
|
}
|
|
|