Skip to content

Commit

Permalink
Initial support for 'intro.md'
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrado committed Jan 21, 2018
1 parent d3aaef7 commit 75e29b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 9 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,12 @@ 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 }
intro.data['layout'] = 'none' if !intro.nil?
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 +295,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

0 comments on commit 75e29b4

Please sign in to comment.