Skip to content

Commit

Permalink
Update Authorbox to use author data
Browse files Browse the repository at this point in the history
This supports multiple authors, and avoids using the now-deprecated
[Author] block in Hugo.toml

Fixes Issue Vimux#382
  • Loading branch information
EliRibble committed Nov 8, 2024
1 parent 13e04b3 commit c04d768
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ googleAnalytics = "" # DEPRECATED! Use .Services.googleAnalytics.ID
[services.googleAnalytics]
ID = "" # Enable Google Analytics by entering your tracking ID

[Author] # Used in authorbox
name = "John Doe"
bio = "John Doe's true identity is unknown. Maybe he is a successful blogger or writer. Nobody knows it."
avatar = "img/avatar.png"

[Params]
description = "John Doe's Personal blog about everything" # Site description. Used in meta description
copyright = "John Doe" # Footer copyright holder, otherwise will use site title
Expand Down Expand Up @@ -159,6 +154,22 @@ googleAnalytics = "" # DEPRECATED! Use .Services.googleAnalytics.ID
For more information about all available standard configuration settings, please read
[All Hugo Configuration Settings](https://gohugo.io/getting-started/configuration/#all-configuration-settings).

### Authorbox

Create a file at `data/authors/earnestfreeguy.json`. Add the following contents to it:

```json
{
"name": "Earnest Freeguy",
"avatar": "img/avatar-earnestfreeguy.png",
"bio": "Earnest cares a lot about Liberty. He likes to spend his time blogging, drinking fair-trade coffee, and eating his cats.",
}
```

Then make sure to include "author: earnestfreeguy" in the Front Matter for a given post.
The Authorbox will use `earnestfreeguy` to look up the data entry, then pull the
various values for that author into the Authorbox.

### Front Matter example

```yaml
Expand Down
49 changes: 30 additions & 19 deletions layouts/partials/authorbox.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
{{- if .Param "authorbox" }}
<div class="authorbox clearfix">
{{- if and (not .Site.Author.avatar) (not .Site.Author.name) (not .Site.Author.bio) }}
<p class="authorbox__warning">
<strong>WARNING:</strong> Authorbox is activated, but [Author] parameters are not specified.
</p>
{{- end }}
{{- with .Site.Author.avatar }}
<figure class="authorbox__avatar">
<img alt="{{ $.Site.Author.name }} avatar" src="{{ $.Site.Author.avatar | relURL }}" class="avatar" height="90" width="90">
</figure>
{{- end }}
{{- with .Site.Author.name }}
<div class="authorbox__header">
<span class="authorbox__name">{{ T "authorbox_name" (dict "Name" .) }}</span>
</div>
{{- end }}
{{- with .Site.Author.bio }}
<div class="authorbox__description">
{{ . | markdownify }}
</div>
{{ $author := default .Site.Author (index .Site.Data.authors (.Params.author | default "default")) }}
{{- with $author }}
{{- if (not $author.avatar) }}
<p class="authorbox__warning">
<strong>WARNING:</strong> Authorbox is activated, but author is missing the "avatar" property.
</p>
{{- end }}
{{- if (not $author.name) }}
<p class="authorbox__warning">
<strong>WARNING:</strong> Authorbox is activated, but author is missing the "name" property.
if (not $author.bio) }}
<p class="authorbox__warning">
<strong>WARNING:</strong> Authorbox is activated, but author is missing the "bio" property.
</p>
{{- end }}
{{- with $author.avatar }}
<figure class="authorbox__avatar">
<img alt="{{ $author.name }} avatar" src="{{ $author.avatar | relURL }}" class="avatar" height="90" width="90">
</figure>
{{- end }}
{{- with $author.name }}
<div class="authorbox__header">
<span class="authorbox__name">{{ T "authorbox_name" (dict "Name" .) }}</span>
</div>
{{- end }}
{{- with $author.bio }}
<div class="authorbox__description">
{{ . | markdownify }}
</div>
{{- end }}
{{- end }}
</div>
{{- end }}

0 comments on commit c04d768

Please sign in to comment.