Skip to content

Releases: aafeher/go-microdata-extract

v0.12.0

Choose a tag to compare

@aafeher aafeher released this 10 May 10:51

What's Changed in v0.12.0

Added

  • ConfigError structured error type (Field string, Err error) — returned by Extract() before any network call when the Extractor is misconfigured (e.g. fetchTimeout is 0 without a custom HTTP client, or maxBodySize ≤ 0); supports errors.As and errors.Unwrap
  • Configuration getter methods: GetUserAgent() string, GetFetchTimeout() uint8, GetHTTPClient() *http.Client, GetMaxBodySize() int64, GetSyntaxes() []Syntax — allow callers to inspect the active configuration; GetSyntaxes() returns a copy to prevent external mutation
  • SetMaxBodySize(size int64) *Extractor — caps the number of bytes read from an HTTP response body via io.LimitReader; responses exceeding the limit are rejected with a FetchError; default is 10 MB
  • URL scheme validation at the start of Extract() — non-http/https schemes (e.g. javascript:, file:, data:) are rejected immediately with a FetchError before any HTTP client call
  • Relative URL resolution in ParseRDFahref, src, and resource attribute values are now resolved against the page base URL (the URL parameter was previously discarded)
  • Relative URL resolution in ParseMicroformatsu-* property values (href, src, data, action) are now resolved against the page base URL (the URL parameter was previously discarded)
  • Relative URL resolution in ParseJSONLD@id and url field values are now resolved against the page base URL (the URL parameter was previously discarded); resolution is applied recursively to nested objects and arrays
  • Package-level godoc: // Package extract … in extract.go and // Package extractor … in extractors/doc.go
  • Godoc comments added to previously undocumented public functions: ParseJSONLD, ParseW3CMicrodata, ParseMicroformats
  • New examples: getconfiguration, getxcards, sethttpclient, setmaxbodysize, getextractedjson
  • errorhandling example extended with a ConfigError scenario

Changed

  • API: extractor public functions renamed to consistent Parse* prefixJSONLDParseJSONLD, W3CMicrodataParseW3CMicrodata, RDFaParseRDFa, DublinCoreParseDublinCore, MicroformatsParseMicroformats; ParseOpenGraph and ParseXCards were already using this prefix
  • XCardsAudio.SecureURL is now resolved against the base URL in resolveXCardsURLs() — previously only URL was resolved; all other media types (XCardsImage, XCardsVideo, OpenGraphImage, OpenGraphVideo, OpenGraphAudio) already resolved both fields
  • Custom generic helpers contains[]/index[] replaced with stdlib slices.Contains/slices.Index (available since Go 1.21)
  • golang.org/x/net bumped to v0.54.0

Fixed

  • XCardsAudio.SecureURL was silently left unresolved — the only SecureURL field across all media types not passed through resolveURL

Full Changelog: v0.11.0...v0.12.0

v0.11.0

Choose a tag to compare

@aafeher aafeher released this 08 May 19:42

What's Changed in v0.11.0

Added

  • GetErrors() []error method on Extractor — exposes the accumulated parse errors from the last Extract() call; previously errs was a private field with no public getter
  • DefaultSyntaxes() []Syntax function — returns a fresh copy of the default syntax list; safe to iterate or pass to SetSyntaxes without risk of mutating the package-level default

Changed

  • Processor struct unexported to processor — it was only used internally by Extract() and was never intended as part of the public API
  • SYNTAXES exported variable replaced by unexported defaultSyntaxes; use DefaultSyntaxes() instead — the old var allowed callers to mutate the global default, causing subtle cross-call bugs
  • FillMissingFieldsFromOpenGraph in extractors/xcards.go unexported to fillMissingFieldsFromOpenGraph — it is an internal implementation detail of the XCards extractor; corresponding tests moved from extract_test.go to extractors/xcards_test.go

Full Changelog: v0.10.0...v0.11.0

v0.10.0

Choose a tag to compare

@aafeher aafeher released this 08 May 17:46

What's Changed in v0.10.0

