Skip to main content

generate_structured_data_from_doc

Function generate_structured_data_from_doc 

Source
pub fn generate_structured_data_from_doc(
    document: &Html,
    config: Option<StructuredDataConfig>,
) -> Result<String>
Expand description

Generates structured data from a pre-parsed DOM tree.

This avoids redundant parsing when the pipeline has already parsed the HTML for other steps.

§Examples

use html_generator::seo::generate_structured_data_from_doc;
use scraper::Html;

let doc = Html::parse_document(
    "<html><head><title>Hi</title></head><body><p>Body</p></body></html>",
);
let json_ld = generate_structured_data_from_doc(&doc, None).unwrap();
assert!(json_ld.contains("application/ld+json"));

§Errors

Same as generate_structured_data: missing title/description, failed config validation, or JSON serialization failure.