mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
RSS of a topic via new route
Adds TopicView#recent_posts; Post#by_newest, #with_user, #author_readable; User#readable_name Autodiscovery tag in topic show HTML.
This commit is contained in:
@@ -17,7 +17,7 @@ class TopicsController < ApplicationController
|
||||
:move_posts]
|
||||
before_filter :consider_user_for_promotion, only: :show
|
||||
|
||||
skip_before_filter :check_xhr, only: [:avatar, :show]
|
||||
skip_before_filter :check_xhr, only: [:avatar, :show, :feed]
|
||||
caches_action :avatar, :cache_path => Proc.new {|c| "#{c.params[:post_number]}-#{c.params[:topic_id]}" }
|
||||
|
||||
|
||||
@@ -141,6 +141,11 @@ class TopicsController < ApplicationController
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def feed
|
||||
@topic_view = TopicView.new(params[:topic_id])
|
||||
render 'topics/show', formats: [:rss]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_topic_view
|
||||
|
||||
@@ -57,6 +57,9 @@ class Post < ActiveRecord::Base
|
||||
TopicUser.auto_track(self.user_id, self.topic_id, TopicUser::NotificationReasons::CREATED_POST)
|
||||
end
|
||||
|
||||
scope :by_newest, order('created_at desc, id desc')
|
||||
scope :with_user, includes(:user)
|
||||
|
||||
def raw_quality
|
||||
|
||||
sentinel = TextSentinel.new(self.raw, min_entropy: SiteSetting.body_min_entropy)
|
||||
@@ -298,6 +301,10 @@ class Post < ActiveRecord::Base
|
||||
"/t/#{Slug.for(topic.title)}/#{topic.id}/#{post_number}"
|
||||
end
|
||||
|
||||
def author_readable
|
||||
user.readable_name
|
||||
end
|
||||
|
||||
def revise(updated_by, new_raw, opts={})
|
||||
PostRevisor.new(self).revise!(updated_by, new_raw, opts)
|
||||
end
|
||||
|
||||
@@ -458,6 +458,14 @@ class User < ActiveRecord::Base
|
||||
$redis.set(last_seen_key, Time.now.to_f)
|
||||
end
|
||||
|
||||
def readable_name
|
||||
if name.present? && name != username
|
||||
"#{name} (#{username})"
|
||||
else
|
||||
username
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def cook
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
|
||||
<%=csrf_meta_tags%>
|
||||
|
||||
<%= yield :head %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -21,3 +21,7 @@
|
||||
|
||||
|
||||
<p>Powered by <a href="http://www.discourse.org">Discourse</a>, best viewed with JavaScript enabled</p>
|
||||
|
||||
<% content_for :head do %>
|
||||
<%= auto_discovery_link_tag(@topic_view, {action: :feed, format: :rss}, title: "RSS feed of '#{@topic_view.title}'") %>
|
||||
<% end %>
|
||||
|
||||
22
app/views/topics/show.rss.erb
Normal file
22
app/views/topics/show.rss.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title><%= @topic_view.title %></title>
|
||||
<link><%= Discourse.base_url %><%= @topic_view.relative_url %></link>
|
||||
<description><%= @topic_view.posts.first.raw %></description>
|
||||
<atom:link href="<%= Discourse.base_url %><%= @topic_view.relative_url %>.rss" rel="self" type="application/rss+xml" />
|
||||
<% @topic_view.recent_posts.each do |post| %>
|
||||
<item>
|
||||
<title><%= @topic_view.title %> at <%= post.created_at %></title>
|
||||
<description><![CDATA[
|
||||
<p><%= post.author_readable %> wrote:</p>
|
||||
<%= post.cooked.html_safe %>
|
||||
]]></description>
|
||||
<link><%= Discourse.base_url %><%= post.url %></link>
|
||||
<pubDate><%= post.created_at.rfc2822 %></pubDate>
|
||||
<guid><%= Discourse.base_url %><%= post.url %></guid>
|
||||
<source url="<%= Discourse.base_url %><%= @topic_view.relative_url %>.rss"><%= @topic_view.title %></source>
|
||||
</item>
|
||||
<% end %>
|
||||
</channel>
|
||||
</rss>
|
||||
Reference in New Issue
Block a user