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:
@@ -243,15 +243,6 @@ func (e *ContentEngine) addContentAttributes(node *html.Node, contentID string)
|
||||
e.setAttribute(node, "data-content-id", contentID)
|
||||
}
|
||||
|
||||
// getAttribute gets an attribute value from an HTML node
|
||||
func (e *ContentEngine) getAttribute(node *html.Node, key string) string {
|
||||
for _, attr := range node.Attr {
|
||||
if attr.Key == key {
|
||||
return attr.Val
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// setAttribute sets an attribute on an HTML node
|
||||
func (e *ContentEngine) setAttribute(node *html.Node, key, value string) {
|
||||
@@ -386,29 +377,7 @@ func (e *ContentEngine) extractHTMLContent(node *html.Node) string {
|
||||
return strings.TrimSpace(content.String())
|
||||
}
|
||||
|
||||
// extractTextContent extracts only the text content from a node (for individual content storage)
|
||||
func (e *ContentEngine) extractTextContent(node *html.Node) string {
|
||||
var text strings.Builder
|
||||
|
||||
// Walk through all text nodes to extract content
|
||||
e.walkNodes(node, func(n *html.Node) {
|
||||
if n.Type == html.TextNode {
|
||||
text.WriteString(n.Data)
|
||||
}
|
||||
})
|
||||
|
||||
return strings.TrimSpace(text.String())
|
||||
}
|
||||
|
||||
// getAttributeValue gets an attribute value from an HTML node
|
||||
func (e *ContentEngine) getAttributeValue(n *html.Node, attrKey string) string {
|
||||
for _, attr := range n.Attr {
|
||||
if attr.Key == attrKey {
|
||||
return attr.Val
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// extractOriginalTemplate extracts the outer HTML of the element (including the element itself)
|
||||
func (e *ContentEngine) extractOriginalTemplate(node *html.Node) string {
|
||||
@@ -634,7 +603,7 @@ func (e *ContentEngine) reconstructCollectionItems(collectionNode *html.Node, co
|
||||
e.walkNodes(structuralBody, func(n *html.Node) {
|
||||
if n.Type == html.ElementNode && e.hasClass(n, "insertr") {
|
||||
// Get content ID from data attribute
|
||||
contentID := e.getAttributeValue(n, "data-content-id")
|
||||
contentID := GetAttribute(n, "data-content-id")
|
||||
if contentID != "" {
|
||||
// Use Injector to hydrate content (unified .insertr approach)
|
||||
element := &Element{Node: n, Type: "html"}
|
||||
@@ -672,7 +641,7 @@ func (e *ContentEngine) processChildElementsAsContent(childElement *html.Node, s
|
||||
contentID := e.idGenerator.Generate(n, "collection-item")
|
||||
|
||||
// Extract actual content from the element
|
||||
actualContent := e.extractTextContent(n)
|
||||
actualContent := ExtractTextContent(n)
|
||||
|
||||
// Store as individual content entry (unified .insertr approach)
|
||||
_, err := e.client.CreateContent(siteID, contentID, actualContent, "", "system")
|
||||
|
||||
Reference in New Issue
Block a user