Skip to content

Feature: Introductory text for autopages, etc. #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/jekyll-paginate-v2/generator/paginationModel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ def paginate(template, config, site_title, all_posts, all_tags, all_categories,
end
end

intro = nil
if intro_file = config['intro']
using_posts.delete_if { |post| post.basename =~ /(^|-)#{intro_file}$/ && intro = post }
# Override inherited defaults
intro.data['layout'] = 'none' if !intro.nil? && !intro.data.has_key?('layout')
end

# Calculate the max number of pagination-pages based on the configured per page value
total_pages = Utils.calculate_number_of_pages(using_posts, config['per_page'])

Expand Down Expand Up @@ -289,8 +296,10 @@ def paginate(template, config, site_title, all_posts, all_tags, all_categories,
end
paginated_page_url = File.join(first_index_page_url, paginated_page_url)

pager_intro = cur_page_nr == 1 ? intro : nil

# 3. Create the pager logic for this page, pass in the prev and next page numbers, assign pager to in-memory page
newpage.pager = Paginator.new( config['per_page'], first_index_page_url, paginated_page_url, using_posts, cur_page_nr, total_pages, indexPageName, indexPageExt)
newpage.pager = Paginator.new( config['per_page'], first_index_page_url, paginated_page_url, using_posts, cur_page_nr, total_pages, indexPageName, indexPageExt, pager_intro)

# Create the url for the new page, make sure we prepend any permalinks that are defined in the template page before
if newpage.pager.page_path.end_with? '/'
Expand Down
11 changes: 7 additions & 4 deletions lib/jekyll-paginate-v2/generator/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module PaginateV2::Generator
class Paginator
attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
:previous_page, :previous_page_path, :next_page, :next_page_path, :page_path, :page_trail,
:first_page, :first_page_path, :last_page, :last_page_path
:first_page, :first_page_path, :last_page, :last_page_path, :intro

def page_trail
@page_trail
Expand All @@ -19,7 +19,7 @@ def page_trail=(page_array)

# Initialize a new Paginator.
#
def initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages, default_indexpage, default_ext)
def initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages, default_indexpage, default_ext, intro = nil)
@page = cur_page_nr
@per_page = config_per_page.to_i
@total_pages = num_pages
Expand Down Expand Up @@ -60,6 +60,8 @@ def initialize(config_per_page, first_index_page_url, paginated_page_url, posts,
@first_page_path = Utils.format_page_number(first_index_page_url, 1, @total_pages)
@last_page = @total_pages
@last_page_path = Utils.format_page_number(paginated_page_url, @total_pages, @total_pages)

@intro = intro
end

# Convert this Paginator's data to a Hash suitable for use by Liquid.
Expand All @@ -81,7 +83,8 @@ def to_liquid
'first_page_path' => first_page_path,
'last_page' => last_page,
'last_page_path' => last_page_path,
'page_trail' => page_trail
'page_trail' => page_trail,
'intro' => intro
}
end

Expand All @@ -108,4 +111,4 @@ def to_liquid
end #class PageTrail

end # module PaginateV2
end # module Jekyll
end # module Jekyll