From 4b4b875f34c9f72c83794f52ffd9767bf02c7b62 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Tue, 16 Nov 2021 06:22:51 +0000 Subject: [PATCH] create header and footer only when needed --- internal/merge.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/merge.go b/internal/merge.go index e4ae80b..5c98061 100644 --- a/internal/merge.go +++ b/internal/merge.go @@ -93,28 +93,30 @@ func merge(base, doc *html.Node) (out *html.Node) { footer := findRec(body, atom.Footer) main := findRec(body, atom.Main) - if header == nil { - header = createElement(atom.Header) - body.InsertBefore(header, body.FirstChild) - } + // TODO: merge attributes + for { n := findRec(newBody, atom.Header) if n == nil { break } + if header == nil { + header = createElement(atom.Header) + body.InsertBefore(header, body.FirstChild) + } reparentChildren(header, n) n.Parent.RemoveChild(n) } - if footer == nil { - footer = createElement(atom.Header) - body.InsertBefore(footer, body.FirstChild) - } for { n := findRec(newBody, atom.Footer) if n == nil { break } + if footer == nil { + footer = createElement(atom.Header) + body.InsertBefore(footer, body.FirstChild) + } reparentChildren(footer, n) n.Parent.RemoveChild(n) }