feat: add manual file enhancement with development mode support

- Add manual enhance API endpoint (POST /api/enhance?site_id={site}) for triggering file enhancement
- Implement enhance button in JavaScript library status indicator (🔄 Enhance)
- Disable auto-enhancement in development mode to prevent live-reload conflicts
- Add dev mode parameter to SiteManager to control enhancement behavior
- Update API routing structure to support /api/enhance endpoint
- Include enhance button styling and user feedback (loading, success, error states)
- Button triggers file enhancement and page reload to show updated static files

Development workflow improvements:
- Content edits → Immediate editor preview (no unwanted page reloads)
- Manual enhance button → Intentional file updates + reload for testing
- Production mode maintains automatic enhancement on content changes

This resolves the live-reload conflict where automatic file enhancement
was causing unwanted page reloads during content editing in development.
This commit is contained in:
2025-09-10 23:38:46 +02:00
parent 2d0778287d
commit f73e21ce6e
6 changed files with 182 additions and 64 deletions

View File

@@ -40,6 +40,53 @@ func (h *ContentHandler) SetSiteManager(siteManager *content.SiteManager) {
h.siteManager = siteManager
}
// EnhanceSite handles POST /api/enhance - manual site enhancement trigger
func (h *ContentHandler) EnhanceSite(w http.ResponseWriter, r *http.Request) {
siteID := r.URL.Query().Get("site_id")
if siteID == "" {
http.Error(w, "site_id parameter is required", http.StatusBadRequest)
return
}
if h.siteManager == nil {
http.Error(w, "Site manager not available", http.StatusServiceUnavailable)
return
}
// Check if site is registered
site, exists := h.siteManager.GetSite(siteID)
if !exists {
http.Error(w, fmt.Sprintf("Site %s is not registered", siteID), http.StatusNotFound)
return
}
// Perform enhancement
err := h.siteManager.EnhanceSite(siteID)
if err != nil {
log.Printf("❌ Manual enhancement failed for site %s: %v", siteID, err)
http.Error(w, fmt.Sprintf("Enhancement failed: %v", err), http.StatusInternalServerError)
return
}
// Get enhancement statistics
stats := h.siteManager.GetStats()
// Return success response with details
response := map[string]interface{}{
"success": true,
"site_id": siteID,
"site_path": site.Path,
"message": fmt.Sprintf("Successfully enhanced site %s", siteID),
"stats": stats,
"timestamp": time.Now().Format(time.RFC3339),
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
log.Printf("✅ Manual enhancement completed for site %s", siteID)
}
// GetContent handles GET /api/content/{id}
func (h *ContentHandler) GetContent(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)