fix: disable auto-enhancement in development mode to prevent live-reload loops

- Add dev_mode parameter to SiteManager constructor
- Modify IsAutoEnhanceEnabled() to return false when dev_mode is true
- Update serve.go to pass dev_mode flag to SiteManager
- Add ForceEnhanceEnabled() method for testing production behavior in development
- Update documentation to explain development vs production mode behavior

This fixes the development workflow where content updates would trigger
file modifications that caused unwanted page reloads in live-server.

Development mode: Content saved to database only, editor loads dynamically
Production mode: Content saved + files enhanced for immediate static deployment
This commit is contained in:
2025-09-10 23:12:32 +02:00
parent 8d92c6477b
commit 2d0778287d
4 changed files with 58 additions and 7 deletions

View File

@@ -24,10 +24,11 @@ type SiteManager struct {
enhancer *Enhancer
mutex sync.RWMutex
backupDir string
devMode bool
}
// NewSiteManager creates a new site manager
func NewSiteManager(contentClient ContentClient, backupDir string) *SiteManager {
func NewSiteManager(contentClient ContentClient, backupDir string, devMode bool) *SiteManager {
if backupDir == "" {
backupDir = "./insertr-backups"
}
@@ -36,6 +37,7 @@ func NewSiteManager(contentClient ContentClient, backupDir string) *SiteManager
sites: make(map[string]*SiteConfig),
enhancer: NewEnhancer(contentClient, ""), // siteID will be set per operation
backupDir: backupDir,
devMode: devMode,
}
}
@@ -103,10 +105,26 @@ func (sm *SiteManager) GetAllSites() map[string]*SiteConfig {
}
// IsAutoEnhanceEnabled checks if a site has auto-enhancement enabled
// Returns false in development mode to prevent unwanted file modifications and live-reload loops
func (sm *SiteManager) IsAutoEnhanceEnabled(siteID string) bool {
sm.mutex.RLock()
defer sm.mutex.RUnlock()
// Disable auto-enhancement in development mode to prevent file modification conflicts with live-reload
if sm.devMode {
return false
}
site, exists := sm.sites[siteID]
return exists && site.AutoEnhance
}
// ForceEnhanceEnabled allows testing production behavior in development mode
// This method bypasses the dev_mode check for testing purposes
func (sm *SiteManager) ForceEnhanceEnabled(siteID string) bool {
sm.mutex.RLock()
defer sm.mutex.RUnlock()
site, exists := sm.sites[siteID]
return exists && site.AutoEnhance
}