From 34481da6f9e2928c6f70926161967985fcec85bd Mon Sep 17 00:00:00 2001 From: Gourav Khunger Date: Tue, 9 May 2023 15:17:03 +0530 Subject: [PATCH] feat: add option to exclude authors from autopage generation (#2) release: v1.0.3 --- README.md | 10 ++++++++++ example/Gemfile.lock | 12 ++++++------ example/_config.yml | 1 + example/_data/authors.yml | 18 ++++++++++++++++++ example/_includes/header.html | 4 ++++ lib/jekyll-auto-authors/defaults.rb | 4 +++- lib/jekyll-auto-authors/main.rb | 6 +++++- lib/jekyll-auto-authors/version.rb | 2 +- 8 files changed, 48 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bd76cab..f14cd70 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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 ``` diff --git a/example/Gemfile.lock b/example/Gemfile.lock index 10ae867..e0194ac 100644 --- a/example/Gemfile.lock +++ b/example/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -91,4 +91,4 @@ DEPENDENCIES webrick BUNDLED WITH - 2.3.23 + 2.4.8 diff --git a/example/_config.yml b/example/_config.yml index 6d52a72..9c61549 100644 --- a/example/_config.yml +++ b/example/_config.yml @@ -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' diff --git a/example/_data/authors.yml b/example/_data/authors.yml index 8504d6c..9cb8c6a 100644 --- a/example/_data/authors.yml +++ b/example/_data/authors.yml @@ -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: "test1@test.com" + 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: "test2@test.com" + socials: + github: "test2" + twitter: "test2" diff --git a/example/_includes/header.html b/example/_includes/header.html index b880f5b..401364e 100644 --- a/example/_includes/header.html +++ b/example/_includes/header.html @@ -19,7 +19,11 @@
{%- for author in site.data.authors -%} + {% if author[1].exclude != true %} + {% unless site.autopages.authors.exclude contains author[0] %} Posts by {{ author[1].name | escape }} + {% endunless %} + {% endif %} {%- endfor -%}
diff --git a/lib/jekyll-auto-authors/defaults.rb b/lib/jekyll-auto-authors/defaults.rb index 8481256..18688ff 100644 --- a/lib/jekyll-auto-authors/defaults.rb +++ b/lib/jekyll-auto-authors/defaults.rb @@ -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. diff --git a/lib/jekyll-auto-authors/main.rb b/lib/jekyll-auto-authors/main.rb index 4bdd782..9026273 100644 --- a/lib/jekyll-auto-authors/main.rb +++ b/lib/jekyll-auto-authors/main.rb @@ -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] @@ -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) diff --git a/lib/jekyll-auto-authors/version.rb b/lib/jekyll-auto-authors/version.rb index 670096a..4f87707 100644 --- a/lib/jekyll-auto-authors/version.rb +++ b/lib/jekyll-auto-authors/version.rb @@ -1,5 +1,5 @@ module Jekyll module AutoAuthors - VERSION = "1.0.2" + VERSION = "1.0.3" end end \ No newline at end of file