Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
Make data file optional, update README.md and bump version
  • Loading branch information
gouravkhunger committed Apr 11, 2022
1 parent 7504842 commit 993bd37
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ autopages:

That's it for the autopages and pagination configuration.

For an example, let's take a minimal `_data/authors.yml` file. Though usernames should be defined at the top level, the plugin provides you the freedom to define particular author's data as you want.
### Optional

Once you define the usernames, all the data for an author is passed on to the liquid template so you can render it as you wish!
You might want to render additional details for each author other than the username.

For an example, let's take a minimal `_data/authors.yml` file. Usernames should be defined at the top level. The plugin provides you the freedom to define particular author's data as you want.

Once you define the usernames, all the data for an author is passed on to the liquid template inside `page.pagination.author_data` variable so you can render it as you wish!

```yml
username1:
Expand All @@ -121,14 +125,16 @@ username2:
# and so on
```

The data for the user is passed on to the template, inside the `page.pagination.author_data` variable.

Let's define a basic template for the `author.html` layout so you get a gist of how to use it:

```html
<!DOCTYPE html>
<html lang="en">
<!-- This has the username of author. The one that you set with "author: name" in front-matter-->
{% assign author_username = page.pagination.author %}
<!-- Use page.pagination.author_data only if you have data file setup correctly -->
{% assign author = page.pagination.author_data %}
<!--
Now you can use the author variable anyhow.
Expand Down
9 changes: 8 additions & 1 deletion lib/jekyll-auto-authors/authorAutoPage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ def initialize(site, base, autopage_config, pagination_config, layout_name, auth
# Construct the lambda function to set the config values this
# function receives the pagination config hash and manipulates it.
set_autopage_data_lambda = lambda do | in_config |
author_data = YAML::load(File.read(autopage_config["data"]))
in_config["author"] = author

if autopage_config["data"].nil?
return
end

# if a data file containing authors is not nil, transfer it to paginator object
# so that it can be used in the pagination template
author_data = YAML::load(File.read(autopage_config["data"]))
in_config["author_data"] = author_data[author_name]
end

Expand Down
9 changes: 5 additions & 4 deletions lib/jekyll-auto-authors/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ 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 |
author_data = YAML::load(File.read(autopage_author_config["data"]))[author_original_name]
if !autopage_author_config["data"].nil?
author_data = YAML::load(File.read(autopage_author_config["data"]))[author_original_name]

if author_data.nil?
Jekyll.logger.warn "Author Pages:", "Author data for "#{author_original_name}" not found. Skipping author page..."
return
if author_data.nil?
Jekyll.logger.warn "Author Pages:", "Author data for '#{author_original_name}' not found. Page will be generated without data."
end
end

site.pages << AuthorAutoPage.new(site, site.dest, autopage_author_config, pagination_config, layout_name, author, author_original_name)
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.0"
VERSION = "1.0.1"
end
end

0 comments on commit 993bd37

Please sign in to comment.