Documentation
¶
Overview ¶
Package structured extracts the machine-readable data pages already publish for SEO and social embeds — JSON-LD, OpenGraph and microdata — as pure functions over the HTML.
Embedded structured data is usually the most drift-resistant thing on a page: sites break their CSS classes weekly and their schema.org markup almost never, because search ranking depends on it. Use these extractors as the sturdy rung of a fallback strategy, or as a cross-check on selector-based extraction.
Everything here follows quarry's determinism rules: no network, no clock, and no URL resolution (relative URLs are returned as written — a base URL is external state). Output shapes are uniform maps and slices rather than typed structs, preserving whatever the page declared; order is document order throughout.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONLD ¶
JSONLD returns every JSON-LD object embedded in <script type="application/ld+json"> blocks, in document order. A block holding a top-level array contributes each object element; @graph containers are returned intact for the caller to unpack.
Malformed blocks are common in the wild, so parsing is lenient per block: unparseable blocks are skipped, every block that parses is returned, and a non-nil joined error names what was dropped. Callers may ignore the error and use the items — the drop is loud, not fatal. Legacy HTML comment wrappers (<!-- ... -->) inside a block are stripped before parsing.
func OpenGraph ¶
OpenGraph returns the page's og:* meta properties, keyed by full property name ("og:title", "og:image:width", ...), with repeated properties preserved in document order — og:image legitimately appears once per image, and a flat map[string]string would silently drop all but one.
Properties are read from <meta property="og:..."> and, because real sites get this wrong (go.dev among them), from <meta name="og:..."> too; when both attributes are present, property wins. Content values are returned exactly as written, including empty strings — this is a syntax extractor, and deciding that an empty og:title is unusable is the caller's (or a fallback chain's) job.
Types ¶
type Item ¶
type Item struct {
// Types holds the itemtype tokens (usually schema.org URLs).
Types []string
// ID is the itemid value, as written (not resolved).
ID string
// Properties maps each itemprop name to its values in document
// order. A value is a string, or a *Item for nested itemscopes.
Properties map[string][]any
}
Item is one HTML microdata item: an element carrying itemscope.
func Microdata ¶
Microdata returns the document's top-level microdata items (elements with itemscope but no itemprop), in document order.
Property values follow the HTML microdata algorithm: meta reads content; img/audio/video/embed/iframe/source/track read src; a, area and link read href; object reads data; data and meter read value; time reads datetime (falling back to its text); anything else contributes its trimmed text content. URL-valued properties are returned as written, unresolved. A space-separated itemprop contributes its value under each name. The itemref attribute is not supported (rare in the wild, and it breaks the tree-shaped model); such properties are simply not collected.