mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 22:42:19 +00:00
FEATURE: improve rendering of RSS feeds
- Eliminate superfluous "author wrote" block - Eliminate block-quote for all posts - Move participant count and reply count to 1 line - Prioritize name over username if forum requests - Use fabrication in list controller spec to speed up spec
This commit is contained in:
parent
344ef5226c
commit
ee36382640
@ -513,4 +513,14 @@ module ApplicationHelper
|
|||||||
!SiteSetting.invite_only &&
|
!SiteSetting.invite_only &&
|
||||||
!SiteSetting.enable_sso
|
!SiteSetting.enable_sso
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rss_creator(user)
|
||||||
|
if user
|
||||||
|
if SiteSetting.prioritize_username_in_ux
|
||||||
|
"#{user.username}"
|
||||||
|
else
|
||||||
|
"#{user.name.presence || user.username }"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,23 +12,15 @@
|
|||||||
<atom:link href="<%= @atom_link %>" rel="self" type="application/rss+xml" />
|
<atom:link href="<%= @atom_link %>" rel="self" type="application/rss+xml" />
|
||||||
<% @topic_list.topics.each do |topic| %>
|
<% @topic_list.topics.each do |topic| %>
|
||||||
<% topic_url = topic.url -%>
|
<% topic_url = topic.url -%>
|
||||||
<% username = topic.user ? topic.user.username : "" %>
|
|
||||||
<% name = topic.user ? topic.user.name : "" %>
|
|
||||||
<item>
|
<item>
|
||||||
<title><%= topic.title %></title>
|
<title><%= topic.title %></title>
|
||||||
<dc:creator><![CDATA[<%= "@#{username}#{" #{name}" if (name.present? && SiteSetting.enable_names?)}" -%>]]></dc:creator>
|
<dc:creator><![CDATA[<%= rss_creator(topic.user) -%>]]></dc:creator>
|
||||||
<category><%= topic.category.name %></category>
|
<category><%= topic.category.name %></category>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
<% if username.present? %>
|
<%- if first_post = topic.ordered_posts.first %>
|
||||||
<p><%= t('author_wrote', author: link_to("@#{username}", "#{Discourse.base_url}/u/#{url_encode(topic.user.username_lower)}")).html_safe %></p>
|
<%= first_post.cooked.html_safe %>
|
||||||
<% end %>
|
<%- end %>
|
||||||
<blockquote>
|
<p><small><%= t 'rss_num_posts', count: topic.posts_count %> - <%= t 'rss_num_participants', count: topic.participant_count %></small></p>
|
||||||
<%- if first_post = topic.ordered_posts.first %>
|
|
||||||
<%= first_post.cooked.html_safe %>
|
|
||||||
<%- end %>
|
|
||||||
</blockquote>
|
|
||||||
<p><%= t 'num_posts' %> <%= topic.posts_count %></p>
|
|
||||||
<p><%= t 'num_participants' %> <%= topic.participant_count %></p>
|
|
||||||
<p><%= link_to t('read_full_topic'), topic_url %></p>
|
<p><%= link_to t('read_full_topic'), topic_url %></p>
|
||||||
]]></description>
|
]]></description>
|
||||||
<link><%= topic_url %></link>
|
<link><%= topic_url %></link>
|
||||||
|
@ -15,17 +15,14 @@
|
|||||||
<% next unless post.user %>
|
<% next unless post.user %>
|
||||||
<item>
|
<item>
|
||||||
<title><%= @topic_view.title %></title>
|
<title><%= @topic_view.title %></title>
|
||||||
<dc:creator><![CDATA[<%= "@#{post.user.username}#{" #{post.user.name}" if (post.user.name.present? && SiteSetting.enable_names?)}" -%>]]></dc:creator>
|
<dc:creator><![CDATA[<%= rss_creator(post.user) -%>]]></dc:creator>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
<% post_url = Discourse.base_url + post.url %>
|
<% post_url = Discourse.base_url + post.url %>
|
||||||
<p><%= t('author_wrote', author: link_to("@#{post.user.username}", "#{Discourse.base_url}/u/#{url_encode(post.user.username_lower)}")).html_safe %></p>
|
<% if post.hidden %>
|
||||||
<blockquote>
|
<%= t('flagging.user_must_edit').html_safe %>
|
||||||
<% if post.hidden %>
|
<% else %>
|
||||||
<%= t('flagging.user_must_edit').html_safe %>
|
<%= post.cooked.html_safe %>
|
||||||
<% else %>
|
<% end %>
|
||||||
<%= post.cooked.html_safe %>
|
|
||||||
<% end %>
|
|
||||||
</blockquote>
|
|
||||||
<p><%= link_to t('read_full_topic'), post_url %></p>
|
<p><%= link_to t('read_full_topic'), post_url %></p>
|
||||||
]]></description>
|
]]></description>
|
||||||
<link><%= post_url %></link>
|
<link><%= post_url %></link>
|
||||||
|
@ -352,9 +352,13 @@ en:
|
|||||||
topics_in_category: "Topics in the '%{category}' category"
|
topics_in_category: "Topics in the '%{category}' category"
|
||||||
rss_posts_in_topic: "RSS feed of '%{topic}'"
|
rss_posts_in_topic: "RSS feed of '%{topic}'"
|
||||||
rss_topics_in_category: "RSS feed of topics in the '%{category}' category"
|
rss_topics_in_category: "RSS feed of topics in the '%{category}' category"
|
||||||
author_wrote: "%{author} wrote:"
|
rss_num_posts:
|
||||||
num_posts: "Posts:"
|
one: "%{count} post"
|
||||||
num_participants: "Participants:"
|
other: "%{count} posts"
|
||||||
|
rss_num_participants:
|
||||||
|
one: "%{count} participant"
|
||||||
|
other: "%{count} participants"
|
||||||
|
|
||||||
read_full_topic: "Read full topic"
|
read_full_topic: "Read full topic"
|
||||||
private_message_abbrev: "Msg"
|
private_message_abbrev: "Msg"
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ListController do
|
RSpec.describe ListController do
|
||||||
let(:topic) { Fabricate(:topic, user: user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
let(:group) { Fabricate(:group) }
|
fab!(:topic) { Fabricate(:topic, user: user) }
|
||||||
let(:user) { Fabricate(:user) }
|
fab!(:group) { Fabricate(:group) }
|
||||||
let(:admin) { Fabricate(:admin) }
|
fab!(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
admin # to skip welcome wizard at home page `/`
|
admin # to skip welcome wizard at home page `/`
|
||||||
@ -73,12 +73,12 @@ RSpec.describe ListController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "shows correct title if topic list is set for homepage" do
|
it "shows correct title if topic list is set for homepage" do
|
||||||
get "/"
|
get "/latest"
|
||||||
|
|
||||||
expect(response.body).to have_tag "title", text: "Discourse"
|
expect(response.body).to have_tag "title", text: "Discourse"
|
||||||
|
|
||||||
SiteSetting.short_site_description = "Best community"
|
SiteSetting.short_site_description = "Best community"
|
||||||
get "/"
|
get "/latest"
|
||||||
|
|
||||||
expect(response.body).to have_tag "title", text: "Discourse - Best community"
|
expect(response.body).to have_tag "title", text: "Discourse - Best community"
|
||||||
end
|
end
|
||||||
@ -95,7 +95,7 @@ RSpec.describe ListController do
|
|||||||
|
|
||||||
get "/categories_and_latest.json"
|
get "/categories_and_latest.json"
|
||||||
data = JSON.parse(response.body)
|
data = JSON.parse(response.body)
|
||||||
expect(data["topic_list"]["topics"].length).to eq(1)
|
expect(data["topic_list"]["topics"].length).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -305,12 +305,11 @@ RSpec.describe ListController do
|
|||||||
|
|
||||||
it 'renders links correctly with subfolder' do
|
it 'renders links correctly with subfolder' do
|
||||||
set_subfolder "/forum"
|
set_subfolder "/forum"
|
||||||
post = Fabricate(:post, topic: topic, user: user)
|
_post = Fabricate(:post, topic: topic, user: user)
|
||||||
get "/latest.rss"
|
get "/latest.rss"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.body).to_not include("/forum/forum")
|
expect(response.body).to_not include("/forum/forum")
|
||||||
expect(response.body).to include("http://test.localhost/forum/t/#{topic.slug}")
|
expect(response.body).to include("http://test.localhost/forum/t/#{topic.slug}")
|
||||||
expect(response.body).to include("http://test.localhost/forum/u/#{post.user.username}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders top RSS' do
|
it 'renders top RSS' do
|
||||||
@ -498,16 +497,18 @@ RSpec.describe ListController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "topics_by" do
|
describe "topics_by" do
|
||||||
|
fab!(:topic2) { Fabricate(:topic, user: user) }
|
||||||
|
fab!(:user2) { Fabricate(:user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in(Fabricate(:user))
|
sign_in(user2)
|
||||||
Fabricate(:topic, user: user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should respond with a list" do
|
it "should respond with a list" do
|
||||||
get "/topics/created-by/#{user.username}.json"
|
get "/topics/created-by/#{user.username}.json"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
expect(json["topic_list"]["topics"].size).to eq(1)
|
expect(json["topic_list"]["topics"].size).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with period in username" do
|
it "should work with period in username" do
|
||||||
@ -515,7 +516,7 @@ RSpec.describe ListController do
|
|||||||
get "/topics/created-by/#{user.username}", xhr: true
|
get "/topics/created-by/#{user.username}", xhr: true
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
expect(json["topic_list"]["topics"].size).to eq(1)
|
expect(json["topic_list"]["topics"].size).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user