diff --git a/lib/item.ex b/lib/item.ex index 2e77ac7..9506873 100644 --- a/lib/item.ex +++ b/lib/item.ex @@ -8,7 +8,7 @@ defmodule FeedParser.Item do @type t() :: %__MODULE__{ guid: String.t(), url: String.t() | nil, - links: [{href :: String.t(), rel :: String.t()} | href :: String.t()], + links: [{href :: String.t(), rel :: String.t() | nil}], title: String.t() | nil, content: String.t(), date: DateTime.t() diff --git a/lib/parser/atom.ex b/lib/parser/atom.ex index 687b6b8..457c2a4 100644 --- a/lib/parser/atom.ex +++ b/lib/parser/atom.ex @@ -52,18 +52,12 @@ defmodule FeedParser.Parser.Atom do :xmerl_xpath.string('/entry/link', entry) |> Enum.map(fn link -> value = attr('/link/@href', link) - - case attr('/link/@rel', link) do - nil -> value - rel -> {value, rel} - end + rel = attr('/link/@rel', link) + {value, rel} end) url = - (Enum.find(links, fn - {value, rel} -> rel == "alternate" - _value -> false - end) || List.first(links)) + (Enum.find(links, fn {_value, rel} -> rel == "alternate" end) || List.first(links)) |> case do url when is_binary(url) -> url {url, _rel} -> url diff --git a/lib/parser/jsonfeed.ex b/lib/parser/jsonfeed.ex index 55d6348..8f031f7 100644 --- a/lib/parser/jsonfeed.ex +++ b/lib/parser/jsonfeed.ex @@ -48,7 +48,7 @@ defmodule FeedParser.Parser.JSONFeed do %FeedParser.Item{ guid: id, url: url, - links: [url], + links: [{url, nil}], title: title, content: content, date: date diff --git a/lib/parser/rss2.ex b/lib/parser/rss2.ex index f965694..482a23d 100644 --- a/lib/parser/rss2.ex +++ b/lib/parser/rss2.ex @@ -63,7 +63,7 @@ defmodule FeedParser.Parser.RSS2 do guid: guid, title: title, url: link, - links: [link], + links: [{link, nil}], content: description, date: pubDate } diff --git a/lib/parser/rssinjson.ex b/lib/parser/rssinjson.ex index 40603da..ec7cbd0 100644 --- a/lib/parser/rssinjson.ex +++ b/lib/parser/rssinjson.ex @@ -56,7 +56,7 @@ defmodule FeedParser.Parser.RSSInJSON do %FeedParser.Item{ guid: guid, url: link, - links: [link], + links: [{link, nil}], title: title, content: content, date: pubDate