Skip to content

Commit

Permalink
Cleaner paginated page url (#491)
Browse files Browse the repository at this point in the history
* Don't add index.html to end of paginated page URL

* Fix issue with dirname

* fix formatting
  • Loading branch information
jaredcwhite authored Feb 18, 2022
1 parent 13ce4a4 commit 0d03040
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
13 changes: 1 addition & 12 deletions bridgetown-paginate/lib/bridgetown-paginate/pagination_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,7 @@ def paginate(template, config, site_title, documents_payload)
index_page_ext
)

# Create the url for the new page, make sure we prepend any permalinks
# that are defined in the template page before
if newpage.paginator.page_path.end_with? "/"
newpage.set_url(File.join(newpage.paginator.page_path, index_page_with_ext))
elsif newpage.paginator.page_path.end_with? index_page_ext.to_s
# Support for direct .html files
newpage.set_url(newpage.paginator.page_path)
else
# Support for extensionless permalinks
newpage.set_url(newpage.paginator.page_path + index_page_ext.to_s)
end

newpage.set_url(newpage.paginator.page_path)
newpage.data["permalink"] = newpage.paginator.page_path if template.data["permalink"]

# Transfer the title across to the new page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize(page_to_copy, cur_page_nr, total_pages, index_pageandext, templat
# rubocop:disable Naming/AccessorMethodName
def set_url(url_value)
@path = url_value.delete_prefix "/"
@dir = File.dirname(@path)
@dir = @path.ends_with?("/") ? @path : File.dirname(@path)
@url = url_value
end
# rubocop:enable Naming/AccessorMethodName
Expand Down
4 changes: 2 additions & 2 deletions bridgetown-paginate/lib/bridgetown-paginate/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def initialize( # rubocop:todo Metrics/AbcSize
# Ensure that the current page has correct extensions if needed
this_page_url = Utils.ensure_full_path(
@page == 1 ? first_index_page_url : paginated_page_url,
!default_indexpage || default_indexpage.empty? ? "index" : default_indexpage,
!default_ext || default_ext.empty? ? ".html" : default_ext
default_indexpage || "",
default_ext || ""
)

# To support customizable pagination pages we attempt to explicitly
Expand Down

0 comments on commit 0d03040

Please sign in to comment.