smarana 0.10.13

An extensible note taking system for typst.
// Appendix — Tag Index Pages
// Auto-generated pages listing all notes for each tag

#import "theme.typ": palettes

#let make-tag-slug(tag) = {
  let slug = tag.replace(regex("[^a-zA-Z0-9]+"), "-").trim("-")
  if slug == "" { "untitled" } else { slug }
}

// Renders a single tag index page
// tag: the tag name string
// notes: array of (title, label-slug) pairs
#let tag-index-page(tag, notes, theme-mode: "dark") = {
  let colors = palettes.at(theme-mode).appendix

  page(
    fill: colors.outer,
    margin: 1.2cm,
    height: auto,
    {
      set text(
        size: 11pt,
        fill: colors.text,
      )

      show ref: it => {
        let make-styled(c) = text(fill: colors.accent, strong(c))

        if it.supplement != auto and it.supplement != none {
          link(it.target, make-styled(it.supplement))
        } else if it.element != none and it.element.func() == heading {
          link(it.target, make-styled(it.element.body))
        } else {
          it
        }
      }

show line: it => {
        if it.length == 30pt {
          line(length: 100%, stroke: 1pt + colors.line)
        } else {
          it
        }
      }

      // Hidden heading for label target (tag page anchor)
      set heading(numbering: "1.1")
      show heading: it => {
        if it.level >= 10 {
          box(width: 0pt, height: 0pt, clip: true, it)
        } else {
          it.body
        }
      }

      // Anchor label for this tag page
      let tag-slug = make-tag-slug(tag)
      [#heading(level: 10)[#tag] #label("tag-" + tag-slug)]

      // Header
      block(width: 100%, {
        grid(
          columns: (1fr, auto),
          align: (left + horizon, right + horizon),
          text(size: 10pt, fill: colors.meta, raw("TAG INDEX", lang: "no-box")),
          box(
            fill: colors.tag-bg,
            radius: 4pt,
            inset: (x: 6pt, y: 2pt),
            text(size:10pt, weight: "bold", fill: colors.accent, raw("APPENDIX", lang: "no-box")),
          )
        )
        v(2pt)

        text(size: 20pt, weight: "bold", fill: colors.text, raw("#" + tag, lang: "no-box"))
      })

      v(6pt)
      line(length: 100%, stroke: 1pt + colors.line)
      v(6pt)

      // Note list — clean grid style
      set text(fill: colors.text)
      grid(
        columns: (1fr, 1fr, 1fr),
        gutter: 8pt,
        ..notes.map(note => {
          let (title, slug) = note
          link(label(slug), block(
            width: 100%,
            fill: colors.tag-bg,
            radius: 2pt,
            inset: (x: 8pt, y: 6pt),
            stroke: (left: 2pt + colors.accent),
            {
              text(size: 9pt, weight: "medium", fill: colors.text, title)
            }
          ))
        })
      )
    }
  )
}