feat: Implement syntactic sugar and site-specific discovery config
- Add syntactic sugar for container transformation: .insertr containers → children get .insertr - Fix discovery auto-running when disabled with site-specific config loading - Add comprehensive styling test examples for HTML attribute preservation - Include test input for syntactic sugar validation - Update discovery defaults to respect developer intent (disabled by default)
This commit is contained in:
@@ -90,6 +90,7 @@ type FileDiscoveryResult struct {
|
||||
ElementsEnhanced int
|
||||
ContainersAdded int
|
||||
IndividualsAdded int
|
||||
SugarTransformed int // Count of syntactic sugar transformations
|
||||
Document *html.Node
|
||||
}
|
||||
|
||||
@@ -124,7 +125,30 @@ func (disc *Discoverer) discoverNode(node *html.Node, result *FileDiscoveryResul
|
||||
return
|
||||
}
|
||||
|
||||
// Skip if already has insertr class
|
||||
// Handle syntactic sugar: containers with .insertr class
|
||||
if disc.hasInsertrClass(node) && disc.isGoodContainer(node) {
|
||||
// Syntactic sugar transformation: remove .insertr from container, add to viable children
|
||||
viableChildren := engine.FindViableChildren(node)
|
||||
if len(viableChildren) >= 1 {
|
||||
disc.removeInsertrClass(node) // Remove from container
|
||||
for _, child := range viableChildren {
|
||||
if !disc.hasInsertrClass(child) {
|
||||
disc.addInsertrClass(child)
|
||||
result.IndividualsAdded++
|
||||
result.ElementsEnhanced++
|
||||
}
|
||||
}
|
||||
result.ContainersAdded++
|
||||
result.SugarTransformed++ // Track sugar transformations
|
||||
|
||||
// Don't process children since we just processed them
|
||||
return
|
||||
}
|
||||
// If no viable children, leave .insertr on the element (individual editing)
|
||||
return
|
||||
}
|
||||
|
||||
// Skip if already has insertr class (individual editing elements)
|
||||
if disc.hasInsertrClass(node) {
|
||||
return
|
||||
}
|
||||
@@ -258,6 +282,18 @@ func (disc *Discoverer) addInsertrClass(node *html.Node) {
|
||||
disc.setClasses(node, classes)
|
||||
}
|
||||
|
||||
// removeInsertrClass removes the insertr class from a node
|
||||
func (disc *Discoverer) removeInsertrClass(node *html.Node) {
|
||||
classes := disc.getClasses(node)
|
||||
var filteredClasses []string
|
||||
for _, class := range classes {
|
||||
if class != "insertr" {
|
||||
filteredClasses = append(filteredClasses, class)
|
||||
}
|
||||
}
|
||||
disc.setClasses(node, filteredClasses)
|
||||
}
|
||||
|
||||
// getClasses extracts CSS classes from a node
|
||||
func (disc *Discoverer) getClasses(node *html.Node) []string {
|
||||
for i, attr := range node.Attr {
|
||||
|
||||
@@ -13,11 +13,12 @@ import (
|
||||
|
||||
// SiteConfig represents configuration for a registered site
|
||||
type SiteConfig struct {
|
||||
SiteID string `yaml:"site_id"`
|
||||
Path string `yaml:"path"` // Served path (enhanced output)
|
||||
SourcePath string `yaml:"source_path"` // Source path (for enhancement)
|
||||
Domain string `yaml:"domain,omitempty"`
|
||||
AutoEnhance bool `yaml:"auto_enhance"`
|
||||
SiteID string `yaml:"site_id"`
|
||||
Path string `yaml:"path"` // Served path (enhanced output)
|
||||
SourcePath string `yaml:"source_path"` // Source path (for enhancement)
|
||||
Domain string `yaml:"domain,omitempty"`
|
||||
AutoEnhance bool `yaml:"auto_enhance"`
|
||||
Discovery *DiscoveryConfig `yaml:"discovery,omitempty"` // Override discovery settings
|
||||
}
|
||||
|
||||
// SiteManager handles registration and enhancement of static sites
|
||||
@@ -159,17 +160,27 @@ func (sm *SiteManager) EnhanceSite(siteID string) error {
|
||||
}
|
||||
|
||||
// Create enhancer with auth provider for this operation
|
||||
defaultConfig := EnhancementConfig{
|
||||
Discovery: DiscoveryConfig{
|
||||
Enabled: true,
|
||||
Aggressive: false,
|
||||
Containers: true,
|
||||
Individual: true,
|
||||
},
|
||||
// Discovery disabled by default - developers should explicitly mark elements with class="insertr"
|
||||
discoveryConfig := 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 := EnhancementConfig{
|
||||
Discovery: discoveryConfig,
|
||||
ContentInjection: true,
|
||||
GenerateIDs: true,
|
||||
}
|
||||
enhancer := NewEnhancerWithAuth(sm.contentClient, siteID, defaultConfig, sm.authProvider)
|
||||
enhancer := NewEnhancerWithAuth(sm.contentClient, siteID, config, sm.authProvider)
|
||||
|
||||
// Perform enhancement from source to output
|
||||
if err := enhancer.EnhanceDirectory(sourcePath, outputPath); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user