Manual code review by an actual human.
This commit is contained in:
@@ -220,13 +220,12 @@ func (e *ContentEngine) hasInsertrAddClass(node *html.Node) bool {
|
||||
}
|
||||
|
||||
// addContentAttributes adds data-content-id attribute only
|
||||
// HTML-first approach: no content-type attribute needed
|
||||
func (e *ContentEngine) addContentAttributes(node *html.Node, contentID string) {
|
||||
// Add data-content-id attribute
|
||||
e.setAttribute(node, "data-content-id", contentID)
|
||||
}
|
||||
|
||||
// setAttribute sets an attribute on an HTML node
|
||||
// setAttribute sets an attribute on a HTML node
|
||||
func (e *ContentEngine) setAttribute(node *html.Node, key, value string) {
|
||||
// Remove existing attribute if it exists
|
||||
for i, attr := range node.Attr {
|
||||
@@ -262,10 +261,8 @@ func (e *ContentEngine) addClass(node *html.Node, className string) {
|
||||
}
|
||||
|
||||
// Check if class already exists
|
||||
for _, class := range classes {
|
||||
if class == className {
|
||||
return // Class already exists
|
||||
}
|
||||
if slices.Contains(classes, className) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add new class
|
||||
@@ -314,7 +311,7 @@ func (e *ContentEngine) removeClass(node *html.Node, className string) {
|
||||
// Update or remove class attribute
|
||||
if len(newClasses) == 0 {
|
||||
// Remove class attribute entirely if no classes remain
|
||||
node.Attr = append(node.Attr[:classIndex], node.Attr[classIndex+1:]...)
|
||||
node.Attr = slices.Delete(node.Attr, classIndex, classIndex+1)
|
||||
} else {
|
||||
// Update class attribute with remaining classes
|
||||
node.Attr[classIndex].Val = strings.Join(newClasses, " ")
|
||||
@@ -338,6 +335,7 @@ func (e *ContentEngine) injectContent(elements []ProcessedElement, siteID string
|
||||
elem.Content = contentItem.HTMLContent
|
||||
|
||||
// Update injector siteID for this operation
|
||||
// HACK: I do not like this. Injector refactor?
|
||||
e.injector.siteID = siteID
|
||||
e.injector.injectHTMLContent(elem.Node, contentItem.HTMLContent)
|
||||
}
|
||||
@@ -360,6 +358,7 @@ func (e *ContentEngine) extractHTMLContent(node *html.Node) string {
|
||||
}
|
||||
|
||||
// extractOriginalTemplate extracts the outer HTML of the element (including the element itself)
|
||||
// HACK: Rename
|
||||
func (e *ContentEngine) extractOriginalTemplate(node *html.Node) string {
|
||||
var buf strings.Builder
|
||||
if err := html.Render(&buf, node); err != nil {
|
||||
@@ -418,10 +417,8 @@ func (e *ContentEngine) hasClass(n *html.Node, className string) bool {
|
||||
for _, attr := range n.Attr {
|
||||
if attr.Key == "class" {
|
||||
classes := strings.Fields(attr.Val)
|
||||
for _, class := range classes {
|
||||
if class == className {
|
||||
return true
|
||||
}
|
||||
if slices.Contains(classes, className) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user