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 {
return dirutil.HasFileFromRoot("tailwind.config.js")
return dirutil.GetConfig().Tailwind && dirutil.HasFileFromRoot("tailwind.config.js")
}
func Setup() bool {

View file

@ -1,7 +1,6 @@
package main
import (
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/google/uuid"
"github.com/maddalax/htmgo/cli/htmgo/internal"
@ -36,8 +35,6 @@ func startWatcher(cb func(version string, file []*fsnotify.Event)) {
for {
select {
case event, ok := <-watcher.Events:
slog.Debug("event:", slog.String("name", event.Name), slog.String("op", event.Op.String()))
if !ok {
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) {
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)
})
if event.Has(fsnotify.Write) || event.Has(fsnotify.Remove) || event.Has(fsnotify.Rename) {
if !dirutil.IsGlobMatch(event.Name, config.WatchFiles, config.WatchIgnore) {
continue
}
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:
if !ok {
return
@ -105,15 +104,6 @@ func startWatcher(cb func(version string, file []*fsnotify.Event)) {
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
err = filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
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",
},
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
# 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/*"]
# 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,
h.Fragment(
partials.NavBar(ctx, partials.NavBarProps{
Expanded: false,
Expanded: false,
ShowPreRelease: true,
}),
h.Div(
children...,