create header and footer only when needed

master
magical 2021-11-16 06:22:51 +00:00
parent 406008135f
commit 4b4b875f34
1 changed files with 10 additions and 8 deletions

View File

@ -93,28 +93,30 @@ func merge(base, doc *html.Node) (out *html.Node) {
footer := findRec(body, atom.Footer) footer := findRec(body, atom.Footer)
main := findRec(body, atom.Main) main := findRec(body, atom.Main)
if header == nil { // TODO: merge attributes
header = createElement(atom.Header)
body.InsertBefore(header, body.FirstChild)
}
for { for {
n := findRec(newBody, atom.Header) n := findRec(newBody, atom.Header)
if n == nil { if n == nil {
break break
} }
if header == nil {
header = createElement(atom.Header)
body.InsertBefore(header, body.FirstChild)
}
reparentChildren(header, n) reparentChildren(header, n)
n.Parent.RemoveChild(n) n.Parent.RemoveChild(n)
} }
if footer == nil {
footer = createElement(atom.Header)
body.InsertBefore(footer, body.FirstChild)
}
for { for {
n := findRec(newBody, atom.Footer) n := findRec(newBody, atom.Footer)
if n == nil { if n == nil {
break break
} }
if footer == nil {
footer = createElement(atom.Header)
body.InsertBefore(footer, body.FirstChild)
}
reparentChildren(footer, n) reparentChildren(footer, n)
n.Parent.RemoveChild(n) n.Parent.RemoveChild(n)
} }