Remove internal/content package and use engine directly
- Eliminate content.Enhancer wrapper around engine.ContentEngine - Update cmd/enhance.go to call engine.ProcessFile/ProcessDirectory directly - Update sites/manager.go to use engine.NewContentEngineWithAuth directly - Remove unused EnhancementConfig and discovery configuration logic - Simplify enhance command to use input path as site ID - Remove CLI config dependency from config package
This commit is contained in:
@@ -9,9 +9,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/insertr/insertr/internal/config"
|
||||
"github.com/insertr/insertr/internal/content"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
"github.com/insertr/insertr/internal/engine"
|
||||
)
|
||||
|
||||
var enhanceCmd = &cobra.Command{
|
||||
@@ -37,6 +36,7 @@ func init() {
|
||||
|
||||
func runEnhance(cmd *cobra.Command, args []string) {
|
||||
inputPath := args[0]
|
||||
siteID := inputPath
|
||||
|
||||
// Validate input path and determine if it's a file or directory
|
||||
inputStat, err := os.Stat(inputPath)
|
||||
@@ -68,30 +68,6 @@ func runEnhance(cmd *cobra.Command, args []string) {
|
||||
outputDir = "./dist" // default
|
||||
}
|
||||
|
||||
// Auto-derive site_id for demo paths or validate for production
|
||||
if strings.Contains(inputPath, "/demos/") || strings.Contains(inputPath, "./demos/") {
|
||||
// Auto-derive site_id from demo path
|
||||
cfg.CLI.SiteID = content.DeriveOrValidateSiteID(inputPath, cfg.CLI.SiteID)
|
||||
} else {
|
||||
// Validate site_id for non-demo paths
|
||||
if cfg.CLI.SiteID == "" || cfg.CLI.SiteID == "demo" {
|
||||
log.Fatalf(`❌ site_id must be explicitly configured for non-demo sites.
|
||||
|
||||
💡 Examples:
|
||||
# Set via command line:
|
||||
insertr enhance --site-id mysite /path/to/site
|
||||
|
||||
# Set in insertr.yaml:
|
||||
cli:
|
||||
site_id: "mysite"
|
||||
|
||||
# Set via environment:
|
||||
INSERTR_CLI_SITE_ID=mysite insertr enhance /path/to/site
|
||||
|
||||
🚀 For demo sites under demos/, site_id is auto-derived from the directory name.`)
|
||||
}
|
||||
}
|
||||
|
||||
// Create content client
|
||||
var client db.ContentRepository
|
||||
if cfg.API.URL != "" {
|
||||
@@ -109,37 +85,13 @@ func runEnhance(cmd *cobra.Command, args []string) {
|
||||
panic("🧪 No database or API configured\n")
|
||||
}
|
||||
|
||||
// Load site-specific configuration
|
||||
enhancementConfig := content.EnhancementConfig{
|
||||
Discovery: config.DiscoveryConfig{
|
||||
Enabled: false, // Default: disabled for explicit class="insertr" markings only
|
||||
Aggressive: false,
|
||||
Containers: true,
|
||||
Individual: true,
|
||||
},
|
||||
ContentInjection: true,
|
||||
GenerateIDs: true,
|
||||
}
|
||||
|
||||
// Override with site-specific discovery config if available
|
||||
for _, site := range cfg.Server.Sites {
|
||||
if site.SiteID == cfg.CLI.SiteID && site.Discovery != nil {
|
||||
enhancementConfig.Discovery.Enabled = site.Discovery.Enabled
|
||||
enhancementConfig.Discovery.Aggressive = site.Discovery.Aggressive
|
||||
enhancementConfig.Discovery.Containers = site.Discovery.Containers
|
||||
enhancementConfig.Discovery.Individual = site.Discovery.Individual
|
||||
fmt.Printf("🔧 Site '%s': discovery.enabled=%v\n", cfg.CLI.SiteID, site.Discovery.Enabled)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Create enhancer with loaded configuration
|
||||
enhancer := content.NewEnhancer(client, cfg.CLI.SiteID, enhancementConfig)
|
||||
// Create content engine directly
|
||||
contentEngine := engine.NewContentEngine(client)
|
||||
|
||||
fmt.Printf("🚀 Starting enhancement process...\n")
|
||||
fmt.Printf("📁 Input: %s\n", inputPath)
|
||||
fmt.Printf("📁 Output: %s\n", outputDir)
|
||||
fmt.Printf("🏷️ Site ID: %s\n\n", cfg.CLI.SiteID)
|
||||
fmt.Printf("🏷️ Site ID: %s\n\n", siteID)
|
||||
|
||||
// Enhance based on input type
|
||||
if isFile {
|
||||
@@ -151,11 +103,11 @@ func runEnhance(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
// If output doesn't exist or is a file, use it as-is as the output file path
|
||||
|
||||
if err := enhancer.EnhanceFile(inputPath, outputFilePath); err != nil {
|
||||
if err := contentEngine.ProcessFile(inputPath, outputFilePath, siteID, engine.Enhancement); err != nil {
|
||||
log.Fatalf("Enhancement failed: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err := enhancer.EnhanceDirectory(inputPath, outputDir); err != nil {
|
||||
if err := contentEngine.ProcessDirectory(inputPath, outputDir, siteID, engine.Enhancement); err != nil {
|
||||
log.Fatalf("Enhancement failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user