Skip to content

Commit fc5684b

Browse files
noellabohiyuki2578
authored andcommitted
Add an RSS feed tagged to a public profile page (mastodon#10502)
* Add featured tag support to rss feed on public account page * fix codeing style
1 parent 1ec0c3e commit fc5684b

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

app/controllers/accounts_controller.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def show
2828
@pinned_statuses = cache_collection(@account.pinned_statuses, Status) if show_pinned_statuses?
2929
@statuses = filtered_status_page(params)
3030
@statuses = cache_collection(@statuses, Status)
31+
@rss_url = rss_url
3132

3233
unless @statuses.empty?
3334
@older_url = older_url if @statuses.last.id > filtered_statuses.last.id
@@ -38,8 +39,9 @@ def show
3839
format.rss do
3940
expires_in 0, public: true
4041

41-
@statuses = cache_collection(default_statuses.without_reblogs.without_replies.limit(PAGE_SIZE), Status)
42-
render xml: RSS::AccountSerializer.render(@account, @statuses)
42+
@statuses = filtered_statuses.without_reblogs.without_replies.limit(PAGE_SIZE)
43+
@statuses = cache_collection(@statuses, Status)
44+
render xml: RSS::AccountSerializer.render(@account, @statuses, params[:tag])
4345
end
4446

4547
format.json do
@@ -97,6 +99,14 @@ def username_param
9799
params[:username]
98100
end
99101

102+
def rss_url
103+
if tag_requested?
104+
short_account_tag_url(@account, params[:tag], format: 'rss')
105+
else
106+
short_account_url(@account, format: 'rss')
107+
end
108+
end
109+
100110
def older_url
101111
pagination_url(max_id: @statuses.last.id)
102112
end
@@ -126,7 +136,7 @@ def replies_requested?
126136
end
127137

128138
def tag_requested?
129-
request.path.ends_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize)
139+
request.path.split('.').first.ends_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize)
130140
end
131141

132142
def filtered_status_page(params)

app/serializers/rss/account_serializer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class RSS::AccountSerializer
55
include StatusesHelper
66
include RoutingHelper
77

8-
def render(account, statuses)
8+
def render(account, statuses, tag)
99
builder = RSSBuilder.new
1010

1111
builder.title("#{display_name(account)} (@#{account.local_username_and_domain})")
1212
.description(account_description(account))
13-
.link(ActivityPub::TagManager.instance.url_for(account))
13+
.link(tag.present? ? short_account_tag_url(account, tag) : short_account_url(account))
1414
.logo(full_pack_url('media/images/logo.svg'))
1515
.accent_color('2b90d9')
1616

@@ -33,7 +33,7 @@ def render(account, statuses)
3333
builder.to_xml
3434
end
3535

36-
def self.render(account, statuses)
37-
new.render(account, statuses)
36+
def self.render(account, statuses, tag)
37+
new.render(account, statuses, tag)
3838
end
3939
end

app/views/accounts/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- if @account.user&.setting_noindex
88
%meta{ name: 'robots', content: 'noindex, noarchive' }/
99

10-
%link{ rel: 'alternate', type: 'application/rss+xml', href: account_url(@account, format: 'rss') }/
10+
%link{ rel: 'alternate', type: 'application/rss+xml', href: @rss_url }/
1111
%link{ rel: 'alternate', type: 'application/activity+json', href: ActivityPub::TagManager.instance.uri_for(@account) }/
1212

1313
- if @older_url

0 commit comments

Comments
 (0)