Fix demo site auto-enhancement and content persistence

- Restructure demo directory from test-sites/ to demos/ with flattened layout
- Add auto-enhancement on server startup for all sites with auto_enhance: true
- Fix inconsistent content ID generation that prevented dan-eden-portfolio content persistence
- Update server configuration to enhance from source to separate output directories
- Remove manual enhancement from justfile in favor of automatic server enhancement
- Clean up legacy test files and unused restore command
- Update build system to use CDN endpoint instead of file copying
This commit is contained in:
2025-09-17 00:07:40 +02:00
parent 1fa607c47c
commit 71561316da
73 changed files with 190 additions and 4827 deletions

View File

@@ -192,6 +192,11 @@ func (e *Enhancer) enhanceWithEngine(htmlContent []byte, filePath string) ([]byt
return []byte(buf.String()), nil
}
// SetSiteID sets the site ID for the enhancer
func (e *Enhancer) SetSiteID(siteID string) {
e.siteID = siteID
}
// EnhanceInPlace performs in-place enhancement of static site files
func (e *Enhancer) EnhanceInPlace(sitePath string, siteID string) error {
// Use the provided siteID (derivation should happen at CLI level)
@@ -204,7 +209,7 @@ func (e *Enhancer) EnhanceInPlace(sitePath string, siteID string) error {
// DeriveOrValidateSiteID automatically derives site_id for demo paths or validates for production
func DeriveOrValidateSiteID(sitePath string, configSiteID string) string {
// Check if this is a demo path
if strings.Contains(sitePath, "/demos/") {
if strings.Contains(sitePath, "/demos/") || strings.Contains(sitePath, "./demos/") {
return deriveDemoSiteID(sitePath)
}
@@ -222,10 +227,10 @@ func deriveDemoSiteID(sitePath string) string {
}
absPath = filepath.Clean(absPath)
// Look for patterns in demo paths:
// demos/demo-site_enhanced -> "demo"
// demos/simple/test-simple_enhanced -> "simple"
// demos/simple/dan-eden-portfolio -> "dan-eden"
// Flattened structure - just use directory name after demos/
// demos/default -> "default"
// demos/simple -> "simple"
// demos/dan-eden-portfolio -> "dan-eden-portfolio"
parts := strings.Split(absPath, string(filepath.Separator))
@@ -240,41 +245,14 @@ func deriveDemoSiteID(sitePath string) string {
if demosIndex == -1 || demosIndex >= len(parts)-1 {
// Fallback if demos not found in path
return "demo"
return "default"
}
// Get the segment after demos/
nextSegment := parts[demosIndex+1]
// Get the segment after demos/ and clean it
dirName := parts[demosIndex+1]
dirName = strings.TrimSuffix(dirName, "_enhanced")
// Handle different demo directory patterns:
if strings.HasPrefix(nextSegment, "demo-site") {
return "demo"
}
if nextSegment == "simple" && len(parts) > demosIndex+2 {
// For demos/simple/something, use the something part
finalSegment := parts[demosIndex+2]
// Extract meaningful name from directory
if strings.HasPrefix(finalSegment, "test-") {
// test-simple_enhanced -> simple
return "simple"
}
if strings.Contains(finalSegment, "dan-eden") {
return "dan-eden"
}
// Generic case: use the directory name as-is
return strings.TrimSuffix(finalSegment, "_enhanced")
}
// Default case: use the immediate subdirectory of demos/
result := strings.TrimSuffix(nextSegment, "_enhanced")
// Clean up common suffixes
result = strings.TrimSuffix(result, "-site")
return result
return dirName
}
// copyFile copies a file from src to dst