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)
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)
}