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.

Sitemap v0.0.3

Sitemap generator for Raku

Authors

  • Sasha Abbott

License

CC0-1.0

Dependencies

Cro::HTTP:auth<zef:cro>:api<0>URI:auth<zef:raku-community-modules>LibXML:auth<zef:dwarring>LibXML::Writer:auth<zef:dwarring>Compress::ZlibJSON::Fast:auth<zef:timo>YAMLish:auth<zef:leont>DateTime::Format:auth<zef:raku-community-modules>Syndicate:auth<zef:sasha>

Test Dependencies

Provides

  • Sitemap
  • Sitemap::Builder
  • Sitemap::Config
  • Sitemap::Crawler
  • Sitemap::DirScanner
  • Sitemap::Extraction
  • Sitemap::Fetcher
  • Sitemap::Format::Atom
  • Sitemap::Format::FeedBuilder
  • Sitemap::Format::HTML
  • Sitemap::Format::MRSS
  • Sitemap::Format::RSS
  • Sitemap::Format::TXT
  • Sitemap::Grammar::LinkExtract
  • Sitemap::Grammar::RobotsTxt
  • Sitemap::Grammar::SitemapSniff
  • Sitemap::InputParser
  • Sitemap::Item
  • Sitemap::JsonLd
  • Sitemap::Parser
  • Sitemap::SiteTree
  • Sitemap::Subscribable

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite โ€” the markup and publishing tools behind this site.