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__{ @type t() :: %__MODULE__{
guid: String.t(), guid: String.t(),
url: String.t() | nil, 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, title: String.t() | nil,
content: String.t(), content: String.t(),
date: DateTime.t() date: DateTime.t()

View File

@ -52,18 +52,12 @@ defmodule FeedParser.Parser.Atom do
:xmerl_xpath.string('/entry/link', entry) :xmerl_xpath.string('/entry/link', entry)
|> Enum.map(fn link -> |> Enum.map(fn link ->
value = attr('/link/@href', link) value = attr('/link/@href', link)
rel = attr('/link/@rel', link)
case attr('/link/@rel', link) do {value, rel}
nil -> value
rel -> {value, rel}
end
end) end)
url = url =
(Enum.find(links, fn (Enum.find(links, fn {_value, rel} -> rel == "alternate" end) || List.first(links))
{value, rel} -> rel == "alternate"
_value -> false
end) || List.first(links))
|> case do |> case do
url when is_binary(url) -> url url when is_binary(url) -> url
{url, _rel} -> url {url, _rel} -> url

View File

@ -48,7 +48,7 @@ defmodule FeedParser.Parser.JSONFeed do
%FeedParser.Item{ %FeedParser.Item{
guid: id, guid: id,
url: url, url: url,
links: [url], links: [{url, nil}],
title: title, title: title,
content: content, content: content,
date: date date: date

View File

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

View File

@ -56,7 +56,7 @@ defmodule FeedParser.Parser.RSSInJSON do
%FeedParser.Item{ %FeedParser.Item{
guid: guid, guid: guid,
url: link, url: link,
links: [link], links: [{link, nil}],
title: title, title: title,
content: content, content: content,
date: pubDate date: pubDate