mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Add previous page link for crawlers
This commit is contained in:
@ -46,7 +46,8 @@ class ListController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
|
list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")
|
||||||
list.more_topics_url = construct_url_with(list_opts)
|
list.more_topics_url = construct_next_url_with(list_opts)
|
||||||
|
list.prev_topics_url = construct_prev_url_with(list_opts)
|
||||||
if Discourse.anonymous_filters.include?(filter)
|
if Discourse.anonymous_filters.include?(filter)
|
||||||
@description = SiteSetting.site_description
|
@description = SiteSetting.site_description
|
||||||
@rss = filter
|
@rss = filter
|
||||||
@ -92,8 +93,8 @@ class ListController < ApplicationController
|
|||||||
guardian.ensure_can_see_private_messages!(target_user.id) unless action == :topics_by
|
guardian.ensure_can_see_private_messages!(target_user.id) unless action == :topics_by
|
||||||
list = generate_list_for(action.to_s, target_user, list_opts)
|
list = generate_list_for(action.to_s, target_user, list_opts)
|
||||||
url_prefix = "topics" unless action == :topics_by
|
url_prefix = "topics" unless action == :topics_by
|
||||||
url = construct_url_with(list_opts, url_prefix)
|
list.more_topics_url = url_for(construct_next_url_with(list_opts, url_prefix))
|
||||||
list.more_topics_url = url_for(url)
|
list.prev_topics_url = url_for(construct_prev_url_with(list_opts, url_prefix))
|
||||||
respond(list)
|
respond(list)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -163,7 +164,8 @@ class ListController < ApplicationController
|
|||||||
top_options[:per_page] = SiteSetting.topics_per_period_in_top_page
|
top_options[:per_page] = SiteSetting.topics_per_period_in_top_page
|
||||||
user = list_target_user
|
user = list_target_user
|
||||||
list = TopicQuery.new(user, top_options).public_send("list_top_#{period}")
|
list = TopicQuery.new(user, top_options).public_send("list_top_#{period}")
|
||||||
list.more_topics_url = construct_url_with(top_options)
|
list.more_topics_url = construct_next_url_with(top_options)
|
||||||
|
list.prev_topics_url = construct_prev_url_with(top_options)
|
||||||
respond(list)
|
respond(list)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -202,8 +204,19 @@ class ListController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def next_page_params(opts = nil)
|
def next_page_params(opts = nil)
|
||||||
|
page_params(opts).merge(page: params[:page].to_i + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def prev_page_params(opts = nil)
|
||||||
|
page_params(opts).merge(page: params[:page].to_i > 1 ? (params[:page].to_i - 1) : 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def page_params(opts = nil)
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
route_params = { format: 'json', page: params[:page].to_i + 1 }
|
route_params = {format: 'json'}
|
||||||
route_params[:category] = @category.slug if @category
|
route_params[:category] = @category.slug if @category
|
||||||
route_params[:parent_category] = @category.parent_category.slug if @category && @category.parent_category
|
route_params[:parent_category] = @category.parent_category.slug if @category && @category.parent_category
|
||||||
route_params[:sort_order] = opts[:sort_order] if opts[:sort_order].present?
|
route_params[:sort_order] = opts[:sort_order] if opts[:sort_order].present?
|
||||||
@ -211,8 +224,6 @@ class ListController < ApplicationController
|
|||||||
route_params
|
route_params
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def set_category
|
def set_category
|
||||||
slug_or_id = params.fetch(:category)
|
slug_or_id = params.fetch(:category)
|
||||||
parent_slug_or_id = params[:parent_category]
|
parent_slug_or_id = params[:parent_category]
|
||||||
@ -269,11 +280,16 @@ class ListController < ApplicationController
|
|||||||
TopicQuery.new(current_user, opts).send("list_#{action}", target_user)
|
TopicQuery.new(current_user, opts).send("list_#{action}", target_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def construct_url_with(opts, url_prefix = nil)
|
def construct_next_url_with(opts, url_prefix = nil)
|
||||||
method = url_prefix.blank? ? "#{action_name}_path" : "#{url_prefix}_#{action_name}_path"
|
method = url_prefix.blank? ? "#{action_name}_path" : "#{url_prefix}_#{action_name}_path"
|
||||||
public_send(method, opts.merge(next_page_params(opts)))
|
public_send(method, opts.merge(next_page_params(opts)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def construct_prev_url_with(opts, url_prefix = nil)
|
||||||
|
method = url_prefix.blank? ? "#{action_name}_path" : "#{url_prefix}_#{action_name}_path"
|
||||||
|
public_send(method, opts.merge(prev_page_params(opts)))
|
||||||
|
end
|
||||||
|
|
||||||
def generate_top_lists(options)
|
def generate_top_lists(options)
|
||||||
top = TopLists.new
|
top = TopLists.new
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ class TopicList
|
|||||||
include ActiveModel::Serialization
|
include ActiveModel::Serialization
|
||||||
|
|
||||||
attr_accessor :more_topics_url,
|
attr_accessor :more_topics_url,
|
||||||
|
:prev_topics_url,
|
||||||
:draft,
|
:draft,
|
||||||
:draft_key,
|
:draft_key,
|
||||||
:draft_sequence,
|
:draft_sequence,
|
||||||
|
@ -4,10 +4,16 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if @list.topics.length > 0 %>
|
<p>
|
||||||
<p><a href="<%= @list.more_topics_url.sub('.json?','?') %>" rel="next"><%= t 'next_page'%></a></p>
|
<% if params[:page].to_i > 1 %>
|
||||||
|
<a href="<%= @list.prev_topics_url.sub('.json?','?') %>" rel="prev" style="margin-right: 30px;"><%= t 'prev_page'%></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if @list.topics.length > 0 %>
|
||||||
|
<a href="<%= @list.more_topics_url.sub('.json?','?') %>" rel="next"><%= t 'next_page'%></a>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p><%= t 'powered_by_html' %></p>
|
<p><%= t 'powered_by_html' %></p>
|
||||||
|
|
||||||
<% if @rss %>
|
<% if @rss %>
|
||||||
|
@ -76,6 +76,7 @@ en:
|
|||||||
invalid_characters: "contains invalid characters"
|
invalid_characters: "contains invalid characters"
|
||||||
is_invalid: "is invalid; try to be a little more descriptive"
|
is_invalid: "is invalid; try to be a little more descriptive"
|
||||||
next_page: "next page →"
|
next_page: "next page →"
|
||||||
|
prev_page: "← previous page"
|
||||||
page_num: "Page %{num}"
|
page_num: "Page %{num}"
|
||||||
by: "By"
|
by: "By"
|
||||||
topics_in_category: "Topics in the '%{category}' category"
|
topics_in_category: "Topics in the '%{category}' category"
|
||||||
|
Reference in New Issue
Block a user