Change how links without rels are stored

This commit is contained in:
Shadowfacts 2019-09-01 16:35:32 -04:00
parent 4308939726
commit 4b44c06257
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 7 additions and 13 deletions

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -63,7 +63,7 @@ defmodule FeedParser.Parser.RSS2 do
guid: guid,
title: title,
url: link,
links: [link],
links: [{link, nil}],
content: description,
date: pubDate
}

View File

@ -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