Skip to main content

Module head_dom

Module head_dom 

Source
Expand description

Parser-driven helpers for HTML <head> manipulation.

Replaces the previous str::find / str::replace patterns scattered across the SEO, og_image, llm, ai, i18n, highlight, sbom, atom, json_feed, and jsonld plugins (issues #538, #539, #540).

Three operations are exposed:

  • inject_before_head_close — append a payload immediately before the real </head> end-tag, never inside a <pre> / <code> / comment / <script> template that happens to contain the literal </head> string.
  • extract_head_meta — single lol_html walk that pulls the document <title>, the <html lang> attribute, and the existing <link rel="canonical"> href in one pass.
  • remove_canonical_links — strip every <link rel~="canonical"> in <head> without disturbing non-canonical <link> elements or matching literals embedded in <pre> blocks.

All three guard against the standard str::find failure modes: comments containing the literal markup, <pre> / <code> samples that quote the same tag, attribute order and quoting variants, and multiple matches in body content.

Structs§

HeadMeta
Metadata extracted from the document <head> in a single parser walk.

Functions§

extract_head_meta
Extracts {title, lang, canonical} from html in a single lol_html pass.
inject_before_head_close
Inserts payload immediately before the real </head> end-tag.
remove_canonical_links
Removes every <link rel~="canonical"> element from the document.
replace_canonical_link
Replaces every existing <link rel~="canonical"> with a single payload injected just before </head>, in one parser pass.