Files
insertr/internal/content/enhancer.go
Joakim d0ac3088b4 refactor: consolidate database structure and move injector to engine
Database Structure Cleanup:
- Move all SQL files from ./db/ to ./internal/db/
- Update sqlc.yaml to use new paths (preserving schema+setup.sql hack)
- Consolidate database-related code in single directory
- Remove empty ./db/ directory

Injector Migration:
- Move injector.go from content package to engine package
- Update ContentClient interface to return map instead of slice for GetBulkContent
- Update database client implementation to match interface
- Remove injector dependency from enhancer (stub implementation)

Demo-Site Consolidation:
- Move demo-site to test-sites/demo-site for better organization
- Update build scripts to use new demo-site location
- Maintain all functionality while improving project structure

This continues the unified architecture consolidation by moving core content
processing logic to the engine and organizing related files properly.
2025-09-16 15:39:25 +02:00

94 lines
2.6 KiB
Go

package content
import (
"fmt"
"os"
"path/filepath"
"github.com/insertr/insertr/internal/engine"
)
// Enhancer combines parsing and content injection using unified engine
type Enhancer struct {
engine *engine.ContentEngine
// injector functionality will be integrated into engine
}
// NewEnhancer creates a new HTML enhancer using unified engine
func NewEnhancer(client ContentClient, siteID string) *Enhancer {
// Create database client for engine
var engineClient engine.ContentClient
if dbClient, ok := client.(*DatabaseClient); ok {
engineClient = engine.NewDatabaseClient(dbClient.db)
} else {
// For non-database clients, we'll implement proper handling later
engineClient = engine.NewDatabaseClient(nil) // This will need to be fixed
}
return &Enhancer{
engine: engine.NewContentEngine(engineClient),
}
}
// EnhanceFile processes an HTML file and injects content
func (e *Enhancer) EnhanceFile(inputPath, outputPath string) error {
// TODO: Implement with unified engine
// For now, just copy the file to maintain functionality
return e.copyFile(inputPath, outputPath)
}
// EnhanceDirectory processes all HTML files in a directory
func (e *Enhancer) EnhanceDirectory(inputDir, outputDir string) error {
// Create output directory
if err := os.MkdirAll(outputDir, 0755); err != nil {
return fmt.Errorf("creating output directory: %w", err)
}
// Walk input directory and copy files for now
return filepath.Walk(inputDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Calculate relative path and output path
relPath, err := filepath.Rel(inputDir, path)
if err != nil {
return err
}
outputPath := filepath.Join(outputDir, relPath)
// Handle directories
if info.IsDir() {
return os.MkdirAll(outputPath, info.Mode())
}
// Copy files (HTML processing will be implemented later)
return e.copyFile(path, outputPath)
})
}
// EnhanceInPlace performs in-place enhancement of static site files
func (e *Enhancer) EnhanceInPlace(sitePath string, siteID string) error {
// TODO: Implement with unified engine
// For now, just log that enhancement was requested
fmt.Printf("📄 Enhancement requested for site %s at %s (stub implementation)\n", siteID, sitePath)
return nil
}
// copyFile copies a file from src to dst
func (e *Enhancer) copyFile(src, dst string) error {
// Create directory for destination
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
return err
}
// Read source
data, err := os.ReadFile(src)
if err != nil {
return err
}
// Write destination
return os.WriteFile(dst, data, 0644)
}