Clean up legacy code after unified architecture implementation

- Remove obsolete cmd/auto_enhance.go command (replaced by unified enhance)
- Implement EnhanceInPlace method using unified pipeline
- Remove generated demo files from git tracking
- Verify all functionality works after cleanup:
  * go build successful
  * enhance command working correctly
  * unified pipeline (discovery → ID generation → content injection) verified
  * clean command structure (only enhance, serve, restore commands)

The codebase is now clean with no legacy auto-enhance references or stub implementations. All functionality consolidated into the unified Discoverer + Enhancer architecture.
This commit is contained in:
2025-09-16 17:08:43 +02:00
parent 27a619b452
commit eabb7b16e8
14 changed files with 145 additions and 134 deletions

6
.gitignore vendored
View File

@@ -98,11 +98,7 @@ client-dist/
output/
# Generated demo sites (auto-generated by CLI)
test-sites/**/*-demo/
test-sites/**/*-enhanced/
test-sites/**/*-auto/
test-sites/**/*-temp/
test-sites/**/*-full/
test-sites/**/*_enhanced/
# Air temporary files
tmp/

View File

@@ -1,91 +0,0 @@
package cmd
import (
"fmt"
"os"
"github.com/insertr/insertr/internal/content"
"github.com/spf13/cobra"
)
var (
autoEnhanceOutput string
autoEnhanceAggressive bool
)
var autoEnhanceCmd = &cobra.Command{
Use: "auto-enhance [input-dir]",
Short: "Automatically detect and add insertr classes to HTML elements",
Long: `Auto-enhance scans HTML files and automatically adds insertr classes to viable content elements.
This command uses intelligent heuristics to detect editable content:
- Text-only elements (headers, paragraphs, simple links)
- Elements with safe inline formatting (strong, em, span, etc.)
- Container elements that benefit from expansion
- Buttons and other interactive content elements
Examples:
insertr auto-enhance ./site --output ./enhanced
insertr auto-enhance ./blog --output ./blog-enhanced --aggressive
insertr auto-enhance /path/to/site --output /path/to/enhanced`,
Args: cobra.ExactArgs(1),
RunE: runAutoEnhance,
}
func runAutoEnhance(cmd *cobra.Command, args []string) error {
inputDir := args[0]
// Validate input directory
if _, err := os.Stat(inputDir); os.IsNotExist(err) {
return fmt.Errorf("input directory does not exist: %s", inputDir)
}
// Default output directory if not specified
if autoEnhanceOutput == "" {
autoEnhanceOutput = inputDir + "-enhanced"
}
fmt.Printf("🔍 Auto-enhancing HTML files...\n")
fmt.Printf("📁 Input: %s\n", inputDir)
fmt.Printf("📁 Output: %s\n", autoEnhanceOutput)
if autoEnhanceAggressive {
fmt.Printf("⚡ Aggressive mode: enabled\n")
}
fmt.Printf("\n")
// Create discoverer
discoverer := content.NewDiscoverer()
// Run element discovery
result, err := discoverer.DiscoverDirectory(inputDir, autoEnhanceOutput, autoEnhanceAggressive)
if err != nil {
return fmt.Errorf("auto-enhancement failed: %w", err)
}
// Print results
fmt.Printf("✅ Auto-enhancement complete!\n\n")
fmt.Printf("📊 Results:\n")
fmt.Printf(" Files processed: %d\n", result.FilesProcessed)
fmt.Printf(" Elements enhanced: %d\n", result.ElementsEnhanced)
fmt.Printf(" Containers added: %d\n", result.ContainersAdded)
fmt.Printf(" Individual elements: %d\n", result.IndividualsAdded)
if len(result.SkippedFiles) > 0 {
fmt.Printf("\n⚠ Skipped files (%d):\n", len(result.SkippedFiles))
for _, file := range result.SkippedFiles {
fmt.Printf(" - %s\n", file)
}
}
fmt.Printf("\n🎯 Enhanced files ready in: %s\n", autoEnhanceOutput)
fmt.Printf("📝 Use 'insertr enhance %s' to inject content from database\n", autoEnhanceOutput)
return nil
}
func init() {
autoEnhanceCmd.Flags().StringVarP(&autoEnhanceOutput, "output", "o", "", "output directory for enhanced files")
autoEnhanceCmd.Flags().BoolVar(&autoEnhanceAggressive, "aggressive", false, "aggressive mode: enhance single-child containers")
rootCmd.AddCommand(autoEnhanceCmd)
}

