Crawler.Snapper.LinkReplacer (Crawler v1.1.2) View Source

Replaces links found in a page so they work offline.

Link to this section Summary

Functions

Replaces links found in a page so they work offline.

Link to this section Functions

Link to this function

replace_links(body, opts)

View Source

Replaces links found in a page so they work offline.

Examples

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

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

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

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