From 0bad96d86664278a0bf15d3a5b7fb2c5ebf396d0 Mon Sep 17 00:00:00 2001 From: Joakim Date: Sun, 26 Oct 2025 21:45:03 +0100 Subject: [PATCH] Fix collection content injection regression introduced during engine refactoring Restore missing content hydration logic in reconstructCollectionItems method that was accidentally removed during the engine file split (b46f643). Collection items were appearing empty instead of displaying original developer content. This fix restores the database-first behavior where content is properly extracted, stored, and injected back into .insertr elements within collection items. --- insertr.yaml | 2 +- internal/engine/collection.go | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/insertr.yaml b/insertr.yaml index 7df2f2b..3ce48f6 100644 --- a/insertr.yaml +++ b/insertr.yaml @@ -15,7 +15,7 @@ server: - site_id: "blog" path: "./demos/blog_enhanced" source_path: "./demos/blog/" - auto_enhance: false + auto_enhance: true - site_id: "default" path: "./demos/default_enhanced" source_path: "./demos/default" diff --git a/internal/engine/collection.go b/internal/engine/collection.go index 94dcaf7..a79fe74 100644 --- a/internal/engine/collection.go +++ b/internal/engine/collection.go @@ -174,8 +174,23 @@ func (e *ContentEngine) reconstructCollectionItems(collectionNode *html.Node, co structuralChild.Parent.RemoveChild(structuralChild) } - // Add hydrated structural elements directly to collection (stored HTML has complete structure) - // The structural template already contains hydrated content from database + // RESTORED: Inject content into .insertr elements within collection items + // Walk through structural elements and hydrate with content from content table + e.walkNodes(structuralChild, func(n *html.Node) { + if n.Type == html.ElementNode && HasClass(n, "insertr") { + // Get content ID from data attribute + contentID := GetAttribute(n, "data-content-id") + if contentID != "" { + // Get actual content from database and inject it + contentItem, err := e.client.GetContent(context.Background(), siteID, contentID) + if err == nil && contentItem != nil { + // Use injector to hydrate content (unified .insertr approach) + e.injector.siteID = siteID + e.injector.injectHTMLContent(n, contentItem.HTMLContent) + } + } + } + }) // Inject data-item-id attribute for collection item identification if structuralChild.Type == html.ElementNode {