Pi66

Home | Repos | About | Blog | Gaza

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

About | Files | Commits | Refs | License


fix: debounce duplicate file events

Author: pi66
Date: 2026-09-18 21:13
commit: c8feb418

Stat

A src/core/watch/main.go 9 +9 -0

Diff

diff --git a/src/core/watch/main.go b/src/core/watch/main.go
index edf9a26..20eecf2 100644
--- a/src/core/watch/main.go
+++ b/src/core/watch/main.go
@@ -25,6 +25,9 @@ func (self *Watcher) Run(state *state.State, args *[]string) (err error) {
 	check(watcher.Add(state.Config.Tree.Markdown))
 	check(state.Lua.RunHook("on_start_watching"))

+ lastEvents := make(map[string]time.Time) + const debounce = 100 * time.Millisecond + for { select { case event, ok := <-watcher.Events: @@ -32,6 +35,12 @@ func (self *Watcher) Run(state *state.State, args *[]string) (err error) { return nil }

+ now := time.Now() + if last, ok := lastEvents[event.Name]; ok && now.Sub(last) < debounce { ...

Show all

diff --git a/src/core/watch/main.go b/src/core/watch/main.go
index edf9a26..20eecf2 100644
--- a/src/core/watch/main.go
+++ b/src/core/watch/main.go
@@ -25,6 +25,9 @@ func (self *Watcher) Run(state *state.State, args *[]string) (err error) {
 	check(watcher.Add(state.Config.Tree.Markdown))
 	check(state.Lua.RunHook("on_start_watching"))

+ lastEvents := make(map[string]time.Time) + const debounce = 100 * time.Millisecond + for { select { case event, ok := <-watcher.Events: @@ -32,6 +35,12 @@ func (self *Watcher) Run(state *state.State, args *[]string) (err error) { return nil }

+ now := time.Now() + if last, ok := lastEvents[event.Name]; ok && now.Sub(last) < debounce { + continue + } + + lastEvents[event.Name] = now check(state.Lua.RunHook("on_file_changed", event.Op.String(), event.Name))

	case err, ok := &#60;-watcher.Errors:

// Created by Pi66

// Copyright ©Pi66 2026