Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/perron/site/builder/feeds/atom.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator uri="<%= @configuration.url %>" version="<%= Perron::VERSION %>">Perron</generator>
<id><%= current_feed_url %></id>
<id><%= current_feed_url.call %></id>
<title><%= config.title.presence || @configuration.site_name %></title>
<subtitle><%= config.description.presence || @configuration.site_description %></subtitle>
<link href="<%= current_feed_url %>" rel="self" type="application/atom+xml"/>
<link href="<%= current_feed_url.call %>" rel="self" type="application/atom+xml"/>
<link href="<%= @configuration.url %>" rel="alternate" type="text/html"/>
<updated><%= resources.first&.published_at&.iso8601 || Time.current.iso8601 %></updated>

Expand All @@ -16,20 +16,20 @@

<% resources.each do |resource| %>
<entry>
<id><%= url_for_resource(resource) || "#{@configuration.url}/posts/#{resource.id}" %></id>
<id><%= url_for_resource.call(resource) || "#{@configuration.url}/posts/#{resource.id}" %></id>
<title><%= resource.metadata.title %></title>
<link href="<%= url_for_resource(resource) %>" rel="alternate" type="text/html"/>
<link href="<%= url_for_resource.call(resource) %>" rel="alternate" type="text/html"/>
<published><%= resource.published_at&.iso8601 %></published>
<updated><%= (resource.metadata.updated_at || resource.published_at)&.iso8601 %></updated>

<% entry_author = author(resource); if entry_author %>
<% entry_author = author.call(resource); if entry_author %>
<author>
<% if entry_author.name %><name><%= entry_author.name %></name><% end %>
<% if entry_author.email %><email><%= entry_author.email %></email><% end %>
</author>
<% end %>

<% base_url = url_for_resource(resource) %>
<% base_url = url_for_resource.call(resource) %>
<% if base_url %>
<content type="html" xml:base="<%= base_url %>"><![CDATA[<%= Perron::Markdown.render(resource.content, processors: ["absolute_urls"]) %>]]></content>
<% else %>
Expand Down
6 changes: 3 additions & 3 deletions lib/perron/site/builder/feeds/rss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<item>
<guid isPermaLink="false"><%= resource.id %></guid>

<% resource_url = url_for_resource(resource) %>
<% resource_url = url_for_resource.call(resource) %>
<% if resource_url %>
<link><%= resource_url %></link>
<% end %>

<pubDate><%= resource.published_at&.rfc822 %></pubDate>
<% author = author(resource); if author && author.email %>
<author><%= author.name ? "#{author.email} (#{author.name})" : author.email %></author>
<% entry_author = author.call(resource); if entry_author && entry_author.email %>
<author><%= entry_author.name ? "#{entry_author.email} (#{entry_author.name})" : entry_author.email %></author>
<% end %>
<title><%= resource.metadata.title %></title>

Expand Down
29 changes: 29 additions & 0 deletions test/perron/site/builder/feeds_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,33 @@ class Perron::Site::Builder::FeedsTest < ActiveSupport::TestCase

assert output.start_with?("<?xml"), "Should generate XML when no custom template"
end

test "Atom feed renders URLs as actual URLs, not method signatures" do
posts = Perron::Site.collection("posts")

posts.configuration.feeds.atom.enabled = true
posts.configuration.feeds.atom.path = "feed.atom"

atom = Perron::Site::Builder::Feeds::Atom.new(collection: posts)
output = atom.generate

refute_includes output, "#<Method:", "Should not contain method signatures"
refute_includes output, "current_feed_url", "Should not contain method name in output"
assert_includes output, "http://", "Should contain actual URL"
end

test "Atom feed id and self link contain actual feed URL" do
posts = Perron::Site.collection("posts")

posts.configuration.feeds.atom.enabled = true
posts.configuration.feeds.atom.path = "feed.atom"

atom = Perron::Site::Builder::Feeds::Atom.new(collection: posts)
output = atom.generate

feed_url = "http://localhost:3000/feed.atom"

assert_match(/<id>#{Regexp.escape(feed_url)}<\/id>/, output, "Feed id should contain actual URL")
assert_match(/<link href="#{Regexp.escape(feed_url)}"[^>]*rel="self"/, output, "Self link should contain actual URL")
end
end
Loading