Skip to content

Commit

Permalink
feat: generate autopages for authors without posts but defined author…
Browse files Browse the repository at this point in the history
… data

release v1.0.2 🎉
  • Loading branch information
gouravkhunger committed Jul 14, 2022
1 parent c36cb72 commit 2c95fdf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions lib/jekyll-auto-authors/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ def generate(site)
return
end

Jekyll.logger.info "Author Pages:", "Generating..."

# Lambda that created the author page for a given author.
# will be passed to PaginateV2::Autopages for processing.
createauthorpage_lambda = lambda do | autopage_author_config, pagination_config, layout_name, author, author_original_name |
Expand Down Expand Up @@ -59,6 +57,31 @@ def generate(site)
autopage_config, pagination_config, posts_to_use, "authors", "author", createauthorpage_lambda
)

# Set of authors for whom autopages have been created
finished_pages = Set.new

posts_to_use.each do | post |
next if post.data["author"].nil? || finished_pages.include?(post.data["author"])
finished_pages << post.data["author"]
end

if !authors_config["data"].nil?
# if a data file containing authors is not nil, then iterate through the specified
# authors to build author pages for them, even if they don't have posts yet.
author_data = YAML::load(File.read(authors_config["data"]))

author_data.each do | author, data |
if !finished_pages.include?(author)
# create pages for pending authors with specified layouts
authors_config['layouts'].each do | layout_name |
createauthorpage_lambda.call(authors_config, pagination_config, layout_name, author, author)
end

finished_pages << author
end
end
end

# Now auto pages for authors have been created, we can generate the pagination logic.

# Further logic is mostly similar as PaginateV2::Generator::PaginationModel#paginate(), but we need
Expand Down Expand Up @@ -133,7 +156,8 @@ def generate(site)

pagination_posts.sort!{ |a,b|
PaginateV2::Generator::Utils.sort_values(
PaginateV2::Generator::Utils.sort_get_post_data(a.data, sort_field), PaginateV2::Generator::Utils.sort_get_post_data(b.data, sort_field)
PaginateV2::Generator::Utils.sort_get_post_data(a.data, sort_field),
PaginateV2::Generator::Utils.sort_get_post_data(b.data, sort_field)
)
}

Expand Down Expand Up @@ -256,6 +280,7 @@ def generate(site)
end
end

Jekyll.logger.info "Author Pages:", "Generated autopages for #{finished_pages.size} author(s)"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-auto-authors/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Jekyll
module AutoAuthors
VERSION = "1.0.1"
VERSION = "1.0.2"
end
end

0 comments on commit 2c95fdf

Please sign in to comment.