View File

@@ -13,13 +13,18 @@ server:
port: 8080 # HTTP API server port
sites: # Registered sites for file-based enhancement
- site_id: "demo"
path: "./test-sites/demo-site"
path: "./test-sites/demo-site_enhanced"
domain: "localhost:3000"
auto_enhance: true
backup_originals: true
- site_id: "dan-eden-test"
path: "./test-sites/simple/dan-eden-portfolio"
domain: "localhost:3001"
- site_id: "simple"
path: "./test-sites/simple/test-simple_enhanced"
domain: "localhost:3000"
auto_enhance: true
backup_originals: true
- site_id: "dan-eden"
path: "./test-sites/simple/dan-eden-portfolio_enhanced"
domain: "localhost:3000"
auto_enhance: true
backup_originals: true
# Example additional site configuration:

View File

@@ -342,8 +342,15 @@ func (h *ContentHandler) CreateContent(w http.ResponseWriter, r *http.Request) {
item := h.convertToAPIContent(content)
// Trigger file enhancement if site is registered for auto-enhancement
if h.siteManager != nil && h.siteManager.IsAutoEnhanceEnabled(siteID) {
log.Printf("🔍 Checking auto-enhancement for site: %s", siteID)
if h.siteManager == nil {
log.Printf("❌ No site manager configured")
} else if !h.siteManager.IsAutoEnhanceEnabled(siteID) {
log.Printf("❌ Auto-enhancement not enabled for site: %s", siteID)
} else {
log.Printf("✅ Triggering auto-enhancement for site: %s", siteID)
go func() {
log.Printf("🔄 Starting enhancement for site: %s", siteID)
if err := h.siteManager.EnhanceSite(siteID); err != nil {
log.Printf("⚠️ Failed to enhance site %s: %v", siteID, err)
} else {

View File

@@ -133,12 +133,17 @@ func (disc *Discoverer) discoverNode(node *html.Node, result *FileDiscoveryResul
if disc.isGoodContainer(node) {
viableChildren := engine.FindViableChildren(node)
if len(viableChildren) >= 2 || (aggressive && len(viableChildren) >= 1) {
// Add insertr class to container for expansion
disc.addInsertrClass(node)
// Container expansion: add insertr class to each viable child, not the container
for _, child := range viableChildren {
if !disc.hasInsertrClass(child) {
disc.addInsertrClass(child)
result.IndividualsAdded++
result.ElementsEnhanced++
}
}
result.ContainersAdded++
result.ElementsEnhanced += len(viableChildren)
// Don't process children since container expansion handles them
// Don't process children since we just processed them
return
}
}

View File

@@ -194,9 +194,11 @@ func (e *Enhancer) enhanceWithEngine(htmlContent []byte, filePath string) ([]byt
// EnhanceInPlace performs in-place enhancement of static site files
func (e *Enhancer) EnhanceInPlace(sitePath string, siteID string) error {
// TODO: Implement in-place enhancement using the unified pipeline
fmt.Printf("📄 Enhancement requested for site %s at %s (unified pipeline implementation needed)\n", siteID, sitePath)
return nil
// Update the enhancer's site ID for this operation
e.siteID = siteID
// Use EnhanceDirectory with same input and output (in-place)
return e.EnhanceDirectory(sitePath, sitePath)
}
// copyFile copies a file from src to dst

View File

@@ -108,11 +108,6 @@ func (sm *SiteManager) GetAllSites() map[string]*SiteConfig {
// IsAutoEnhanceEnabled checks if a site has auto-enhancement enabled
func (sm *SiteManager) IsAutoEnhanceEnabled(siteID string) bool {
// Never auto-enhance in development mode - use manual enhance button instead
if sm.devMode {
return false
}
sm.mutex.RLock()
defer sm.mutex.RUnlock()

View File

@@ -75,6 +75,12 @@ func (e *ContentEngine) ProcessContent(input ContentInput) (*ContentResult, erro
}
}
// 5. Inject editor assets for enhancement mode (development)
if input.Mode == Enhancement {
injector := NewInjector(e.client, input.SiteID)
injector.InjectEditorAssets(doc, true, "")
}
return &ContentResult{
Document: doc,
Elements: processedElements,

View File

@@ -15,6 +15,15 @@ dev: build-lib build
#!/usr/bin/env bash
echo "🚀 Starting Full-Stack Insertr Development..."
echo "================================================"
echo ""
# Enhance demo site if needed
if [ ! -d "./test-sites/demo-site_enhanced" ]; then
echo "🔧 Demo site not ready - enhancing now..."
./insertr enhance test-sites/demo-site --output test-sites/demo-site_enhanced --config test-sites/demo-site/insertr.yaml
echo "✅ Demo site enhanced!"
fi
echo ""
echo "📝 Unified logs below (API server + Demo site):"
echo "🔌 [SERVER] = API server logs"
@@ -34,7 +43,7 @@ dev: build-lib build
# Start API server with prefixed output
echo "🔌 Starting API server (localhost:8080)..."
INSERTR_DATABASE_PATH=./dev.db ./insertr serve --dev-mode 2>&1 | sed 's/^/🔌 [SERVER] /' &
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --dev-mode 2>&1 | sed 's/^/🔌 [SERVER] /' &
SERVER_PID=$!
# Wait for server startup
@@ -53,8 +62,8 @@ dev: build-lib build
echo "📝 Full-stack ready - edit content with real-time persistence!"
echo ""
# Start demo site with prefixed output (this will block) - use local installation
cd {{justfile_directory()}} && npx --prefer-offline live-server test-sites/demo-site --port=3000 --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [DEMO] /' &
# Start enhanced demo site with prefixed output (this will block) - use local installation
cd {{justfile_directory()}} && npx --prefer-offline live-server test-sites/demo-site_enhanced --port=3000 --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [DEMO] /' &
DEMO_PID=$!
# Wait for both processes
@@ -67,7 +76,7 @@ dev: build-lib build
dev-about: build-lib build
#!/usr/bin/env bash
echo "🚀 Starting full-stack development (about page)..."
INSERTR_DATABASE_PATH=./dev.db ./insertr serve --dev-mode &
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --dev-mode &
SERVER_PID=$!
sleep 3
npx --prefer-offline live-server test-sites/demo-site --port=3000 --host=localhost --open=/about.html
@@ -98,24 +107,29 @@ demo site="":
echo ""
echo "💡 Note: Sites are auto-enhanced on first run"
elif [ "{{site}}" = "default" ] || [ "{{site}}" = "demo" ]; then
if [ ! -d "./test-sites/demo-site_enhanced" ]; then
echo "🔧 Default demo not ready - enhancing now..."
just build
./insertr enhance test-sites/demo-site --output test-sites/demo-site_enhanced --config test-sites/demo-site/insertr.yaml
fi
echo "🚀 Starting default demo site..."
just dev
just demo-site "demo" "./test-sites/demo-site_enhanced" "3000"
elif [ "{{site}}" = "dan-eden" ]; then
if [ ! -d "./test-sites/simple/dan-eden-portfolio-demo" ]; then
if [ ! -d "./test-sites/simple/dan-eden-portfolio_enhanced" ]; then
echo "🔧 Dan Eden demo not ready - enhancing now..."
just build
./insertr enhance test-sites/simple/dan-eden-portfolio --output test-sites/simple/dan-eden-portfolio-demo --config test-sites/simple/dan-eden-portfolio/insertr.yaml
./insertr enhance test-sites/simple/dan-eden-portfolio --output test-sites/simple/dan-eden-portfolio_enhanced --config test-sites/simple/dan-eden-portfolio/insertr.yaml
fi
echo "🚀 Starting Dan Eden portfolio demo..."
just demo-site "dan-eden" "./test-sites/simple/dan-eden-portfolio-demo" "3000"
just demo-site "dan-eden" "./test-sites/simple/dan-eden-portfolio_enhanced" "3000"
elif [ "{{site}}" = "simple" ]; then
if [ ! -d "./test-sites/simple/test-simple-demo" ]; then
if [ ! -d "./test-sites/simple/test-simple_enhanced" ]; then
echo "🔧 Simple demo not ready - enhancing now..."
just build
./insertr enhance test-sites/simple/test-simple --output test-sites/simple/test-simple-demo --config test-sites/simple/test-simple/insertr.yaml
./insertr enhance test-sites/simple/test-simple --output test-sites/simple/test-simple_enhanced --config test-sites/simple/test-simple/insertr.yaml
fi
echo "🚀 Starting simple test site demo..."
just demo-site "simple" "./test-sites/simple/test-simple-demo" "3000"
just demo-site "simple" "./test-sites/simple/test-simple_enhanced" "3000"
else
echo "❌ Unknown demo site: {{site}}"
echo ""
@@ -151,7 +165,7 @@ demo-site site_id path port="3000": build
# Start API server
echo "🔌 Starting API server (localhost:8080)..."
INSERTR_DATABASE_PATH=./dev.db ./insertr serve --dev-mode 2>&1 | sed 's/^/🔌 [{{site_id}}] /' &
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --dev-mode 2>&1 | sed 's/^/🔌 [{{site_id}}] /' &
SERVER_PID=$!
# Wait for server startup
@@ -211,7 +225,7 @@ enhance input="test-sites/demo-site" output="dist":
# Start content API server (default port 8080)
serve port="8080":
INSERTR_DATABASE_PATH=./dev.db ./insertr serve --port {{port}} --dev-mode
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --port {{port}} --dev-mode
# Start API server in production mode
serve-prod port="8080" db="./insertr.db":
@@ -292,14 +306,19 @@ clean-demos:
echo "========================================="
# Demo directories
if [ -d "./test-sites/simple/dan-eden-portfolio-demo" ]; then
rm -rf "./test-sites/simple/dan-eden-portfolio-demo"
echo "🗑️ Removed: dan-eden-portfolio-demo"
if [ -d "./test-sites/demo-site_enhanced" ]; then
rm -rf "./test-sites/demo-site_enhanced"
echo "🗑️ Removed: demo-site_enhanced"
fi
if [ -d "./test-sites/simple/test-simple-demo" ]; then
rm -rf "./test-sites/simple/test-simple-demo"
echo "🗑️ Removed: test-simple-demo"
if [ -d "./test-sites/simple/dan-eden-portfolio_enhanced" ]; then
rm -rf "./test-sites/simple/dan-eden-portfolio_enhanced"
echo "🗑️ Removed: dan-eden-portfolio_enhanced"
fi
if [ -d "./test-sites/simple/test-simple_enhanced" ]; then
rm -rf "./test-sites/simple/test-simple_enhanced"
echo "🗑️ Removed: test-simple_enhanced"
fi
# Clean up any temporary directories

View File

@@ -0,0 +1,27 @@
# Insertr Configuration for Default Demo Site
# Main configuration for the default demo site
# Global settings
dev_mode: true # Development mode for demos
# Database configuration
database:
path: "./insertr.db" # Shared database with main config
# Demo-specific configuration
demo:
site_id: "demo" # Unique site ID for default demo
inject_demo_gate: true # Auto-inject demo gate if no gates exist
mock_auth: true # Use mock authentication for demos
api_endpoint: "http://localhost:8080/api/content"
demo_port: 3000 # Port for live-server
# CLI enhancement configuration
cli:
site_id: "demo" # Site ID for this demo
output: "./demo_enhanced" # Output directory for enhanced files
inject_demo_gate: true # Inject demo gate in development mode
# Authentication configuration (for demo)
auth:
provider: "mock" # Mock auth for demos

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html><html><head>
<title>Simple Test</title>
</head>
<body>
<h1 class="insertr" data-content-id="index-h1-e0f926" data-content-type="text">Welcome</h1>
<p class="insertr" data-content-id="index-p-b376ed" data-content-type="markdown">This is a <strong>test</strong> paragraph with <a href="/">a link</a>.</p>
<div class="insertr" data-content-id="index-div-e90881" data-content-type="markdown">
<h2>Section Title</h2>
<p>Another paragraph here.</p>
<button>Click Me</button>
</div>
</body></html>

View File

@@ -0,0 +1,27 @@
# Insertr Configuration for Simple Demo Site
# Specific configuration for the simple test site demo
# Global settings
dev_mode: true # Development mode for demos
# Database configuration
database:
path: "./insertr.db" # Shared database with main config
# Demo-specific configuration
demo:
site_id: "simple" # Unique site ID for simple demo
inject_demo_gate: true # Auto-inject demo gate if no gates exist
mock_auth: true # Use mock authentication for demos
api_endpoint: "http://localhost:8080/api/content"
demo_port: 3000 # Port for live-server
# CLI enhancement configuration
cli:
site_id: "simple" # Site ID for this demo
output: "./simple-demo" # Output directory for enhanced files
inject_demo_gate: true # Inject demo gate in development mode
# Authentication configuration (for demo)
auth:
provider: "mock" # Mock auth for demos

View File

@@ -19,7 +19,7 @@ demo:
# CLI enhancement configuration
cli:
site_id: "simple" # Site ID for this demo
output: "./simple-demo" # Output directory for enhanced files
output: "./simple_enhanced" # Output directory for enhanced files
inject_demo_gate: true # Inject demo gate in development mode
# Authentication configuration (for demo)