如何在单页中为 two/multiple 分页做 SEO link 标记?

How to do SEO link tag for two/multiple pagination in single page?

我在 rails 4 中写了一个应用程序。在那个应用程序中,我在单个页面中有两个分页 'x (page)'。 url.

中的组和页面等参数
Url looks like:
https://example.com/x?page=2&group=4
Initial page:
https://example.com/x
If pagination page params, then
https://example.com/x?page=2
If paginating groups params, then
https://example.com/x?group=2
If paginating both,then
https://example.com/x?page=2&group=2
and so on.

我正在使用 Kaminari gem 进行分页。在那个 gem 中,我使用了 rel_next_prev_link_tags 助手来显示 prev/next 的 link 标签。

如何显示多个分页的 link 个标签?

您不能向搜索引擎显示二维分页。在您的情况下,它看起来更像是 grouping/categorizing + 分页。

喜欢:

Group 1 pages:
https://example.com/x
https://example.com/x?page=2
https://example.com/x?page=3
Group 2 pages:
https://example.com/x?group=2
https://example.com/x?page=2&group=2
https://example.com/x?page=3&group=2

等等

我创建了一个自定义助手来处理 URL 并基于参数创建分类的 link 标签。例如:在视图中,

pagination_link_tags(@pages,'page') for pages pagination
pagination_link_tags(@groups,'group') for groups pagination

def pagination_link_tags(collection,pagination_params)
    output = []
    link = '<link rel="%s" href="%s"/>'
    url = request.fullpath
    uri = Addressable::URI.parse(url)
    parameters = uri.query_values
    # Update the params based on params name and create a link for SEO
    if parameters.nil?
      if collection.next_page
        parameters = {}
        parameters["#{pagination_params}"] = "#{collection.next_page}"
        uri.query_values = parameters
        output << link % ["next", uri.to_s]
      end
    else
      if collection.previous_page
        parameters["#{pagination_params}"] = "#{collection.previous_page}"
        uri.query_values = parameters
        output << link % ["prev", uri.to_s]
      end
      if collection.next_page
        parameters["#{pagination_params}"] = "#{collection.next_page}"
        uri.query_values = parameters
        output << link % ["next", uri.to_s]
      end
    end
    output.join("\n").html_safe
  end