forked from AkkomaGang/akkoma
passes w3c validator
This commit is contained in:
parent
8e5a88edf7
commit
4cafb8a89a
|
@ -14,14 +14,14 @@ defmodule Pleroma.Web.Feed.FeedView do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
@spec pub_date(String.t() | DateTime.t()) :: String.t()
|
||||
def pub_date(date) when is_binary(date) do
|
||||
@spec pub_date(String.t() | DateTime.t() | NaiveDateTime.t(), String.t()) :: String.t()
|
||||
def pub_date(date, format) when is_binary(date) do
|
||||
date
|
||||
|> Timex.parse!("{ISO:Extended}")
|
||||
|> pub_date
|
||||
|> pub_date(format)
|
||||
end
|
||||
|
||||
def pub_date(%DateTime{} = date), do: Timex.format!(date, "{RFC822}")
|
||||
def pub_date(date, format), do: Timex.format!(date, format)
|
||||
|
||||
def prepare_activity(activity, opts \\ []) do
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
@ -39,15 +39,14 @@ defmodule Pleroma.Web.Feed.FeedView do
|
|||
}
|
||||
end
|
||||
|
||||
def most_recent_update(activities) do
|
||||
def most_recent_update(activities, format) do
|
||||
with %{updated_at: updated_at} <- List.first(activities) do
|
||||
NaiveDateTime.to_iso8601(updated_at)
|
||||
Timex.format!(updated_at, format)
|
||||
end
|
||||
end
|
||||
|
||||
def most_recent_update(activities, user) do
|
||||
(List.first(activities) || user).updated_at
|
||||
|> NaiveDateTime.to_iso8601()
|
||||
def most_recent_update(activities, user, format) do
|
||||
(List.first(activities) || user).updated_at |> Timex.format!(format)
|
||||
end
|
||||
|
||||
def feed_logo do
|
||||
|
@ -107,9 +106,36 @@ defmodule Pleroma.Web.Feed.FeedView do
|
|||
end
|
||||
end
|
||||
|
||||
def escape(html) do
|
||||
html
|
||||
def escape(str) do
|
||||
str
|
||||
|> html_escape()
|
||||
|> safe_to_string()
|
||||
|> xml_escape()
|
||||
end
|
||||
|
||||
# Encoding newlines, e.g., per XML spec
|
||||
def xml_escape(nil), do: ""
|
||||
def xml_escape(str) when is_binary(str) do
|
||||
str
|
||||
|> xml_escape_string()
|
||||
|> to_string()
|
||||
end
|
||||
|
||||
defp xml_escape_string(""), do: ""
|
||||
defp xml_escape_string(<<"&"::utf8, rest::binary>>), do: xml_escape_entity(rest)
|
||||
defp xml_escape_string(<<"<"::utf8, rest::binary>>), do: ["<" | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<">"::utf8, rest::binary>>), do: [">" | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<"\""::utf8, rest::binary>>), do: [""" | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<"'"::utf8, rest::binary>>), do: ["'" | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<"\t"::utf8, rest::binary>>), do: ["	" | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<"\n"::utf8, rest::binary>>), do: [" " | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<"\r\n"::utf8, rest::binary>>), do: [" " | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<"\r"::utf8, rest::binary>>), do: [" " | xml_escape_string(rest)]
|
||||
defp xml_escape_string(<<c::utf8, rest::binary>>), do: [c | xml_escape_string(rest)]
|
||||
defp xml_escape_entity(<<"amp;"::utf8, rest::binary>>), do: ["&" | xml_escape_string(rest)]
|
||||
defp xml_escape_entity(<<"lt;"::utf8, rest::binary>>), do: ["<" | xml_escape_string(rest)]
|
||||
defp xml_escape_entity(<<"gt;"::utf8, rest::binary>>), do: [">" | xml_escape_string(rest)]
|
||||
defp xml_escape_entity(<<"quot;"::utf8, rest::binary>>), do: [""" | xml_escape_string(rest)]
|
||||
defp xml_escape_entity(<<"apos;"::utf8, rest::binary>>), do: ["'" | xml_escape_string(rest)]
|
||||
defp xml_escape_entity(rest), do: ["&" | xml_escape_string(rest)]
|
||||
end
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<id><%= @data["id"] %></id>
|
||||
<title><%= activity_title(@data, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||
<content type="html"><%= activity_content(@data) %></content>
|
||||
<published><%= @activity.data["published"] %></published>
|
||||
<updated><%= @activity.data["published"] %></updated>
|
||||
<published><%= pub_date(@activity.data["published"], "{RFC3339z}") %></published>
|
||||
<updated><%= pub_date(@activity.data["published"], "{RFC3339z}") %></updated>
|
||||
<ostatus:conversation ref="<%= activity_context(@activity) %>">
|
||||
<%= activity_context(@activity) %>
|
||||
</ostatus:conversation>
|
||||
|
@ -16,10 +16,10 @@
|
|||
<% end %>
|
||||
|
||||
<%= if @activity.local do %>
|
||||
<link type="application/atom+xml" href='<%= @data["id"] %>' rel="self"/>
|
||||
<link type="text/html" href='<%= @data["id"] %>' rel="alternate"/>
|
||||
<link type="application/atom+xml" href="<%= @data["id"] %>" rel="self"/>
|
||||
<link type="text/html" href="<%= @data["id"] %>" rel="alternate"/>
|
||||
<% else %>
|
||||
<link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/>
|
||||
<link type="text/html" href="<%= @data["external_url"] %>" rel="alternate"/>
|
||||
<% end %>
|
||||
|
||||
<%= for tag <- Pleroma.Object.hashtags(@object) do %>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<% end %>
|
||||
|
||||
<%= if @data["inReplyTo"] do %>
|
||||
<thr:in-reply-to ref='<%= @data["inReplyTo"] %>' href='<%= get_href(@data["inReplyTo"]) %>'/>
|
||||
<thr:in-reply-to ref="<%= @data["inReplyTo"] %>" href="<%= get_href(@data["inReplyTo"]) %>"/>
|
||||
<% end %>
|
||||
|
||||
<%= for id <- @activity.recipients do %>
|
||||
|
|
|
@ -4,14 +4,17 @@
|
|||
<guid><%= @data["id"] %></guid>
|
||||
<title><%= activity_title(@data, Keyword.get(@feed_config, :post_title, %{})) %></title>
|
||||
<description><%= activity_content(@data) %></description>
|
||||
<pubDate><%= @activity.data["published"] %></pubDate>
|
||||
<updated><%= @activity.data["published"] %></updated>
|
||||
<pubDate><%= pub_date(@activity.data["published"], "{RFC822z}") %></pubDate>
|
||||
<ostatus:conversation ref="<%= activity_context(@activity) %>">
|
||||
<%= activity_context(@activity) %>
|
||||
</ostatus:conversation>
|
||||
|
||||
<%= if @data["summary"] do %>
|
||||
<description><%= escape(@data["summary"]) %></description>
|
||||
<atom:summary><%= escape(@data["summary"]) %></atom:summary>
|
||||
<% end %>
|
||||
|
||||
<%= if get_in(@data, ["source", "mediaType"]) == "text/markdown" do %>
|
||||
<source:markdown><%= escape(get_in(@data, ["source", "content"])) %></source:markdown>
|
||||
<% end %>
|
||||
|
||||
<%= if @activity.local do %>
|
||||
|
@ -20,26 +23,26 @@
|
|||
<link><%= @data["external_url"] %></link>
|
||||
<% end %>
|
||||
|
||||
<link rel="ostatus:conversation"><%= activity_context(@activity) %></link>
|
||||
<atom:link rel="ostatus:conversation" href="<%= activity_context(@activity) %>"/>
|
||||
|
||||
<%= for tag <- Pleroma.Object.hashtags(@object) do %>
|
||||
<category term="<%= tag %>"></category>
|
||||
<% end %>
|
||||
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
<link type="<%= attachment_type(attachment) %>"><%= attachment_href(attachment) %></link>
|
||||
<atom:link type="<%= attachment_type(attachment) %>" href="<%= attachment_href(attachment) %>"/>
|
||||
<% end %>
|
||||
|
||||
<%= if @data["inReplyTo"] do %>
|
||||
<thr:in-reply-to ref='<%= @data["inReplyTo"] %>' href='<%= get_href(@data["inReplyTo"]) %>'/>
|
||||
<thr:in-reply-to ref="<%= @data["inReplyTo"] %>" href="<%= get_href(@data["inReplyTo"]) %>"/>
|
||||
<% end %>
|
||||
|
||||
<%= for id <- @activity.recipients do %>
|
||||
<%= if id == Pleroma.Constants.as_public() do %>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection">http://activityschema.org/collection/public</link>
|
||||
<atom:link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<% else %>
|
||||
<%= unless Regex.match?(~r/^#{Pleroma.Web.Endpoint.url()}.+followers$/, id) do %>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person"><%= id %></link>
|
||||
<atom:link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="<%= id %>"/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
<author>
|
||||
<id><%= @user.ap_id %></id>
|
||||
<activity:object>http://activitystrea.ms/schema/1.0/person</activity:object>
|
||||
<name><%= @user.nickname %></name>
|
||||
<uri><%= @user.ap_id %></uri>
|
||||
<email><%= @user.email %></email>
|
||||
<activity:object>http://activitystrea.ms/schema/1.0/person</activity:object>
|
||||
<poco:preferredUsername><%= @user.nickname %></poco:preferredUsername>
|
||||
<poco:displayName><%= @user.name %></poco:displayName>
|
||||
<poco:note><%= escape(@user.bio) %></poco:note>
|
||||
<summary><%= escape(@user.bio) %></summary>
|
||||
<name><%= @user.nickname %></name>
|
||||
<link rel="avatar" href="<%= User.avatar_url(@user) %>"/>
|
||||
<%= if @user.bio do %>
|
||||
<poco:note><%= escape(@user.bio) %></poco:note>
|
||||
<% end %>
|
||||
<local:link rel="avatar" href="<%= User.avatar_url(@user) %>"/>
|
||||
<%= if User.banner_url(@user) do %>
|
||||
<link rel="header" href="<%= User.banner_url(@user) %>"/>
|
||||
<local:link rel="header" href="<%= User.banner_url(@user) %>"/>
|
||||
<% end %>
|
||||
<%= if @user.local do %>
|
||||
<ap_enabled>true</ap_enabled>
|
||||
<ap:ap_enabled>true</ap:ap_enabled>
|
||||
<% end %>
|
||||
</author>
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
<managingEditor>
|
||||
<guid><%= @user.ap_id %></guid>
|
||||
<managingEditor><%= @user.email %></managingEditor>
|
||||
<atom:author>
|
||||
<atom:name><%= @user.nickname %></atom:name>
|
||||
<atom:uri><%= @user.ap_id %></atom:uri>
|
||||
<atom:email><%= @user.email %></atom:email>
|
||||
<activity:object>http://activitystrea.ms/schema/1.0/person</activity:object>
|
||||
<uri><%= @user.ap_id %></uri>
|
||||
<poco:preferredUsername><%= @user.nickname %></poco:preferredUsername>
|
||||
<poco:displayName><%= @user.name %></poco:displayName>
|
||||
<poco:note><%= escape(@user.bio) %></poco:note>
|
||||
<description><%= escape(@user.bio) %></description>
|
||||
<name><%= @user.nickname %></name>
|
||||
<link rel="avatar"><%= User.avatar_url(@user) %></link>
|
||||
<%= if @user.bio do %>
|
||||
<poco:note><%= escape(@user.bio) %></poco:note>
|
||||
<% end %>
|
||||
<atom:link rel="avatar" href="<%= User.avatar_url(@user) %>"/>
|
||||
<%= if User.banner_url(@user) do %>
|
||||
<link rel="header"><%= User.banner_url(@user) %></link>
|
||||
<atom:link rel="header" href="<%= User.banner_url(@user) %>"/>
|
||||
<% end %>
|
||||
<%= if @user.local do %>
|
||||
<ap_enabled>true</ap_enabled>
|
||||
<ap:ap_enabled>true</ap:ap_enabled>
|
||||
<% end %>
|
||||
</managingEditor>
|
||||
</atom:author>
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
<content type="html"><%= activity_content(@data) %></content>
|
||||
|
||||
<%= if @activity.local do %>
|
||||
<link type="application/atom+xml" href='<%= @data["id"] %>' rel="self"/>
|
||||
<link type="text/html" href='<%= @data["id"] %>' rel="alternate"/>
|
||||
<link type="application/atom+xml" href="<%= @data["id"] %>" rel="self"/>
|
||||
<link type="text/html" href="<%= @data["id"] %>" rel="alternate"/>
|
||||
<% else %>
|
||||
<link type="text/html" href='<%= @data["external_url"] %>' rel="alternate"/>
|
||||
<link type="text/html" href="<%= @data["external_url"] %>" rel="alternate"/>
|
||||
<% end %>
|
||||
|
||||
<published><%= @activity.data["published"] %></published>
|
||||
<updated><%= @activity.data["published"] %></updated>
|
||||
<published><%= pub_date(@activity.data["published"], "{RFC3339z}") %></published>
|
||||
<updated><%= pub_date(@activity.data["published"], "{RFC3339z}") %></updated>
|
||||
|
||||
<ostatus:conversation ref="<%= activity_context(@activity) %>">
|
||||
<%= activity_context(@activity) %>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<guid isPermalink="true"><%= activity_context(@activity) %></guid>
|
||||
<link><%= activity_context(@activity) %></link>
|
||||
<pubDate><%= pub_date(@activity.data["published"]) %></pubDate>
|
||||
<pubDate><%= pub_date(@activity.data["published"], "{RFC822z}") %></pubDate>
|
||||
|
||||
<description><%= activity_content(@data) %></description>
|
||||
<%= for attachment <- @data["attachment"] || [] do %>
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
xmlns:ostatus="http://ostatus.org/schema/1.0"
|
||||
xmlns:statusnet="http://status.net/schema/api/1/">
|
||||
|
||||
<id><%= '#{Routes.tag_feed_url(@conn, :feed, @tag)}.rss' %></id>
|
||||
<id><%= Routes.tag_feed_url(@conn, :feed, @tag) <> ".atom" %></id>
|
||||
<title>#<%= @tag %></title>
|
||||
|
||||
<subtitle><%= Gettext.dpgettext("static_pages", "tag feed description", "These are public toots tagged with #%{tag}. You can interact with them if you have an account anywhere in the fediverse.", tag: @tag) %></subtitle>
|
||||
<logo><%= feed_logo() %></logo>
|
||||
<updated><%= most_recent_update(@activities) %></updated>
|
||||
<link rel="self" href="<%= '#{Routes.tag_feed_url(@conn, :feed, @tag)}.atom' %>" type="application/atom+xml"/>
|
||||
<updated><%= most_recent_update(@activities, "{RFC3339z}") %></updated>
|
||||
<link rel="self" href="<%= Routes.tag_feed_url(@conn, :feed, @tag) <> ".atom" %>" type="application/atom+xml"/>
|
||||
<%= for activity <- @activities do %>
|
||||
<%= render @view_module, "_tag_activity.atom", Map.merge(assigns, prepare_activity(activity, actor: true)) %>
|
||||
<% end %>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<title>#<%= @tag %></title>
|
||||
<description><%= Gettext.dpgettext("static_pages", "tag feed description", "These are public toots tagged with #%{tag}. You can interact with them if you have an account anywhere in the fediverse.", tag: @tag) %></description>
|
||||
<link><%= '#{Routes.tag_feed_url(@conn, :feed, @tag)}.rss' %></link>
|
||||
<link><%= "#{Routes.tag_feed_url(@conn, :feed, @tag)}.rss" %></link>
|
||||
<webfeeds:logo><%= feed_logo() %></webfeeds:logo>
|
||||
<webfeeds:accentColor>2b90d9</webfeeds:accentColor>
|
||||
<%= for activity <- @activities do %>
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<feed
|
||||
xmlns="http://www.w3.org/2005/Atom"
|
||||
xmlns:rss="https://www.rssboard.org/rss-specification"
|
||||
xmlns:thr="http://purl.org/syndication/thread/1.0"
|
||||
xmlns:activity="http://activitystrea.ms/spec/1.0/"
|
||||
xmlns:poco="http://portablecontacts.net/spec/1.0"
|
||||
xmlns:ostatus="http://ostatus.org/schema/1.0">
|
||||
xmlns:ostatus="http://ostatus.org/schema/1.0"
|
||||
xmlns:ap="https://www.w3.org/TR/activitypub/">
|
||||
|
||||
<id><%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".atom" %></id>
|
||||
<title><%= @user.nickname <> "'s timeline" %></title>
|
||||
<updated><%= most_recent_update(@activities, @user) %></updated>
|
||||
<updated><%= most_recent_update(@activities, @user, "{RFC3339z}") %></updated>
|
||||
<logo><%= logo(@user) %></logo>
|
||||
<link rel="self" href="<%= '#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.atom' %>" type="application/atom+xml"/>
|
||||
<link rel="self" href="<%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".atom" %>" type="application/atom+xml"/>
|
||||
|
||||
<%= render @view_module, "_author.atom", assigns %>
|
||||
|
||||
<%= if last_activity(@activities) do %>
|
||||
<link rel="next" href="<%= '#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.atom?max_id=#{last_activity(@activities).id}' %>" type="application/atom+xml"/>
|
||||
<link rel="next" href="<%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".atom?max_id=#{last_activity(@activities).id}" %>" type="application/atom+xml"/>
|
||||
<% end %>
|
||||
|
||||
<%= for activity <- @activities do %>
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<rss version="2.0"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:thr="http://purl.org/syndication/thread/1.0"
|
||||
xmlns:activity="http://activitystrea.ms/spec/1.0/"
|
||||
xmlns:poco="http://portablecontacts.net/spec/1.0"
|
||||
xmlns:ostatus="http://ostatus.org/schema/1.0"
|
||||
xmlns:source="https://github.com/scripting/tweetFeedSupport"
|
||||
xmlns:ap="https://www.w3.org/TR/activitypub/">
|
||||
<channel>
|
||||
<guid><%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".rss" %></guid>
|
||||
<title><%= @user.nickname <> "'s timeline" %></title>
|
||||
<updated><%= most_recent_update(@activities, @user) %></updated>
|
||||
<image><%= logo(@user) %></image>
|
||||
<link><%= '#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.rss' %></link>
|
||||
<description>Publicly visible items published by <%= @user.nickname %></description>
|
||||
<link><%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".rss" %></link>
|
||||
<lastBuildDate><%= most_recent_update(@activities, @user, "{RFC822z}") %></lastBuildDate>
|
||||
<image>
|
||||
<link><%= logo(@user) %></link>
|
||||
<title><%= @user.nickname <> "'s avatar" %></title>
|
||||
<url><%= logo(@user) %></url>
|
||||
</image>
|
||||
|
||||
<%= render @view_module, "_author.rss", assigns %>
|
||||
|
||||
<%= if last_activity(@activities) do %>
|
||||
<link rel="next"><%= '#{Routes.user_feed_url(@conn, :feed, @user.nickname)}.rss?max_id=#{last_activity(@activities).id}' %></link>
|
||||
<atom:link rel="next" href="<%= Routes.user_feed_url(@conn, :feed, @user.nickname) <> ".rss?max_id=#{last_activity(@activities).id}" %>"/>
|
||||
<% end %>
|
||||
|
||||
<%= for activity <- @activities do %>
|
||||
<%= render @view_module, "_activity.rss", Map.merge(assigns, prepare_activity(activity)) %>
|
||||
<% end %>
|
||||
|
|
|
@ -138,8 +138,8 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
]
|
||||
|
||||
assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
|
||||
FeedView.pub_date(activity2.data["published"]),
|
||||
FeedView.pub_date(activity1.data["published"])
|
||||
FeedView.pub_date(activity2.data["published"], "{RFC822z}"),
|
||||
FeedView.pub_date(activity1.data["published"], "{RFC822z}")
|
||||
]
|
||||
|
||||
assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
|
||||
|
|
Loading…
Reference in New Issue