Skip to main content

remove_canonical_links

Function remove_canonical_links 

Source
pub fn remove_canonical_links(html: &str) -> String
Expand description

Removes every <link rel~="canonical"> element from the document.

Uses the link[rel~="canonical" i] selector so any attribute order or quoting is handled by the parser, including rel="canonical other-token" (the space-separated token set match). Literal <link rel="canonical"> text embedded inside a <pre> / <code> block or an HTML comment is left untouched because lol_html only dispatches on real elements.

ยงExamples

use ssg::util::head_dom::remove_canonical_links;
let html = r#"<head><link rel="canonical" href="/old"></head>"#;
let out = remove_canonical_links(html);
assert!(!out.contains("canonical"));