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:
@@ -3,7 +3,6 @@ package config
|
||||
type Config struct {
|
||||
Database DatabaseConfig `yaml:"database" mapstructure:"database"`
|
||||
API APIConfig `yaml:"api" mapstructure:"api"`
|
||||
CLI CLIConfig `yaml:"cli" mapstructure:"cli"`
|
||||
Server ServerConfig `yaml:"server" mapstructure:"server"`
|
||||
Auth AuthConfig `yaml:"auth" mapstructure:"auth"`
|
||||
Library LibraryConfig `yaml:"library" mapstructure:"library"`
|
||||
@@ -18,10 +17,6 @@ type APIConfig struct {
|
||||
Key string `yaml:"key" mapstructure:"key"`
|
||||
}
|
||||
|
||||
type CLIConfig struct {
|
||||
SiteID string `yaml:"site_id" mapstructure:"site_id"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Port int `yaml:"port" mapstructure:"port"`
|
||||
Host string `yaml:"host" mapstructure:"host"`
|
||||
@@ -29,18 +24,10 @@ type ServerConfig struct {
|
||||
}
|
||||
|
||||
type AuthConfig struct {
|
||||
DevMode bool `yaml:"dev_mode" mapstructure:"dev_mode"`
|
||||
Provider string `yaml:"provider" mapstructure:"provider"`
|
||||
JWTSecret string `yaml:"jwt_secret" mapstructure:"jwt_secret"`
|
||||
OAuthConfigs map[string]OAuthConfig `yaml:"oauth_configs" mapstructure:"oauth_configs"`
|
||||
OIDC *OIDCConfig `yaml:"oidc" mapstructure:"oidc"`
|
||||
}
|
||||
|
||||
type OAuthConfig struct {
|
||||
ClientID string `yaml:"client_id" mapstructure:"client_id"`
|
||||
ClientSecret string `yaml:"client_secret" mapstructure:"client_secret"`
|
||||
RedirectURL string `yaml:"redirect_url" mapstructure:"redirect_url"`
|
||||
Scopes []string `yaml:"scopes" mapstructure:"scopes"`
|
||||
DevMode bool `yaml:"dev_mode" mapstructure:"dev_mode"`
|
||||
Provider string `yaml:"provider" mapstructure:"provider"`
|
||||
JWTSecret string `yaml:"jwt_secret" mapstructure:"jwt_secret"`
|
||||
OIDC *OIDCConfig `yaml:"oidc" mapstructure:"oidc"`
|
||||
}
|
||||
|
||||
type OIDCConfig struct {
|
||||
|
||||
@@ -69,9 +69,6 @@ func (l *viperLoader) LoadWithFlags(dbPath, apiURL, apiKey, siteID string) (*Con
|
||||
if apiKey != "" {
|
||||
config.API.Key = apiKey
|
||||
}
|
||||
if siteID != "" {
|
||||
config.CLI.SiteID = siteID
|
||||
}
|
||||
|
||||
return config, validate(config)
|
||||
}
|
||||
@@ -81,10 +78,6 @@ func (l *viperLoader) setDefaults(config *Config) error {
|
||||
config.Database.Path = "./insertr.db"
|
||||
}
|
||||
|
||||
if config.CLI.SiteID == "" {
|
||||
config.CLI.SiteID = "demo"
|
||||
}
|
||||
|
||||
if config.Server.Port == 0 {
|
||||
config.Server.Port = 8080
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -17,10 +18,6 @@ func validate(config *Config) error {
|
||||
return fmt.Errorf("api config: %w", err)
|
||||
}
|
||||
|
||||
if err := validateCLI(config.CLI); err != nil {
|
||||
return fmt.Errorf("cli config: %w", err)
|
||||
}
|
||||
|
||||
if err := validateServer(config.Server); err != nil {
|
||||
return fmt.Errorf("server config: %w", err)
|
||||
}
|
||||
@@ -66,18 +63,6 @@ func validateAPI(config APIConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateCLI(config CLIConfig) error {
|
||||
if config.SiteID == "" {
|
||||
return fmt.Errorf("site_id is required")
|
||||
}
|
||||
|
||||
if strings.TrimSpace(config.SiteID) != config.SiteID {
|
||||
return fmt.Errorf("site_id cannot have leading or trailing whitespace")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateServer(config ServerConfig) error {
|
||||
if config.Port < 1 || config.Port > 65535 {
|
||||
return fmt.Errorf("port must be between 1 and 65535, got %d", config.Port)
|
||||
@@ -136,13 +121,7 @@ func validateAuth(config AuthConfig) error {
|
||||
}
|
||||
|
||||
validProviders := []string{"mock", "authentik"}
|
||||
valid := false
|
||||
for _, provider := range validProviders {
|
||||
if config.Provider == provider {
|
||||
valid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
valid := slices.Contains(validProviders, config.Provider)
|
||||
if !valid {
|
||||
return fmt.Errorf("invalid provider %q, must be one of: %s", config.Provider, strings.Join(validProviders, ", "))
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/insertr/insertr/internal/config"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
"github.com/insertr/insertr/internal/engine"
|
||||
)
|
||||
|
||||
// EnhancementConfig configures the enhancement pipeline
|
||||
type EnhancementConfig struct {
|
||||
Discovery config.DiscoveryConfig
|
||||
ContentInjection bool
|
||||
GenerateIDs bool
|
||||
}
|
||||
|
||||
// Enhancer combines discovery, ID generation, and content injection in unified pipeline
|
||||
type Enhancer struct {
|
||||
engine *engine.ContentEngine
|
||||
config EnhancementConfig
|
||||
siteID string
|
||||
}
|
||||
|
||||
// NewEnhancer creates a new HTML enhancer with unified pipeline
|
||||
func NewEnhancer(client db.ContentRepository, siteID string, config EnhancementConfig) *Enhancer {
|
||||
return &Enhancer{
|
||||
engine: engine.NewContentEngine(client),
|
||||
config: config,
|
||||
siteID: siteID,
|
||||
}
|
||||
}
|
||||
|
||||
// NewEnhancerWithAuth creates a new HTML enhancer with auth provider
|
||||
func NewEnhancerWithAuth(client db.ContentRepository, siteID string, config EnhancementConfig, authProvider *engine.AuthProvider) *Enhancer {
|
||||
return &Enhancer{
|
||||
engine: engine.NewContentEngineWithAuth(client, authProvider),
|
||||
config: config,
|
||||
siteID: siteID,
|
||||
}
|
||||
}
|
||||
|
||||
// NewDefaultEnhancer creates an enhancer with default configuration
|
||||
func NewDefaultEnhancer(client db.ContentRepository, siteID string) *Enhancer {
|
||||
defaultConfig := EnhancementConfig{
|
||||
Discovery: config.DiscoveryConfig{
|
||||
Enabled: true,
|
||||
Aggressive: false,
|
||||
Containers: true,
|
||||
Individual: true,
|
||||
},
|
||||
ContentInjection: true,
|
||||
GenerateIDs: true,
|
||||
}
|
||||
return NewEnhancer(client, siteID, defaultConfig)
|
||||
}
|
||||
|
||||
// EnhanceFile processes a single HTML file through the engine
|
||||
func (e *Enhancer) EnhanceFile(inputPath, outputPath string) error {
|
||||
return e.engine.ProcessFile(inputPath, outputPath, e.siteID, engine.Enhancement)
|
||||
}
|
||||
|
||||
// EnhanceDirectory processes all files in a directory through the engine
|
||||
func (e *Enhancer) EnhanceDirectory(inputDir, outputDir string) error {
|
||||
return e.engine.ProcessDirectory(inputDir, outputDir, e.siteID, engine.Enhancement)
|
||||
}
|
||||
|
||||
// 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)
|
||||
e.siteID = siteID
|
||||
|
||||
// Use EnhanceDirectory with same input and output (in-place)
|
||||
return e.EnhanceDirectory(sitePath, sitePath)
|
||||
}
|
||||
|
||||
// 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/") || strings.Contains(sitePath, "./demos/") {
|
||||
return deriveDemoSiteID(sitePath)
|
||||
}
|
||||
|
||||
// For non-demo paths, return the configured site_id
|
||||
// Validation of non-demo site_id will be handled at the CLI level
|
||||
return configSiteID
|
||||
}
|
||||
|
||||
// deriveDemoSiteID extracts site_id from demo directory structure
|
||||
func deriveDemoSiteID(sitePath string) string {
|
||||
// Convert to absolute path and clean it
|
||||
absPath, err := filepath.Abs(sitePath)
|
||||
if err != nil {
|
||||
absPath = sitePath
|
||||
}
|
||||
absPath = filepath.Clean(absPath)
|
||||
|
||||
// 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))
|
||||
|
||||
// Find the demos directory index
|
||||
demosIndex := -1
|
||||
for i, part := range parts {
|
||||
if part == "demos" {
|
||||
demosIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if demosIndex == -1 || demosIndex >= len(parts)-1 {
|
||||
// Fallback if demos not found in path
|
||||
return "default"
|
||||
}
|
||||
|
||||
// Get the segment after demos/ and clean it
|
||||
dirName := parts[demosIndex+1]
|
||||
dirName = strings.TrimSuffix(dirName, "_enhanced")
|
||||
|
||||
return dirName
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/insertr/insertr/internal/config"
|
||||
"github.com/insertr/insertr/internal/content"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
"github.com/insertr/insertr/internal/engine"
|
||||
"maps"
|
||||
@@ -18,7 +17,6 @@ import (
|
||||
// SiteManager handles registration and enhancement of static sites
|
||||
type SiteManager struct {
|
||||
sites map[string]*config.SiteConfig
|
||||
enhancer *content.Enhancer
|
||||
mutex sync.RWMutex
|
||||
devMode bool
|
||||
contentClient db.ContentRepository
|
||||
@@ -29,7 +27,6 @@ type SiteManager struct {
|
||||
func NewSiteManager(contentClient db.ContentRepository, devMode bool) *SiteManager {
|
||||
return &SiteManager{
|
||||
sites: make(map[string]*config.SiteConfig),
|
||||
enhancer: content.NewDefaultEnhancer(contentClient, ""), // siteID will be set per operation
|
||||
devMode: devMode,
|
||||
contentClient: contentClient,
|
||||
authProvider: &engine.AuthProvider{Type: "mock"}, // default
|
||||
@@ -151,31 +148,11 @@ func (sm *SiteManager) EnhanceSite(siteID string) error {
|
||||
return fmt.Errorf("failed to create output directory %s: %w", outputPath, err)
|
||||
}
|
||||
|
||||
// Create enhancer with auth provider for this operation
|
||||
// Discovery disabled by default - developers should explicitly mark elements with class="insertr"
|
||||
discoveryConfig := config.DiscoveryConfig{
|
||||
Enabled: false, // Changed from true - respect developer intent
|
||||
Aggressive: false,
|
||||
Containers: true,
|
||||
Individual: true,
|
||||
}
|
||||
|
||||
// Override with site-specific discovery config if provided
|
||||
if site.Discovery != nil {
|
||||
discoveryConfig = *site.Discovery
|
||||
log.Printf("🔧 Using site-specific discovery config for %s: enabled=%v, aggressive=%v",
|
||||
siteID, discoveryConfig.Enabled, discoveryConfig.Aggressive)
|
||||
}
|
||||
|
||||
config := content.EnhancementConfig{
|
||||
Discovery: discoveryConfig,
|
||||
ContentInjection: true,
|
||||
GenerateIDs: true,
|
||||
}
|
||||
enhancer := content.NewEnhancerWithAuth(sm.contentClient, siteID, config, sm.authProvider)
|
||||
// Create content engine with auth provider for this operation
|
||||
contentEngine := engine.NewContentEngineWithAuth(sm.contentClient, sm.authProvider)
|
||||
|
||||
// Perform enhancement from source to output
|
||||
if err := enhancer.EnhanceDirectory(sourcePath, outputPath); err != nil {
|
||||
if err := contentEngine.ProcessDirectory(sourcePath, outputPath, siteID, engine.Enhancement); err != nil {
|
||||
return fmt.Errorf("failed to enhance site %s: %w", siteID, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user