Skip to content

Commit

Permalink
feat: add option to exclude authors from autopage generation (#2)
Browse files Browse the repository at this point in the history
release: v1.0.3
  • Loading branch information
gouravkhunger authored May 9, 2023
1 parent c0ba1b1 commit 34481da
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ autopages:
authors:
enabled: true
data: '_data/authors.yml' # Data file with the author details
exclude: [ "author1", "author2" ] # Force exclude certain authors from autopage generation
layouts:
- 'author.html' # We'll define this layout later
title: 'Posts by :author'
Expand Down Expand Up @@ -133,6 +134,15 @@ username2:
twitter: '@user2'
github: 'user2'
test:
exclude: true # Skips author from autopage generation only if they have no post assigned.
name: 'Test user'
bio: 'Bio of test user'
website: 'http://test.com'
socials:
twitter: '@test'
github: 'test'
# and so on
```

Expand Down
12 changes: 6 additions & 6 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GIT
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.1)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
colorator (1.1.0)
concurrent-ruby (1.2.2)
Expand All @@ -20,9 +20,9 @@ GEM
eventmachine (1.2.7)
ffi (1.15.5)
forwardable-extended (2.6.0)
google-protobuf (3.22.2-arm64-darwin)
google-protobuf (3.23.0-arm64-darwin)
http_parser.rb (0.8.0)
i18n (1.12.0)
i18n (1.13.0)
concurrent-ruby (~> 1.0)
jekyll (4.3.2)
addressable (~> 2.4)
Expand All @@ -40,7 +40,7 @@ GEM
safe_yaml (~> 1.0)
terminal-table (>= 1.8, < 4.0)
webrick (~> 1.7)
jekyll-auto-authors (1.0.2)
jekyll-auto-authors (1.0.3)
jekyll (>= 3.0.0)
jekyll-paginate-v2 (>= 3.0.0)
jekyll-feed (0.17.0)
Expand Down Expand Up @@ -71,7 +71,7 @@ GEM
rexml (3.2.5)
rouge (4.1.0)
safe_yaml (1.0.5)
sass-embedded (1.60.0-arm64-darwin)
sass-embedded (1.62.1-arm64-darwin)
google-protobuf (~> 3.21)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
Expand All @@ -91,4 +91,4 @@ DEPENDENCIES
webrick

BUNDLED WITH
2.3.23
2.4.8
1 change: 1 addition & 0 deletions example/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ autopages:
authors:
enabled: true
data: '_data/authors.yml' # Data file with the author details
exclude: ["test2", "abc"] # Force skip autopages for author even if they have posts assigned
layouts:
- 'author.html' # We'll define this layout later
title: 'Posts by :author'
Expand Down
18 changes: 18 additions & 0 deletions example/_data/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@ janedoe:
socials:
github: "jane-doe"
twitter: "jane_doe"

test1:
exclude: true # testing the exclude attribute
name: "test1"
bio: "Test is a demo author 1"
email: "[email protected]"
socials:
github: "test1"
twitter: "test1"

# test2 is excluded via exclude attribute for authors autopage config in _config.yml
test2:
name: "test2"
bio: "Test is a demo author 2"
email: "[email protected]"
socials:
github: "test2"
twitter: "test2"
4 changes: 4 additions & 0 deletions example/_includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

<div class="trigger">
{%- for author in site.data.authors -%}
{% if author[1].exclude != true %}
{% unless site.autopages.authors.exclude contains author[0] %}
<a class="page-link" href="/author/{{ author[0] | relative_url }}">Posts by {{ author[1].name | escape }}</a>
{% endunless %}
{% endif %}
{%- endfor -%}
</div>
</nav>
Expand Down
4 changes: 3 additions & 1 deletion lib/jekyll-auto-authors/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ module AutoAuthors
"data" => "_data/authors.yml", # The data file inside _data/ folder that contains author information.
"layouts" => ["authors.html"], # The layout file inside _layouts/ folder to use for the author pages.

"exclude" => [], # The list of authors to **force** skip processing an autopage for.

"title" => "Posts by :author", # :author is replaced by author name.
"permalink" => "/author/:author", # :author is customizable elements
"permalink" => "/author/:author", # :author is customizable elements.

"slugify" => {
"mode" => "none", # [raw, default, pretty, ascii or latin], none gives back the same string.
Expand Down
6 changes: 5 additions & 1 deletion lib/jekyll-auto-authors/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def generate(site)
# 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 |
# Force skip excluded authors from autopage generation
return if autopage_author_config["exclude"].include?(author)

if !autopage_author_config["data"].nil?
author_data = YAML::load(File.read(autopage_author_config["data"]))[author_original_name]

Expand Down Expand Up @@ -71,7 +74,8 @@ def generate(site)
author_data = YAML::load(File.read(authors_config["data"]))

author_data.each do | author, data |
if !finished_pages.include?(author)
# The exclude attribute ignores authors from autopage generation unless they have a post assigned.
if !finished_pages.include?(author) and !data["exclude"]
# 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)
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.2"
VERSION = "1.0.3"
end
end

0 comments on commit 34481da

Please sign in to comment.