Link Preview v1.0.1 LinkPreview.Parsers.Util
Utility functions shared across 2 or more parsers.
Summary
Functions
When :force_images_absolute_url
is set to true, website_url from page struct will
be prepend to all relative urls. Absolute urls remain unchanged
When :force_images_url_schema
is set to true, http://
will
be prepend to all urls without schema
When :friendly_string
is set to true, given url will be converted to
more human friedly format
Check if given urls leads to images when some url-changing options are enabled
Functions
When :force_images_absolute_url
is set to true, website_url from page struct will
be prepend to all relative urls. Absolute urls remain unchanged.
Example:
iex> page = %Page{website_url: "example.com"}
iex> maybe_force_absolute_url(["another_page/image.jpg", "/assets/image.jpg"], page)
["another_page/image.jpg", "/assets/image.jpg"]
iex> Application.put_env(:link_preview, :force_images_absolute_url, true)
iex> maybe_force_absolute_url(["another_page/image.jpg", "/assets/image.jpg"], page)
["another_page/image.jpg", "example.com/assets/image.jpg"]
When :force_images_url_schema
is set to true, http://
will
be prepend to all urls without schema.
Example:
iex> maybe_force_url_schema(["page1/image.jpg", "https:://page2/image.jpg"])
["page1/image.jpg", "https:://page2/image.jpg"]
iex> Application.put_env(:link_preview, :force_images_url_schema, true)
iex> maybe_force_url_schema(["page1/image.jpg", "https:://page2/image.jpg"])
["http://page1/image.jpg", "https:://page2/image.jpg"]
When :friendly_string
is set to true, given url will be converted to
more human friedly format
- Removes leading and trailing whitespaces.
- Changes rest of newline characters to space and replace all multiple spaces by single space.
- If HtmlEntities optional package is loaded then decodes html entities, e.g. "