add htmx to window

small swap fix
copy public assets to dist if changed
This commit is contained in:
maddalax 2024-10-07 12:57:24 -05:00
parent 5cf90208d8
commit 1014f6c961
8 changed files with 62 additions and 9 deletions

View file

@ -108,6 +108,11 @@ func OnFileChange(version string, events []*fsnotify.Event) {
//tasks.Run = true
}
// something in public folder changed
if c.HasAnyPrefix("assets/public/") {
copyassets.CopyAssets()
}
if hasTask {
slog.Info("file changed", slog.String("version", version), slog.String("file", c.Name()))
}

File diff suppressed because one or more lines are too long

View file

@ -8,6 +8,9 @@ import "./htmxextensions/livereload"
import "./htmxextensions/htmgo";
import "./htmxextensions/sse"
// @ts-ignore
window.htmx = htmx;
function watchUrl(callback: (oldUrl: string, newUrl: string) => void) {
let lastUrl = window.location.href;
setInterval(() => {

View file

@ -63,11 +63,14 @@ func SwapMany(ctx *RequestContext, elements ...*Element) *Element {
return Empty()
}
for _, element := range elements {
element.AppendChild(outOfBandSwap(""))
if element.tag != "" {
element.AppendChild(outOfBandSwap(""))
}
}
return Fragment(Map(elements, func(arg *Element) Ren {
res := Fragment(Map(elements, func(arg *Element) Ren {
return arg
})...)
return res
}
func SwapManyX(ctx *RequestContext, args ...SwapArg) *Element {

View file

@ -0,0 +1,13 @@
//go:build !prod
// +build !prod
package main
import (
"io/fs"
"starter-template/internal/embedded"
)
func GetStaticAssets() fs.FS {
return embedded.NewOsFs()
}

View file

@ -0,0 +1,16 @@
//go:build prod
// +build prod
package main
import (
"embed"
"io/fs"
)
//go:embed assets/dist/*
var staticAssets embed.FS
func GetStaticAssets() fs.FS {
return staticAssets
}

View file

@ -0,0 +1,17 @@
package embedded
import (
"io/fs"
"os"
)
type OsFs struct {
}
func (receiver OsFs) Open(name string) (fs.File, error) {
return os.Open(name)
}
func NewOsFs() OsFs {
return OsFs{}
}

View file

@ -1,7 +1,6 @@
package main
import (
"embed"
"github.com/maddalax/htmgo/framework/h"
"github.com/maddalax/htmgo/framework/service"
"io/fs"
@ -9,9 +8,6 @@ import (
"starter-template/__htmgo"
)
//go:embed assets/dist/*
var StaticAssets embed.FS
func main() {
locator := service.NewLocator()
@ -19,7 +15,7 @@ func main() {
ServiceLocator: locator,
LiveReload: true,
Register: func(app *h.App) {
sub, err := fs.Sub(StaticAssets, "assets/dist")
sub, err := fs.Sub(GetStaticAssets(), "assets/dist")
if err != nil {
panic(err)