fix(feed): format RSS build dates
This commit is contained in:
parent
d0c8ca92a5
commit
96f471a291
3 changed files with 33 additions and 2 deletions
|
|
@ -38,6 +38,20 @@ defmodule Pleroma.Web.Feed.FeedView do
|
|||
end
|
||||
end
|
||||
|
||||
def most_recent_update([], :rss), do: nil
|
||||
|
||||
def most_recent_update(activities, :rss) do
|
||||
activities
|
||||
|> Enum.map(fn activity ->
|
||||
case Object.normalize(activity, fetch: false) do
|
||||
%Object{updated_at: updated_at} -> updated_at
|
||||
_ -> activity.updated_at
|
||||
end
|
||||
end)
|
||||
|> Enum.max_by(&NaiveDateTime.to_erl/1)
|
||||
|> to_rfc2822()
|
||||
end
|
||||
|
||||
def most_recent_update(activities, user, :atom) do
|
||||
(List.first(activities) || user).updated_at
|
||||
|> to_rfc3339()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
<webfeeds:logo><%= feed_logo() %></webfeeds:logo>
|
||||
<webfeeds:icon><%= feed_logo() %></webfeeds:icon>
|
||||
<webfeeds:accentColor>2b90d9</webfeeds:accentColor>
|
||||
<lastBuildDate><%= most_recent_update(@activities) || to_rfc2822(NaiveDateTime.utc_now()) %></lastBuildDate>
|
||||
<%= with last_build_date when not is_nil(last_build_date) <- most_recent_update(@activities, :rss) do %>
|
||||
<lastBuildDate><%= last_build_date %></lastBuildDate>
|
||||
<% end %>
|
||||
<generator><%= Pleroma.Application.named_version() %></generator>
|
||||
<%= for activity <- @activities do %>
|
||||
<%= render Phoenix.Controller.view_module(@conn), "_tag_activity.xml", Map.merge(assigns, prepare_activity(activity)) %>
|
||||
|
|
|
|||
|
|
@ -105,8 +105,10 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
}
|
||||
])
|
||||
|
||||
edited_at = NaiveDateTime.add(object.updated_at, 60)
|
||||
|
||||
object
|
||||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Ecto.Changeset.change(data: object_data, updated_at: edited_at)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
{:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
|
||||
|
|
@ -141,6 +143,9 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
FeedView.to_rfc2822(activity1.data["published"])
|
||||
]
|
||||
|
||||
assert xpath(xml, ~x"//channel/lastBuildDate/text()"s) ==
|
||||
FeedView.to_rfc2822(edited_at)
|
||||
|
||||
assert xpath(xml, ~x"//channel/item/media:content/@url"sl) == [
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
]
|
||||
|
|
@ -181,6 +186,16 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
]
|
||||
end
|
||||
|
||||
test "does not fabricate lastBuildDate for an empty RSS feed", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "empty.rss"))
|
||||
|> response(200)
|
||||
|
||||
refute response =~ "<lastBuildDate>"
|
||||
end
|
||||
|
||||
describe "private instance" do
|
||||
setup do: clear_config([:instance, :public], false)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue