more config

This commit is contained in:
maddalax 2024-10-14 09:49:48 -05:00
parent da82b7f536
commit 2bac9307c6
6 changed files with 29 additions and 34 deletions

View file

@ -12,7 +12,7 @@ import (
) )
func IsTailwindEnabled() bool { func IsTailwindEnabled() bool {
return dirutil.HasFileFromRoot("tailwind.config.js") return dirutil.GetConfig().Tailwind && dirutil.HasFileFromRoot("tailwind.config.js")
} }
func Setup() bool { func Setup() bool {

View file

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/maddalax/htmgo/cli/htmgo/internal" "github.com/maddalax/htmgo/cli/htmgo/internal"
@ -36,8 +35,6 @@ func startWatcher(cb func(version string, file []*fsnotify.Event)) {
for { for {
select { select {
case event, ok := <-watcher.Events: case event, ok := <-watcher.Events:
slog.Debug("event:", slog.String("name", event.Name), slog.String("op", event.Op.String()))
if !ok { if !ok {
return return
} }
@ -69,23 +66,25 @@ func startWatcher(cb func(version string, file []*fsnotify.Event)) {
} }
} }
if dirutil.IsGlobMatch(event.Name, config.WatchFiles, config.WatchIgnore) { if event.Has(fsnotify.Write) || event.Has(fsnotify.Remove) || event.Has(fsnotify.Rename) {
if event.Has(fsnotify.Write) || event.Has(fsnotify.Remove) || event.Has(fsnotify.Rename) { if !dirutil.IsGlobMatch(event.Name, config.WatchFiles, config.WatchIgnore) {
events = append(events, &event) continue
debouncer.Do(func() {
seen := make(map[string]bool)
dedupe := make([]*fsnotify.Event, 0)
for _, e := range events {
if _, ok := seen[e.Name]; !ok {
seen[e.Name] = true
dedupe = append(dedupe, e)
}
}
cb(uuid.NewString()[0:6], dedupe)
events = make([]*fsnotify.Event, 0)
})
} }
events = append(events, &event)
debouncer.Do(func() {
seen := make(map[string]bool)
dedupe := make([]*fsnotify.Event, 0)
for _, e := range events {
if _, ok := seen[e.Name]; !ok {
seen[e.Name] = true
dedupe = append(dedupe, e)
}
}
cb(uuid.NewString()[0:6], dedupe)
events = make([]*fsnotify.Event, 0)
})
} }
case err, ok := <-watcher.Errors: case err, ok := <-watcher.Errors:
if !ok { if !ok {
return return
@ -105,15 +104,6 @@ func startWatcher(cb func(version string, file []*fsnotify.Event)) {
watcher.Add(assetPath) watcher.Add(assetPath)
} }
go func() {
for {
time.Sleep(time.Second * 5)
files := watcher.WatchList()
count := len(files)
fmt.Printf("Watching %d dirs\n", count)
}
}()
// Walk through the root directory and add all subdirectories to the watcher // Walk through the root directory and add all subdirectories to the watcher
err = filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error { err = filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {

View file

@ -1 +0,0 @@
tailwind: true

View file

@ -19,7 +19,7 @@ func DefaultProjectConfig() *ProjectConfig {
"node_modules", ".git", ".idea", "assets/dist", "node_modules", ".git", ".idea", "assets/dist",
}, },
WatchFiles: []string{ WatchFiles: []string{
"**/*.go", "**/*.html", "**/*.css", "**/*.js", "**/*.json", "**/*.yaml", "**/*.yml", "**/*.go", "**/*.html", "**/*.css", "**/*.js", "**/*.json", "**/*.yaml", "**/*.yml", "**/*.md",
}, },
} }
} }

View file

@ -1,5 +1,10 @@
# htmgo configuration
# if tailwindcss is enabled, htmgo will automatically compile your tailwind and output it to assets/dist
tailwind: true tailwind: true
# which directories to ignore when watching for changes, supports glob patterns
# which directories to ignore when watching for changes, supports glob patterns through https://github.com/bmatcuk/doublestar
watch_ignore: [".git", "node_modules", "dist/*"] watch_ignore: [".git", "node_modules", "dist/*"]
# files to watch for changes that are not included by default, supports glob patterns
watch_files: ["**/*.go", "**/*.css"] # files to watch for changes, supports glob patterns through https://github.com/bmatcuk/doublestar
watch_files: ["**/*.go", "**/*.css", "**/*.md"]

View file

@ -45,7 +45,8 @@ func PageWithNav(ctx *h.RequestContext, children ...h.Ren) *h.Element {
return RootPage(ctx, return RootPage(ctx,
h.Fragment( h.Fragment(
partials.NavBar(ctx, partials.NavBarProps{ partials.NavBar(ctx, partials.NavBarProps{
Expanded: false, Expanded: false,
ShowPreRelease: true,
}), }),
h.Div( h.Div(
children..., children...,