Major codebase cleanup after .insertr-add functionality overhaul
Consolidates duplicate code and removes technical debt accumulated during rapid development. This cleanup improves maintainability while preserving all functionality. Backend cleanup: - Remove unused legacy function findViableChildrenLegacy() - Consolidate duplicate SQL null string helper functions into shared utils - Unify text extraction functions across utils, engine, and id_generator - Consolidate duplicate attribute getter functions into single implementation Frontend cleanup: - Remove duplicate authentication methods (authenticateWithOAuth vs performOAuthFlow) - Remove unused hasPermission() method from auth.js - Centralize repetitive API endpoint construction in api-client.js - Reduce excessive console logging while preserving important error logs Impact: -144 lines of code, improved maintainability, no functionality changes All tests pass and builds succeed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -330,7 +330,7 @@ func (g *IDGenerator) getParentContainerContext(node *html.Node) string {
|
||||
|
||||
for current != nil && current.Type == html.ElementNode && depth < 3 {
|
||||
// Check for ID attribute (most unique)
|
||||
if id := g.getAttribute(current, "id"); id != "" {
|
||||
if id := GetAttribute(current, "id"); id != "" {
|
||||
return "id:" + id
|
||||
}
|
||||
|
||||
@@ -367,9 +367,7 @@ func (g *IDGenerator) getSiblingContext(node *html.Node) string {
|
||||
tag := strings.ToLower(sibling.Data)
|
||||
// Check for heading elements
|
||||
if tag == "h1" || tag == "h2" || tag == "h3" || tag == "h4" || tag == "h5" || tag == "h6" {
|
||||
var text strings.Builder
|
||||
g.extractTextContent(sibling, &text)
|
||||
content := strings.TrimSpace(text.String())
|
||||
content := ExtractTextContent(sibling)
|
||||
if content != "" && len(content) > 3 {
|
||||
// Return first 12 chars for uniqueness
|
||||
if len(content) > 12 {
|
||||
@@ -391,9 +389,7 @@ func (g *IDGenerator) getParentUniqueText(parent *html.Node) string {
|
||||
tag := strings.ToLower(child.Data)
|
||||
// Look for heading elements or elements with distinctive text
|
||||
if tag == "h1" || tag == "h2" || tag == "h3" || tag == "h4" || tag == "h5" || tag == "h6" {
|
||||
var text strings.Builder
|
||||
g.extractTextContent(child, &text)
|
||||
content := strings.TrimSpace(text.String())
|
||||
content := ExtractTextContent(child)
|
||||
if content != "" && len(content) > 2 {
|
||||
// Return first 15 chars of heading text for uniqueness
|
||||
if len(content) > 15 {
|
||||
@@ -407,21 +403,10 @@ func (g *IDGenerator) getParentUniqueText(parent *html.Node) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// getAttribute safely gets an attribute value from a node
|
||||
func (g *IDGenerator) getAttribute(node *html.Node, attrName string) string {
|
||||
for _, attr := range node.Attr {
|
||||
if attr.Key == attrName {
|
||||
return attr.Val
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// getContentPreview extracts first 50 characters of text content for uniqueness
|
||||
func (g *IDGenerator) getContentPreview(node *html.Node) string {
|
||||
var text strings.Builder
|
||||
g.extractTextContent(node, &text)
|
||||
content := strings.TrimSpace(text.String())
|
||||
content := ExtractTextContent(node)
|
||||
if len(content) > 50 {
|
||||
content = content[:50]
|
||||
}
|
||||
@@ -434,15 +419,6 @@ func (g *IDGenerator) getContentPreview(node *html.Node) string {
|
||||
return content
|
||||
}
|
||||
|
||||
// extractTextContent recursively extracts text content from a node
|
||||
func (g *IDGenerator) extractTextContent(node *html.Node, text *strings.Builder) {
|
||||
if node.Type == html.TextNode {
|
||||
text.WriteString(node.Data)
|
||||
}
|
||||
for child := node.FirstChild; child != nil; child = child.NextSibling {
|
||||
g.extractTextContent(child, text)
|
||||
}
|
||||
}
|
||||
|
||||
// getSiblingIndex returns the position of this element among its siblings of the same type and class
|
||||
func (g *IDGenerator) getSiblingIndex(node *html.Node) int {
|
||||
|
||||
Reference in New Issue
Block a user