FIX: add canonical link to tags topic lists

This commit is contained in:
Neil Lalonde 2016-07-25 16:15:58 -04:00
parent 11b3b5e30a
commit ece4fa82c9
1 changed files with 8 additions and 2 deletions

View File

@ -60,6 +60,8 @@ class TagsController < ::ApplicationController
@list.prev_topics_url = construct_url_with(:prev, list_opts) @list.prev_topics_url = construct_url_with(:prev, list_opts)
@rss = "tag" @rss = "tag"
canonical_url "#{Discourse.base_url_no_prefix}#{public_send(url_method(params.slice(:category, :parent_category)))}"
if @list.topics.size == 0 && params[:tag_id] != 'none' && !Tag.where(name: @tag_id).exists? if @list.topics.size == 0 && params[:tag_id] != 'none' && !Tag.where(name: @tag_id).exists?
raise Discourse::NotFound raise Discourse::NotFound
else else
@ -224,14 +226,18 @@ class TagsController < ::ApplicationController
end end
end end
def construct_url_with(action, opts) def url_method(opts={})
method = if opts[:parent_category] && opts[:category] if opts[:parent_category] && opts[:category]
"tag_parent_category_category_#{action_name}_path" "tag_parent_category_category_#{action_name}_path"
elsif opts[:category] elsif opts[:category]
"tag_category_#{action_name}_path" "tag_category_#{action_name}_path"
else else
"tag_#{action_name}_path" "tag_#{action_name}_path"
end end
end
def construct_url_with(action, opts)
method = url_method(opts)
url = if action == :prev url = if action == :prev
public_send(method, opts.merge(prev_page_params(opts))) public_send(method, opts.merge(prev_page_params(opts)))