Skip to main content

inject_before_head_close

Function inject_before_head_close 

Source
pub fn inject_before_head_close(html: &str, payload: &str) -> String
Expand description

Inserts payload immediately before the real </head> end-tag.

Returns the input unchanged when no <head> element exists or when the underlying lol_html rewrite fails (allocation exhaustion is the only documented failure mode). payload is treated as raw HTML so callers retain control over tag construction; callers that need escaping must do so themselves.

Idempotency is the caller’s responsibility — this helper inserts unconditionally and will append a second payload on a second call.

§Examples

use ssg::util::head_dom::inject_before_head_close;
let html = "<html><head><title>T</title></head><body></body></html>";
let out = inject_before_head_close(html, "<meta name=\"x\">");
assert!(out.contains("<meta name=\"x\"></head>"));