When using this it works fine, unless we have a empty heading (level 1), when on the page with the empty heading it puts the header of the title, when it should be leaving it empty, once I fill the heading with some text, the issue goes away.
#let getHeader() = {
locate(loc => {
let chapter = hydra(
sel: heading.where(level: 1),
display: (_, it) => {
it.body
},
loc: loc,
)
let section = hydra(
display: (context, element) => element.body,
loc: loc,
)
return [
#set text(size: 10pt)
#if section != none and chapter != none and section != chapter {
smallcaps(chapter); h(1fr); emph(section)
line(stroke: gradient.linear(black, gray) + .5pt,length: 100%)
} else if chapter != none {
align(center, smallcaps(chapter))
line(stroke: gradient.linear(gray, black).repeat(2, mirror: true) + .5pt, length: 100%)
} else {
[#line(length: 100%, stroke: .25pt)]
}
]
})
}```