Added

  • context.Context parameter as the first argument of Extract() — HTTP fetches now respect context cancellation and deadline; pass context.Background() for the previous behaviour
  • SetHTTPClient(client *http.Client) *Extractor — injects a fully custom HTTP client (enables proxy, mutual TLS, custom transport, auth headers); when set, the client's own timeout is used instead of fetchTimeout
  • FetchError structured error type (URL string, Err error) returned by Extract() on network or non-200 failures; supports errors.As and errors.Unwrap
  • ParseError structured error type (Syntax Syntax, Err error) wrapping every per-extractor error accumulated in Extractor.errs; supports errors.As and errors.Unwrap
  • httpClient *http.Client field added to internal config struct (zero value = use default client built from fetchTimeout)

Changed

  • API: Extract(url, content)Extract(ctx, url, content)context.Context is now the first parameter; all callers (examples, benchmarks, tests) updated
  • fetch() now uses http.NewRequestWithContext instead of http.NewRequest, propagating the caller's context to the HTTP layer
  • All errors returned from fetch() are now wrapped in *FetchError; callers can use errors.As(err, &FetchError{}) to check for fetch vs parse failures
  • Parse errors from extractor goroutines are now wrapped in *ParseError (tagged with the producing Syntax) before being appended to Extractor.errs
  • errorhandling example updated to demonstrate errors.As with *FetchError

Full Changelog: v0.9.0...v0.10.0

v0.9.0

Choose a tag to compare

@aafeher aafeher released this 08 May 16:59

What's Changed in v0.9.0

Changed

  • Extracted shared handleMediaSlice[T any] generic helper to extractors/shared.go — consolidates the slice-management boilerplate (append-or-reuse-last pattern) that was duplicated across all six media property handlers in opengraph.go and xcards.go
  • Extracted parseMusicProperty, parseVideoObjectProperty, parseArticleProperty, parseBookProperty, parseProfileProperty to extractors/shared.go — the five namespace-property switch blocks were identical between parseOpenGraphMetaTag and parseXCardsMetaTag
  • Moved handleMusicSongProperty, handleVideoActorProperty, parseIntSafely, parseTimeSafely to extractors/shared.go — these helpers are shared across multiple files and now live in a single authoritative location
  • handleOpenGraphImageProperty, handleOpenGraphVideoProperty, handleOpenGraphAudioProperty and their XCards counterparts are now thin wrappers over handleMediaSlice, reducing each handler to a format-specific field-assignment closure

Full Changelog: v0.8.0...v0.9.0

v0.8.0

Choose a tag to compare

@aafeher aafeher released this 07 May 18:41

What's Changed in v0.8.0

Added

  • RDFa error/edge-case test fixture (test/test-55-rdfa-errors.html) — HTML with no RDFa items and a dangling property attribute without a typeof parent; corresponding test-55-rdfa-errors test case added
  • Relative URL resolution test fixture (test/test-56-opengraph-relative-urls.html) with corresponding test-56-opengraph-relative-urls test case verifying path-relative URLs are resolved against the page base URL
  • resolveURL(base, ref string) string shared helper in extractors/w3cmicrodata.go using url.URL.ResolveReference (handles absolute, protocol-relative, and path-relative refs correctly)
  • resolveOpenGraphURLs in extractors/opengraph.go — resolves og:url, image/video/audio URL and SecureURL fields
  • resolveXCardsURLs in extractors/xcards.go — resolves twitter/og image/video/audio URL and SecureURL fields

