add htmx to window
small swap fix copy public assets to dist if changed
This commit is contained in:
parent
5cf90208d8
commit
1014f6c961
8 changed files with 62 additions and 9 deletions
|
|
@ -108,6 +108,11 @@ func OnFileChange(version string, events []*fsnotify.Event) {
|
||||||
//tasks.Run = true
|
//tasks.Run = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// something in public folder changed
|
||||||
|
if c.HasAnyPrefix("assets/public/") {
|
||||||
|
copyassets.CopyAssets()
|
||||||
|
}
|
||||||
|
|
||||||
if hasTask {
|
if hasTask {
|
||||||
slog.Info("file changed", slog.String("version", version), slog.String("file", c.Name()))
|
slog.Info("file changed", slog.String("version", version), slog.String("file", c.Name()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
framework/assets/dist/htmgo.js
vendored
4
framework/assets/dist/htmgo.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -8,6 +8,9 @@ import "./htmxextensions/livereload"
|
||||||
import "./htmxextensions/htmgo";
|
import "./htmxextensions/htmgo";
|
||||||
import "./htmxextensions/sse"
|
import "./htmxextensions/sse"
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
window.htmx = htmx;
|
||||||
|
|
||||||
function watchUrl(callback: (oldUrl: string, newUrl: string) => void) {
|
function watchUrl(callback: (oldUrl: string, newUrl: string) => void) {
|
||||||
let lastUrl = window.location.href;
|
let lastUrl = window.location.href;
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,14 @@ func SwapMany(ctx *RequestContext, elements ...*Element) *Element {
|
||||||
return Empty()
|
return Empty()
|
||||||
}
|
}
|
||||||
for _, element := range elements {
|
for _, element := range elements {
|
||||||
|
if element.tag != "" {
|
||||||
element.AppendChild(outOfBandSwap(""))
|
element.AppendChild(outOfBandSwap(""))
|
||||||
}
|
}
|
||||||
return Fragment(Map(elements, func(arg *Element) Ren {
|
}
|
||||||
|
res := Fragment(Map(elements, func(arg *Element) Ren {
|
||||||
return arg
|
return arg
|
||||||
})...)
|
})...)
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func SwapManyX(ctx *RequestContext, args ...SwapArg) *Element {
|
func SwapManyX(ctx *RequestContext, args ...SwapArg) *Element {
|
||||||
|
|
|
||||||
13
templates/starter/assets.go
Normal file
13
templates/starter/assets.go
Normal 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()
|
||||||
|
}
|
||||||
16
templates/starter/assets_prod.go
Normal file
16
templates/starter/assets_prod.go
Normal 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
|
||||||
|
}
|
||||||
17
templates/starter/internal/embedded/os.go
Normal file
17
templates/starter/internal/embedded/os.go
Normal 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{}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
|
||||||
"github.com/maddalax/htmgo/framework/h"
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
"github.com/maddalax/htmgo/framework/service"
|
"github.com/maddalax/htmgo/framework/service"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
|
@ -9,9 +8,6 @@ import (
|
||||||
"starter-template/__htmgo"
|
"starter-template/__htmgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed assets/dist/*
|
|
||||||
var StaticAssets embed.FS
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
locator := service.NewLocator()
|
locator := service.NewLocator()
|
||||||
|
|
||||||
|
|
@ -19,7 +15,7 @@ func main() {
|
||||||
ServiceLocator: locator,
|
ServiceLocator: locator,
|
||||||
LiveReload: true,
|
LiveReload: true,
|
||||||
Register: func(app *h.App) {
|
Register: func(app *h.App) {
|
||||||
sub, err := fs.Sub(StaticAssets, "assets/dist")
|
sub, err := fs.Sub(GetStaticAssets(), "assets/dist")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue