Change how links without rels are stored
This commit is contained in:
parent
4308939726
commit
4b44c06257
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -63,7 +63,7 @@ defmodule FeedParser.Parser.RSS2 do
|
|||
guid: guid,
|
||||
title: title,
|
||||
url: link,
|
||||
links: [link],
|
||||
links: [{link, nil}],
|
||||
content: description,
|
||||
date: pubDate
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue