defmodule SchemaOrg do @moduledoc """ Strictly-typed builder for Schema.org JSON-LD. Each Schema.org Class is a generated struct module under `SchemaOrg.*` (e.g. `SchemaOrg.Product`, `SchemaOrg.Offer`). Build a graph with ordinary struct literals — your editor auto-completes the valid fields and the compiler rejects the rest — then serialise it with `to_json_ld/1`. %SchemaOrg.Product{ name: "MacBook Pro", offers: %SchemaOrg.Offer{price: 1999.0} } |> SchemaOrg.to_map() #=> %{ # "@type" => "Product", # "name" => "MacBook Pro", # "offers" => %{"@type" => "Offer", "price" => 1999.0} # } A property field is untyped, so it accepts Schema.org's loose value model directly: a scalar or a nested struct (`brand: "Apple"` or `brand: %SchemaOrg.Brand{}`), and a single value or a list (`offers: %SchemaOrg.Offer{}` or `offers: [%SchemaOrg.Offer{}, ...]`). ## Multiple top-level nodes (`@graph`) Pass a **list** of structs to describe several independent nodes in one document (e.g. a landing page's `Organization`, `WebSite`, and `BreadcrumbList`). They are emitted under a single top-level `@graph`: [%SchemaOrg.Organization{name: "Acme"}, %SchemaOrg.WebSite{name: "Acme"}] |> SchemaOrg.to_json_ld() #=> {"@context":"https://schema.org","@graph":[{...},{...}]} ## Embedding in a page `to_script_tag/1` returns an HTML-safe `` (or `