@tola/head

Build HTML <head> metadata elements: title, description, canonical link, Open Graph, and Twitter cards.

Import

typst
#import "@tola/head:0.0.0": *

Each function returns an array of HTML elements; concatenate them with + and pass .join() into html.head(...).

Exports

head-metadata

typc
let head-metadata(
  site: dictionary,
  charset: none | string = "utf-8",
  description: auto | none | content | string = auto,
  title: auto | none | content | string = auto,
  viewport: none | string = "width=device-width, initial-scale=1",
) = array;

Return standard <meta charset>, viewport, <title>, and <meta name="description"> elements.

Positional parameters

  • site dictionary required: Site dictionary providing default title and description (usually site from @tola/site).

Named parameters

  • title auto | none | content | string default: auto: Page title. auto uses site.title; none or blank omits <title>.
  • description auto | none | content | string default: auto: Page description. auto uses site.description; none or blank omits the description tag.
  • charset none | string default: "utf-8": Character encoding, defaulting to "utf-8". Pass none or blank to omit.
  • viewport none | string default: "width=device-width, initial-scale=1": Viewport content, defaulting to "width=device-width, initial-scale=1". Pass none or blank to omit.

Compose complete HTML `<head>` metadata

typst
#import "@tola/head:0.0.0": canonical, head-metadata, open-graph, twitter-card
#import "@tola/site:0.0.0": site

#let url = "https://example.com/guide/"
#let cover = (url: "https://example.com/cover.png", alt: "Guide cover")
#let tags = (
  head-metadata(site, title: "Trail Guide", description: "Plan a day hike.")
  + canonical(url)
  + open-graph(title: "Trail Guide", url: url, images: (cover,))
  + twitter-card(card: "summary_large_image", title: "Trail Guide", image: cover)
)

#document("guide/index.html", title: "Trail Guide")[
  #html.html[
    #html.head(tags.join())
    #html.body[Trail Guide]
  ]
]

canonical

typc
let canonical(
  href: string,
) = array;

Return a <link rel="canonical"> element for the page’s canonical HTTP(S) URL.

Positional parameters

  • href string required: Absolute http:// or https:// URL for the current page.

open-graph

typc
let open-graph(
  description: none | string = none,
  images: none | array = none,
  kind: string = "website",
  locale: none | string = none,
  site-name: none | string = none,
  title: string = auto,
  url: string = auto,
) = array;

Return Open Graph <meta property="og:*"> elements for social link previews.

Named parameters

  • title string default: auto: Non-empty page title.
  • kind string default: "website": Open Graph type such as "website" (default) or "article".
  • url string default: auto: Absolute HTTP(S) page URL.
  • images none | array default: none: none to omit image tags, or a non-empty array of (url:, alt:) image dictionaries.
  • description none | string default: none: Optional summary written when non-empty.
  • site-name none | string default: none: Optional site name written when non-empty.
  • locale none | string default: none: Optional locale written when non-empty.

twitter-card

typc
let twitter-card(
  card: string = auto,
  creator: none | string = none,
  description: none | string = none,
  handle: none | string = none,
  image: none | dictionary = none,
  title: string = auto,
) = array;

Return Twitter Card <meta name="twitter:*"> elements for link previews.

Named parameters

  • card string default: auto: Card type: "summary" or "summary_large_image".
  • title string default: auto: Non-empty card title.
  • image none | dictionary default: none: Optional (url:, alt:) dictionary; required when card is "summary_large_image".
  • description none | string default: none: Optional description written when non-empty.
  • handle none | string default: none: Optional site account handle (twitter:site).
  • creator none | string default: none: Optional author account handle (twitter:creator).

Search this site

Use the arrow keys to move through results.

Type to search.