Fix #1883: Add <link> elements for all paginated pages.
Add <link rel="prev"> and <link rel="next"> elements to most pages with pagination. This should work on all index pages, but it won't work for things like pool or forum topic show pages. Also remove the <link rel="top"> element (wasn't useful, was just a link back to the root url).
This commit is contained in:
@@ -13,20 +13,6 @@ module PostsHelper
|
||||
params[:tags] =~ /order:rank/ || params[:action] =~ /searches|viewed/
|
||||
end
|
||||
|
||||
def next_page_url
|
||||
current_page = (params[:page] || 1).to_i
|
||||
url_for(nav_params_for(current_page + 1)).html_safe
|
||||
end
|
||||
|
||||
def prev_page_url
|
||||
current_page = (params[:page] || 1).to_i
|
||||
if current_page >= 2
|
||||
url_for(nav_params_for(current_page - 1)).html_safe
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def missed_post_search_count_js
|
||||
return unless post_search_counts_enabled?
|
||||
return unless params[:ms] == "1" && @post_set.post_count == 0 && @post_set.is_single_tag?
|
||||
|
||||
@@ -60,6 +60,30 @@ module PaginationExtension
|
||||
end
|
||||
end
|
||||
|
||||
def prev_page
|
||||
return nil if is_first_page?
|
||||
|
||||
if paginator_mode == :numbered
|
||||
current_page - 1
|
||||
elsif paginator_mode == :sequential_before
|
||||
"a#{records.first.id}"
|
||||
elsif paginator_mode == :sequential_after
|
||||
"b#{records.last.id}"
|
||||
end
|
||||
end
|
||||
|
||||
def next_page
|
||||
return nil if is_last_page?
|
||||
|
||||
if paginator_mode == :numbered
|
||||
current_page + 1
|
||||
elsif paginator_mode == :sequential_before
|
||||
"b#{records.last.id}"
|
||||
elsif paginator_mode == :sequential_after
|
||||
"a#{records.first.id}"
|
||||
end
|
||||
end
|
||||
|
||||
# XXX Hack: in sequential pagination we fetch one more record than we
|
||||
# need so that we can tell when we're on the first or last page. Here
|
||||
# we override a rails internal method to discard that extra record. See
|
||||
|
||||
@@ -2,8 +2,17 @@
|
||||
<html>
|
||||
<head>
|
||||
<title><%= page_title %></title>
|
||||
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
|
||||
|
||||
<% if @current_item.try(:prev_page) %>
|
||||
<%= tag.link rel: "prev", href: url_for(nav_params_for(@current_item.prev_page)) %>
|
||||
<% end %>
|
||||
|
||||
<% if @current_item.try(:next_page) %>
|
||||
<%= tag.link rel: "next", href: url_for(nav_params_for(@current_item.next_page)) %>
|
||||
<% end %>
|
||||
|
||||
<%= csrf_meta_tag %>
|
||||
<% unless CurrentUser.disable_responsive_mode? %>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
|
||||
@@ -10,11 +10,6 @@
|
||||
<% atom_feed_tag "Posts: #{@post_set.tag_string}", posts_url(tags: @post_set.tag_string, format: :atom) %>
|
||||
<% end %>
|
||||
|
||||
<%= tag.link href: posts_path(format: "atom", tags: params[:tags]), rel: "alternate", title: "ATOM", type: "application/atom+xml" %>
|
||||
<%= tag.link rel: "next", href: next_page_url %>
|
||||
<% if prev_page_url %>
|
||||
<%= tag.link rel: "prev", href: prev_page_url %>
|
||||
<% end %>
|
||||
<%= missed_post_search_count_js %>
|
||||
|
||||
<% if @post_set.hide_from_crawler? %>
|
||||
|
||||
Reference in New Issue
Block a user