diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index ac8643780..6b0836aa2 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -20,9 +20,15 @@ class ForumTopicsController < ApplicationController def index @query = ForumTopic.active.search(params[:search]) - @forum_topics = @query.includes([:creator, :updater]).order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => per_page, :search_count => params[:search]) + @forum_topics = @query.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => per_page, :search_count => params[:search]) respond_with(@forum_topics) do |format| + format.html do + @forum_topics = @forum_topics.includes(:creator, :updater).load + end + format.atom do + @forum_topics = @forum_topics.includes(:creator, :original_post).load + end format.json do render :json => @forum_topics.to_json end @@ -37,8 +43,11 @@ class ForumTopicsController < ApplicationController @forum_topic.mark_as_read!(CurrentUser.user) end @forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page]) - @forum_posts.each # hack to force rails to eager load - respond_with(@forum_topic) + respond_with(@forum_topic) do |format| + format.atom do + @forum_posts = @forum_posts.includes(:creator).load + end + end end def create diff --git a/app/views/forum_topics/index.atom.builder b/app/views/forum_topics/index.atom.builder new file mode 100644 index 000000000..c610dc19a --- /dev/null +++ b/app/views/forum_topics/index.atom.builder @@ -0,0 +1,16 @@ +atom_feed do |feed| + feed.title("Forum Topics") + feed.updated(@forum_topics.first.try(:updated_at)) + + @forum_topics.each do |topic| + feed.entry(topic, published: topic.created_at, updated: topic.updated_at) do |entry| + entry.title("[#{topic.category_name}] #{topic.title}") + entry.content(format_text(topic.original_post.body), type: "html") + + entry.author do |author| + author.name(topic.creator.name) + author.uri(user_url(topic.creator_id)) + end + end + end +end diff --git a/app/views/forum_topics/index.html.erb b/app/views/forum_topics/index.html.erb index 472e32b54..f59fd4af6 100644 --- a/app/views/forum_topics/index.html.erb +++ b/app/views/forum_topics/index.html.erb @@ -22,3 +22,5 @@ <% content_for(:page_title) do %> Forum - <%= Danbooru.config.app_name %> <% end %> + +<% content_for(:html_header, auto_discovery_link_tag(:atom, forum_topics_url(:atom), title: "Forum Topics")) %> diff --git a/app/views/forum_topics/show.atom.builder b/app/views/forum_topics/show.atom.builder new file mode 100644 index 000000000..c946e9eda --- /dev/null +++ b/app/views/forum_topics/show.atom.builder @@ -0,0 +1,16 @@ +atom_feed do |feed| + feed.title(@forum_topic.title) + feed.updated(@forum_topic.try(:updated_at)) + + @forum_posts.each do |post| + feed.entry(post, published: post.created_at, updated: post.updated_at) do |entry| + entry.title("@#{post.creator.name}: #{strip_dtext(post.body).truncate(50, separator: /[[:space:]]/)}") + entry.content(format_text(post.body), type: "html") + + entry.author do |author| + author.name(post.creator.name) + author.uri(user_url(post.creator)) + end + end + end +end diff --git a/app/views/forum_topics/show.html.erb b/app/views/forum_topics/show.html.erb index 0b999223a..2f74bfefd 100644 --- a/app/views/forum_topics/show.html.erb +++ b/app/views/forum_topics/show.html.erb @@ -57,3 +57,5 @@ }); <% end %> + +<% content_for(:html_header, auto_discovery_link_tag(:atom, forum_topics_url(@forum_topic, :atom), title: @forum_topic.title)) %> diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index 0d176526f..496d85807 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -79,6 +79,7 @@