Allow items without dates
This commit is contained in:
parent
fbe98c2e66
commit
740e0e7fca
|
@ -5,7 +5,7 @@ defmodule Frenzy.Item do
|
||||||
alias FrenzyWeb.Endpoint
|
alias FrenzyWeb.Endpoint
|
||||||
|
|
||||||
def to_fever(item) do
|
def to_fever(item) do
|
||||||
%{
|
res = %{
|
||||||
id: item.id,
|
id: item.id,
|
||||||
feed_id: item.feed_id,
|
feed_id: item.feed_id,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
|
@ -13,24 +13,34 @@ defmodule Frenzy.Item do
|
||||||
html: item.content,
|
html: item.content,
|
||||||
url: item.url,
|
url: item.url,
|
||||||
is_saved: 0,
|
is_saved: 0,
|
||||||
is_read: if(item.read, do: 1, else: 0),
|
is_read: if(item.read, do: 1, else: 0)
|
||||||
created_on_time: Timex.to_unix(item.date)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if item.date do
|
||||||
|
Map.put(res, :created_on_time, Timex.to_unix(item.date))
|
||||||
|
else
|
||||||
|
res
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_fervor(item) do
|
def to_fervor(item) do
|
||||||
%{
|
res = %{
|
||||||
id: item.id,
|
id: item.id,
|
||||||
feed_id: item.feed_id,
|
feed_id: item.feed_id,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
author: item.creator,
|
author: item.creator,
|
||||||
created_at: DateTime.to_iso8601(item.date),
|
|
||||||
content: item.content,
|
content: item.content,
|
||||||
url: item.url,
|
url: item.url,
|
||||||
service_url:
|
service_url:
|
||||||
Application.get_env(:frenzy, :base_url) <> Routes.item_path(Endpoint, :show, item.id),
|
Application.get_env(:frenzy, :base_url) <> Routes.item_path(Endpoint, :show, item.id),
|
||||||
read: item.read
|
read: item.read
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if item.date do
|
||||||
|
Map.put(res, :created_at, DateTime.to_iso8601(item.date))
|
||||||
|
else
|
||||||
|
res
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
schema "items" do
|
schema "items" do
|
||||||
|
@ -53,7 +63,7 @@ defmodule Frenzy.Item do
|
||||||
__meta__: Ecto.Schema.Metadata.t(),
|
__meta__: Ecto.Schema.Metadata.t(),
|
||||||
id: integer() | nil,
|
id: integer() | nil,
|
||||||
content: String.t(),
|
content: String.t(),
|
||||||
date: DateTime.t(),
|
date: DateTime.t() | nil,
|
||||||
creator: String.t(),
|
creator: String.t(),
|
||||||
guid: String.t(),
|
guid: String.t(),
|
||||||
url: String.t(),
|
url: String.t(),
|
||||||
|
|
|
@ -14,11 +14,23 @@ defmodule Frenzy.Task.CreateItem do
|
||||||
|
|
||||||
Logger.debug("Creating item for #{url}")
|
Logger.debug("Creating item for #{url}")
|
||||||
|
|
||||||
|
date =
|
||||||
|
entry.date
|
||||||
|
|> Timex.Timezone.convert(:utc)
|
||||||
|
|> case do
|
||||||
|
{:error, reason} ->
|
||||||
|
Logger.debug("Couldn't convert date '#{entry.date}' to UTC: #{reason}")
|
||||||
|
nil
|
||||||
|
|
||||||
|
utc_date ->
|
||||||
|
DateTime.truncate(utc_date, :second)
|
||||||
|
end
|
||||||
|
|
||||||
item_params = %{
|
item_params = %{
|
||||||
guid: entry.guid,
|
guid: entry.guid,
|
||||||
title: entry.title,
|
title: entry.title,
|
||||||
url: url,
|
url: url,
|
||||||
date: entry.date |> Timex.Timezone.convert(:utc) |> DateTime.truncate(:second),
|
date: date,
|
||||||
creator: "",
|
creator: "",
|
||||||
content: entry.content
|
content: entry.content
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
<a href="<%= Routes.item_path(@conn, :show, item.id) %>"><%= item.title || "(Untitled)" %></a>
|
<a href="<%= Routes.item_path(@conn, :show, item.id) %>"><%= item.title || "(Untitled)" %></a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% {:ok, date} = Timex.format(item.date, "{YYYY}-{M}-{D} {h12}:{m} {AM}") %>
|
<% if item.date do %>
|
||||||
<%= date %>
|
<% {:ok, date} = Timex.format(item.date, "{YYYY}-{M}-{D} {h12}:{m} {AM}") %>
|
||||||
|
<%= date %>
|
||||||
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in New Issue