Sean Missingham
2024-07-01 f7bd2137ecbb81f3ed50ae9ccaaee27ae855c11a
quartz/components/renderPage.tsx
@@ -19,6 +19,7 @@
  footer: QuartzComponent
}
const headerRegex = new RegExp(/h[1-6]/)
export function pageResources(
  baseDir: FullSlug | RelativeURL,
  staticResources: StaticResources,
@@ -105,18 +106,24 @@
          // header transclude
          blockRef = blockRef.slice(1)
          let startIdx = undefined
          let startDepth = undefined
          let endIdx = undefined
          for (const [i, el] of page.htmlAst.children.entries()) {
            if (el.type === "element" && el.tagName.match(/h[1-6]/)) {
              if (endIdx) {
                break
              }
            // skip non-headers
            if (!(el.type === "element" && el.tagName.match(headerRegex))) continue
            const depth = Number(el.tagName.substring(1))
              if (startIdx !== undefined) {
                endIdx = i
              } else if (el.properties?.id === blockRef) {
            // lookin for our blockref
            if (startIdx === undefined || startDepth === undefined) {
              // skip until we find the blockref that matches
              if (el.properties?.id === blockRef) {
                startIdx = i
                startDepth = depth
              }
            } else if (depth <= startDepth) {
              // looking for new header that is same level or higher
              endIdx = i
              break
            }
          }
@@ -203,7 +210,7 @@
    </div>
  )
  const lang = componentData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
  const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
  const doc = (
    <html lang={lang}>
      <Head {...componentData} />