Changed

  • API: ParseOpenGraph return type changed from (any, []error) to (*OpenGraph, []error); extract.go wrapper converts typed nil to untyped nil to preserve map semantics
  • API: ParseXCards return type changed from (any, []error) to (*XCards, []error); same nil handling in wrapper
  • API: DublinCore return type changed from (any, []error) to (*DublinCoreItem, []error); same nil handling in wrapper
  • JSONLD signature: unused named parameter URL string replaced with blank identifier _ string
  • DublinCore link href values are now resolved against the page URL (previously stored verbatim)
  • W3CMicrodata inline URL resolution replaced with shared resolveURL — protocol-relative URLs (//host/path) are now properly resolved to http://host/path; existing test updated (test-35-w3cmicrodata-book: discussionUrl value updated from //www.example.com/… to http://www.example.com/…)
  • parseDublinCore now accepts a URL parameter and handles html.Parse errors
  • parseMicroformats, parseRDFa, parseW3CMicrodata now handle html.Parse errors instead of discarding them

Fixed

  • Remove always-true dead condition if len(items) >= 0 in extractors/jsonld.go — simplified JSONLD() to return extractJSONLD() directly
  • Remove no-op nil→empty-slice init blocks in extractors/opengraph.gohandleOpenGraphImageProperty, handleOpenGraphVideoProperty, handleOpenGraphAudioProperty each had a redundant if len == 0 { slice = []T{} } block (Go's append works identically on nil and empty slices)

Full Changelog: v0.7.0...v0.8.0

v0.7.0

Choose a tag to compare

@aafeher aafeher released this 07 May 15:36

What's Changed in v0.7.0

Added

  • Benchmark tests (extract_bench_test.go) for all 7 formats: OpenGraph, X Cards, JSON-LD, W3C Microdata, RDFa, Dublin Core, and Microformats, plus a combined all-syntaxes benchmark
  • Performance section in README with benchmark results table and instructions for running benchmarks

Full Changelog: v0.6.0...v0.7.0

v0.6.0

Choose a tag to compare

@aafeher aafeher released this 06 May 19:23

What's Changed in v0.6.0

Added

  • Microformats2 extractor (extractors/microformats.go) supporting h-* root items, p-* (text), u-* (URL), dt-* (datetime), and e-* (embedded HTML) property prefixes
  • SyntaxMicroformats constant ("microformats") added to SYNTAXES and enabled by default
  • Nested item support: h-* child nodes used as both property values and Children entries
  • Add example: Microformats extraction with recursive nested item printing (examples/getmicroformats)

Changed

  • Default syntaxes list extended with SyntaxMicroformats
  • README: Microformats marked as supported in the formats table, default syntaxes updated

Full Changelog: v0.5.0...v0.6.0

v0.5.0

Choose a tag to compare

@aafeher aafeher released this 06 May 18:23

What's Changed in v0.5.0

Added

  • Dublin Core extractor (extractors/dublincore.go) supporting DC.* and DCTERMS.* prefixes in and attributes
  • SyntaxDublinCore constant ("dublincore") added to SYNTAXES and enabled by default
  • Add example: Dublin Core extraction with type assertion and multiple-value handling (examples/getdublincore)

Changed

  • Default syntaxes list extended with SyntaxDublinCore
  • README: Dublin Core marked as supported in the formats table, default syntaxes updated

Fixed

  • XCards extractor no longer falsely returns an empty struct when non-Twitter tags (e.g. Dublin Core, keywords) are present; xcHasValue is now only set for recognized twitter:, og:, music:, video:, article:, book:, or profile: prefixes

Full Changelog: v0.4.0...v0.5.0

v0.4.0

Choose a tag to compare

@aafeher aafeher released this 05 May 18:46

What's Changed in v0.4.0

Added

  • RDFa support (extractors/rdfa.go) — 38.9% web usage
    • vocab and typeof attributes for typed items
    • property attribute for named properties
    • prefix attribute with CURIE resolution (e.g. schema:Personhttps://schema.org/Person)
    • resource and about attributes for subject URIs
    • Nested items (property + typeof on the same element)
    • Sibling items (typeof-only inside an item's subtree)
    • Property value resolution priority: contentdatetimehrefsrcresource → text content
  • SyntaxRDFa constant ("rdfa") — enabled by default alongside the existing four syntaxes
  • Add example: RDFa extraction with type assertion and nested items (examples/getrdfa)

Changed

  • Default syntaxes list extended with SyntaxRDFa
  • README: RDFa marked as supported in the formats table, default syntaxes updated

Full Changelog: v0.3.0...v0.4.0

v0.3.0

Choose a tag to compare

@aafeher aafeher released this 05 May 17:17

What's Changed in v0.3.0

Added

  • Add example: raw HTML content provided directly without HTTP fetch (examples/rawcontent)
  • Add example: error handling for fetch failures and missing syntax data (examples/errorhandling)
  • Add example: JSON-LD extraction with type assertion and nested field access (examples/getjsonld)
  • Add example: W3C Microdata extraction with type assertion and nested items (examples/getmicrodata)

Full Changelog: v0.2.0...v0.3.0