Crawler v0.2.0 Crawler.Snapper.Replacer

Replaces links found in a page so they work offline.

Link to this section Summary

Link to this section Functions

Link to this function replace_links(body, opts)

Examples

iex> Replacer.replace_links(
iex>   "<a href='http://another.domain/page.html'></a>",
iex>   url: "http://main.domain/dir/page",
iex>   depth: 1,
iex>   max_depths: 2,
iex> )
{:ok, "<a href='../../../another.domain/page.html'></a>"}

iex> Replacer.replace_links(
iex>   "<a href='http://another.domain/dir/page.html'></a>",
iex>   url: "http://main.domain/page",
iex>   depth: 1,
iex>   max_depths: 2,
iex> )
{:ok, "<a href='../../another.domain/dir/page.html'></a>"}

iex> Replacer.replace_links(
iex>   "<a href='http://another.domain/dir/page'></a>",
iex>   url: "http://main.domain/dir/page",
iex>   depth: 1,
iex>   max_depths: 2,
iex> )
{:ok, "<a href='../../../another.domain/dir/page/index.html'></a>"}

iex> Replacer.replace_links(
iex>   "<a href='/dir/page2.html'></a>",
iex>   url: "http://main.domain/dir/page",
iex>   referrer_url: "http://main.domain/dir/page",
iex>   depth: 1,
iex>   max_depths: 2,
iex> )
{:ok, "<a href='../../../main.domain/dir/page2.html'></a>"}