Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 21.3.1
elixir 1.6.6-otp-21
elixir 1.14.5-otp-24
erlang 24.3.4.12
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

if File.exists?("config/#{Mix.env()}.exs") do
import_config "#{Mix.env()}.exs"
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :httparrot,
http_port: 8888,
Expand Down
14 changes: 8 additions & 6 deletions lib/link_preview/parsers/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule LinkPreview.Parsers.Html do
def title(page, body) do
title =
body
|> Floki.parse()
|> Floki.parse_document()
|> elem(1)
|> Floki.find("title")
|> List.first()
|> get_text
Expand Down Expand Up @@ -57,7 +58,7 @@ defmodule LinkPreview.Parsers.Html do
than 100px\n
if set to integer value it filters images with at least one dimension
smaller than that integer\n
requires Mogrify and Tempfile optional packages and imagemagick to be installed on machine\n
requires Mogrify optional package and imagemagick to be installed on machine\n
default: false
\n
WARNING: Using these options may reduce performance. To prevent very long processing time
Expand All @@ -66,7 +67,8 @@ defmodule LinkPreview.Parsers.Html do
def images(page, body) do
images =
body
|> Floki.parse()
|> Floki.parse_document()
|> elem(1)
|> Floki.attribute("img", "src")
|> Enum.map(&String.trim(&1))
|> maybe_limit
Expand All @@ -90,7 +92,8 @@ defmodule LinkPreview.Parsers.Html do
defp search_h(body, level) do
description =
body
|> Floki.parse()
|> Floki.parse_document()
|> elem(1)
|> Floki.find("h#{level}")
|> List.first()
|> get_text
Expand Down Expand Up @@ -140,9 +143,8 @@ defmodule LinkPreview.Parsers.Html do

defp filter_small_image(url, min_size) do
with true <- Code.ensure_loaded?(Mogrify),
true <- Code.ensure_loaded?(Tempfile),
{:ok, %Tesla.Env{body: body}} <- Requests.get(url),
{:ok, tempfile_path} <- Tempfile.random("link_preview"),
{:ok, tempfile_path} <- Briefly.create(),
:ok <- File.write(tempfile_path, body),
%Mogrify.Image{} = raw <- Mogrify.open(tempfile_path),
%Mogrify.Image{width: width, height: height} <- Mogrify.verbose(raw),
Expand Down
9 changes: 6 additions & 3 deletions lib/link_preview/parsers/opengraph.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule LinkPreview.Parsers.Opengraph do
def title(page, body) do
title =
body
|> Floki.parse()
|> Floki.parse_document()
|> elem(1)
|> Floki.find("meta[property^=\"og:title\"]")
|> Floki.attribute("content")
|> List.first()
Expand All @@ -37,7 +38,8 @@ defmodule LinkPreview.Parsers.Opengraph do
def description(page, body) do
description =
body
|> Floki.parse()
|> Floki.parse_document()
|> elem(1)
|> Floki.find("meta[property^=\"og:description\"]")
|> Floki.attribute("content")
|> List.first()
Expand All @@ -64,7 +66,8 @@ defmodule LinkPreview.Parsers.Opengraph do
def images(page, body) do
images =
body
|> Floki.parse()
|> Floki.parse_document()
|> elem(1)
|> Floki.find("meta[property^=\"og:image\"]")
|> Floki.attribute("content")
|> Enum.map(&String.trim(&1))
Expand Down
8 changes: 2 additions & 6 deletions lib/link_preview/parsers/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule LinkPreview.Parsers.Util do

@doc """
When `:friendly_string` is set to true, given url will be converted to
more human friedly format
more human friendly format

* Removes leading and trailing whitespaces.
* Changes rest of newline characters to space and replace all multiple
Expand Down Expand Up @@ -99,11 +99,7 @@ defmodule LinkPreview.Parsers.Util do
defp decode_html(text) do
code = Application.get_env(:link_preview, :code_module, Code)

if code.ensure_loaded?(HtmlEntities) do
text |> HtmlEntities.decode()
else
text
end
if code.ensure_loaded?(HtmlEntities), do: HtmlEntities.decode(text), else: text
end

defp force_absolute_url(url, website_url) do
Expand Down
29 changes: 9 additions & 20 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,22 @@ defmodule LinkPreview.Mixfile do
]
end

def application do
[applications: applications(Mix.env())]
end

def applications(:all), do: [:floki, :inets, :logger, :tesla]
def applications(:test), do: applications(:all) ++ [:httparrot]
def applications(_), do: applications(:all)

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

defp deps do
[
# required
{:floki, "~> 0.21.0"},
{:tesla, "~> 1.2.1"},

# optional
{:html_entities, "~> 0.4", optional: true},
{:mogrify, "~> 0.4.0", optional: true},
{:tempfile, "~> 0.1.0", optional: true},
{:floki, "~> 0.36.2"},
{:tesla, "~> 1.4"},
{:briefly, "~> 0.5.1"},
{:html_entities, "~> 0.5", optional: true},
{:mogrify, "~> 0.9.3", optional: true},

# testing/docs
{:excoveralls, "~> 0.6", only: :test},
{:ex_doc, "~> 0.12", only: :dev},
{:httparrot, "~> 0.5.0", only: :test},
{:mock, "~> 0.3.3", only: :test}
{:excoveralls, "~> 0.18.1", only: :test},
{:ex_doc, "~> 0.34.0", only: :dev},
{:httparrot, "~> 1.3", only: :test},
{:mimic, "~> 1.7", only: :test}
]
end

Expand Down
Loading