Sitemap::Grammar::LinkExtract
NAME
Sitemap::Grammar::LinkExtract - Extract links from HTML
SYNOPSIS
use Sitemap::Grammar::LinkExtract;
my @links = Sitemap::Grammar::LinkExtract.extract($html, $base-url);
my @images = Sitemap::Grammar::LinkExtract.extract-images($html, $base-url);
my @hreflang = Sitemap::Grammar::LinkExtract.extract-hreflang-links($html, $base-url);
FUNCTIONS
extract(Str $html, Str $base = '' --> List)
Extract all href values from anchor tags in HTML. Returns a list of URLs.
extract-with-text(Str $html, Str $base = '' --> List)
Extract links with their link text. Returns a list of hashrefs with 'url' and 'text' keys.
extract-href-only(Str $html --> List)
Fast extraction of just href attributes using regex. Returns URLs only.
extract-images(Str $html, Str $base = '' --> List)
Extract image URLs from HTML. Searches img src, picture/source srcset, and og:image meta tags. Returns a deduplicated list of image URLs. Resolves relative URLs if $base is provided.
extract-hreflang-links(Str $html, Str $base = '' --> List)
Extract hreflang links from link tags. Searches for <link rel="alternate" hreflang="xx" href="...">. Returns a list of hashes with 'lang' and 'url' keys. Resolves relative URLs if $base is provided.
extract-videos(Str $html, Str $base = '' --> List)
Extract video URLs from HTML. Searches <video src>, <video><source>, and og:video meta tags. Returns a deduplicated list of hashes with 'url' and 'poster' keys. Thumbnail resolution priority: poster attribute โ og:image โ first img src โ empty. Resolves relative URLs if $base is provided.
extract-base-href(Str $html --> Str)
Return the href of the first <base> element in document order, or ''
when there is none. Per the HTML spec only the first base element's href is
used, so a later <base> is intentionally ignored. The value may be
relative and must be resolved against the document URL by the caller.