Added multiple author support

This commit is contained in:
Nuno Coração 2022-10-13 23:29:04 +01:00
parent 6a3c4f9c21
commit 2677435117
25 changed files with 275 additions and 6 deletions

View file

@ -21,6 +21,7 @@ Blowfish is designed to be a powerful, lightweight theme for [Hugo](https://gohu
- Firebase integration to support dynamic data
- Views count & like mechanism
- Multiple homepage layouts
- Support for multiple authors
- Flexible with any content types, taxonomies and menus
- Multilingual content support inlcuding support for RTL languages
- Ability to link to posts on third-party websites

View file

@ -1530,6 +1530,10 @@ select {
margin-top: 0.1rem;
}
.mt-4 {
margin-top: 1rem;
}
.\!mt-0 {
margin-top: 0px !important;
}

BIN
assets/img/author2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
assets/img/nuno_avatar.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

View file

@ -14,6 +14,11 @@ buildFuture = false
# googleAnalytics = "G-XXXXXXXXX"
[taxonomies]
tag = "tags"
category = "categories"
author = "authors"
[sitemap]
changefreq = 'daily'
filename = 'sitemap.xml'

View file

@ -46,6 +46,7 @@ enableCodeCopy = true
showReadingTime = true
showTableOfContents = true
showTaxonomies = false
showAuthorsBadges = false
showWordCount = true
showSummary = true
sharingLinks = [ "linkedin", "twitter", "whatsapp", "pinterest", "reddit", "facebook", "email"]

View file

@ -15,6 +15,11 @@ buildFuture = false
googleAnalytics = "G-PEDMYR1V0K"
[taxonomies]
tag = "tags"
category = "categories"
author = "authors"
[sitemap]
changefreq = 'daily'
filename = 'sitemap.xml'

View file

@ -46,6 +46,7 @@ mainSections = ["docs"]
showReadingTime = true
showTableOfContents = true
showTaxonomies = true
showAuthorsBadges = true
showWordCount = false
showSummary = true
sharingLinks = [ "linkedin", "twitter", "whatsapp", "pinterest", "reddit", "facebook", "email"]

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>defaultPathExtensions</key>
<string>md</string>
<key>enforceFencedCodeBlocks</key>
<false/>
<key>sheetFormat</key>
<string>foreign</string>
<key>useInlineLinks</key>
<false/>
</dict>
</plist>

View file

@ -0,0 +1,10 @@
---
title: "Authors Taxonomy Listing Example"
date: 2022-10-12
draft: false
description: "Turn on thumbnails for your articles."
tags: ["thumbnail", "sample"]
summary: "A quick example of how to start using Thumbnails in your artciles."
---
A quick example of how to start using Thumbnails in your articles.

View file

@ -0,0 +1,5 @@
---
title: "Nuno Coração"
---
Nuno's awesome dummy bio.

View file

@ -0,0 +1,5 @@
---
title: "Dummy Second Author"
---
Dummy Second Author's awesome dummy bio.

View file

@ -156,6 +156,7 @@ Many of the article defaults here can be overridden on a per article basis by sp
|`article.showReadingTime`|`true`|Whether or not article reading times are displayed.|
|`article.showTableOfContents`|`false`|Whether or not the table of contents is displayed on articles.|
|`article.showTaxonomies`|`false`|Whether or not the taxonomies related to this article are displayed.|
|`article.showAuthorsBadges`|`false`|Whether the `authors` taxonomies are are displayed in the article or list header. This requires the setup of `multiple authors` and the `authors` taxonomy. Check [this page]({{< ref "multi-author" >}}) for more details on how to configure that feature.|
|`article.showWordCount`|`false`|Whether or not article word counts are displayed.|
|`article.showComments`|`false`|Whether or not the [comments partial]({{< ref "partials#comments" >}}) is included after the article footer.|
|`article.sharingLinks`|_Not set_|Which sharing links to display at the end of each article. When not provided, or set to `false` no links will be displayed.|

View file

@ -23,7 +23,9 @@ Front matter parameter default values are inherited from the theme's [base confi
|`menu`|_Not set_|When a value is provided, a link to this article will appear in the named menus. Valid values are `main` or `footer`.|
|`robots`|_Not set_|String that indicates how robots should handle this article. If set, it will be output in the page head. Refer to [Google's docs](https://developers.google.com/search/docs/advanced/robots/robots_meta_tag#directives) for valid values.|
|`sharingLinks`|`article.sharingLinks`|Which sharing links to display at the end of this article. When not provided, or set to `false` no links will be displayed.|
|`showAuthor`|`article.showAuthor`|Whether or not the author box is displayed in the article footer.|
|`showAuthor`|`article.showAuthor`|Whether or not the author box for the deafult author is displayed in the article footer.|
|`authors`|_Not set_|Array of values for authors, if set it overrides `showAuthor` settings for page or site. Used on the multiple authors feature, check [this page]({{< ref "multi-author" >}}) for more details on how to configure that feature.|
|`showAuthorsBadges`|`article.showAuthorsBadges`|Whether the `authors` taxonomies are are displayed in the article or list header. This requires the setup of `multiple authors` and the `authors` taxonomy. Check [this page]({{< ref "multi-author" >}}) for more details on how to configure that feature.|
|`showBreadcrumbs`|`article.showBreadcrumbs` or `list.showBreadcrumbs`|Whether the breadcrumbs are displayed in the article or list header.|
|`showDate`|`article.showDate`|Whether or not the article date is displayed. The date is set using the `date` parameter.|
|`showDateUpdated`|`article.showDateUpdated`|Whether or not the date the article was updated is displayed. The date is set using the `lastmod` parameter.|

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 KiB

View file

@ -0,0 +1,100 @@
---
title: "Multiple Authors"
date: 2020-08-10
draft: false
description: "Configure multiple authors for your articles."
slug: "multi-author"
tags: ["authors", "config", "docs"]
showAuthor: true
authors:
- "nunocoracao"
showAuthorsBadges : false
---
Some websites have more than one author contributing with content and therefore require more than a single default author across the entire website. For those use-cases, Blowfish allows users to extend the list of authors using the multiple authors feature.
To keep everything backwards compatible, this feature only allows the definition of extra authors and does not change in any way the previous author functionality which is used via config files.
## Create Authors
The first step to create new authors is to set up a new folder in `./data/authors`. Then you can simply add new `json` files inside, one for each new author. The name of the file will be the `key` for that author when referencing it in your articles.
As an example, lets create a file called `nunocoracao.json` within `./data/authors`. The contents of the file should be similar to the ones below. `name`, `image`, `bio`, and `social` are the 4 parameters supported right for authors. They mimic the configurations available for the default author in the config files.
_Note: the key in the social object will be used to fetch one of the themes icons, feel free to use any of the icons available in your setup._
```json
{
"name": "Nuno Coração",
"image" : "img/nuno_avatar.jpg",
"bio": "Theme Creator",
"social": {
"linkedin": "https://linkedin.com/in/nunocoracao",
"twitter": "https://twitter.com/nunocoracao",
"instagram": "https://instagram.com/nunocoracao",
"medium": "https://medium.com/@nunocoracao",
"github": "https://github.com/nunocoracao",
"goodreads": "http://goodreads.com/nunocoracao",
"keybase": "https://keybase.io/nunocoracao",
"reddit": "https://reddit.com/user/nunoheart"
}
}
```
## Reference Authors in Articles
Now that you created one author, the next step is to reference it in one or more articles. In the example below, we reference the author created in the previous step using its `key`.
This will render an extra author using the data provided in the `json` file. This feature does not change in any way the default author configured for the overall site, and therefore, you can control both separately. Using the `showAuthor` parameter, you can configure whether to show the default author, that is the normal use-case for a single author blog. The new `authors` front-matter parameter allows you to define authors specifically to an article, and they will be rendered independently of the configurations for the default site author.
```md
---
title: "Multiple Authors"
date: 2020-08-10
draft: false
description: "Configure multiple authors for your articles."
slug: "multi-author"
tags: ["authors", "config", "docs"]
showAuthor: true
authors:
- "nunocoracao"
showAuthorsBadges : false
---
```
In the example, which matches the markdown of the current page, both the default author and the new one will be displayed. You can scroll now to see the outcome.
## Create the Authors Taxonomy
To get lists of articles for each of your authors you can configure the `authors` taxonomy, which opens up some more configurations that might be interesting. This is an optional step in the process that is not required to display the authors in your articles.
First step is to configure the `authors` taxonomy in your `config.toml` file, like in the example below. Even though `tag` and `category` are defined by default with Hugo, once you add a specific taxonomies section you need to add them again otherwise the site will not process them.
```toml
[taxonomies]
tag = "tags"
category = "categories"
author = "authors"
```
And thats just about it. Now you will have pages that reference your authors and, for each, show the respective list of articles where they participate. You can also use the `article.showAuthorsBadges` on the config file, or `showAuthorsBadges` on each article to chose whether to display the `authors` taxonomy as badges in each post item. As an example, this doc is configured to not display authors but if you look at the sample referenced below you will see the authors displayed as badges.
Lastly, you can add more detail to each author page so that it displays a little bio, links, or whatever information fits your use-case. To achieve that, create a folder with the `key` to each author inside `./content/authors` and inside each folder place a `_index.md` file. For the example above, we would end up with a `.content/authors/nunocoracao/_index.md` file. Inside, you can configure the actual name of the author and the contents of their page. Authors in this documentation website are configured like this, so you can have a look by playing around with the site.
```md
---
title: "Nuno Coração"
---
Nuno's awesome dummy bio.
```
## Sample
The sample below shows an example where the default site author is turned off and the article has multiple authors.
{{< article link="/blowfish/samples/multiple-authors/" >}}

View file

@ -0,0 +1,18 @@
---
title: "Multiple Authors"
date: 2022-10-12
draft: false
description: "Sample for a multiple author setup"
tags: ["authors", "sample"]
summary: "A quick example of how multiple authors could be used."
showAuthor: false
authors:
- "nunocoracao"
- "secondauthor"
---
This is an example of how an article with multiple authors will look like.
Check the article below for details on how to configure the feature.
{{< article link="/blowfish/docs/multi-author/" >}}

View file

@ -0,0 +1,15 @@
{
"name": "Nuno Coração",
"image" : "img/nuno_avatar.jpg",
"bio": "Theme Creator",
"social": {
"linkedin": "https://linkedin.com/in/nunocoracao",
"twitter": "https://twitter.com/nunocoracao",
"instagram": "https://instagram.com/nunocoracao",
"medium": "https://medium.com/@nunocoracao",
"github": "https://github.com/nunocoracao",
"goodreads": "http://goodreads.com/nunocoracao",
"keybase": "https://keybase.io/nunocoracao",
"reddit": "https://reddit.com/user/nunoheart"
}
}

View file

@ -0,0 +1,15 @@
{
"name": "Dummy Second Author",
"image" : "img/author2.png",
"bio": "Dummy",
"social": {
"linkedin": "https://linkedin.com/in/nunocoracao",
"twitter": "https://twitter.com/nunocoracao",
"instagram": "https://instagram.com/nunocoracao",
"medium": "https://medium.com/@nunocoracao",
"github": "https://github.com/nunocoracao",
"goodreads": "http://goodreads.com/nunocoracao",
"keybase": "https://keybase.io/nunocoracao",
"reddit": "https://reddit.com/user/nunoheart"
}
}

View file

@ -138,7 +138,27 @@
</script>
</section>
<footer class="pt-8 max-w-prose print:hidden">
{{ partial "author.html" . }}
{{ $authorsData := .Site.Data.authors }}
{{ $taxonomies := .Site.Taxonomies.authors }}
{{ $baseURL := .Site.BaseURL }}
{{ range $author := .Page.Params.authors }}
{{ $authorData := index $authorsData $author }}
{{- if $authorData -}}
{{ $taxonomyLink := 0 }}
{{ range $taxonomyname, $taxonomy := $taxonomies }}
{{ if (eq $taxonomyname $author) }}
{{ $taxonomyLink = delimit (slice $baseURL "authors/" $author) "" }}
{{ end }}
{{ end }}
{{ partial "author-extra.html" (dict "context" . "data" $authorData "link" $taxonomyLink) }}
{{- end -}}
{{ end }}
{{ partial "sharing-links.html" . }}
{{ partial "article-pagination.html" . }}
{{ if .Params.showComments | default (.Site.Params.article.showComments | default false) }}

View file

@ -57,17 +57,14 @@
{{ if and (eq $scope "single") (and .Draft .Site.Params.article.showDraftLabel) }}
<span class="pl-2">{{ partial "badge.html" (i18n "article.draft" | emojify) }}</span>
{{ end }}
</div>
{{/* Output taxonomies */}}
{{ if .Params.showTaxonomies | default (.Site.Params.article.showTaxonomies | default false) }}
<div class="flex flex-row flex-wrap items-center">
{{ range $taxonomy, $terms := .Site.Taxonomies }}
{{ if not (eq $taxonomy "authors")}}
{{ if (gt (len ($context.GetTerms $taxonomy)) 0) }}
{{ range $context.GetTerms $taxonomy }}
<span style="margin-top:0.5rem" class="mr-2" onclick="window.open({{ .RelPermalink }});">
@ -76,6 +73,24 @@
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</div>
{{ end }}
{{ if .Params.showAuthorsBadges | default (.Site.Params.article.showAuthorsBadges | default false) }}
<div class="flex flex-row flex-wrap items-center">
{{ range $taxonomy, $terms := .Site.Taxonomies }}
{{ if (eq $taxonomy "authors")}}
{{ if (gt (len ($context.GetTerms $taxonomy)) 0) }}
{{ range $context.GetTerms $taxonomy }}
<span style="margin-top:0.5rem" class="mr-2" onclick="window.open({{ .RelPermalink }});">
{{ partial "badge.html" .LinkTitle }}
</span>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</div>
{{ end }}

View file

@ -0,0 +1,32 @@
<div class="flex mt-4">
{{ with .data.image }}
{{ $authorImage := resources.Get . }}
{{ if $authorImage }}
{{ $authorImage := $authorImage.Fill "192x192" }}
<img class="!mt-0 !mb-0 h-24 w-24 rounded-full ltr:mr-4 rtl:ml-4" width="96" height="96"
src="{{ $authorImage.RelPermalink }}" />
{{ end }}
{{ end }}
<div class="place-self-center">
{{ $link := .link}}
{{ with .data.name | markdownify | emojify }}
<div class="text-[0.6rem] uppercase leading-3 text-neutral-500 dark:text-neutral-400">
{{ i18n "author.byline_title" | markdownify | emojify }}
</div>
<a {{ if $link }} href="{{ $link }}" target="_blank" {{ end }} class="font-semibold leading-6 text-neutral-800 dark:text-neutral-300">
{{ . }}
</a>
{{ end }}
{{ with .data.bio | markdownify | emojify }}
<div class="text-sm text-neutral-700 dark:text-neutral-400">{{ . }}</div>
{{ end }}
<div class="text-2xl sm:text-lg">
<div class="flex flex-wrap text-neutral-400 dark:text-neutral-500">
{{ range $name, $link := .data.social }}
<a class="px-1 hover:text-primary-700 dark:hover:text-primary-400" href="{{ $link }}" target="_blank"
aria-label="{{ $name | title }}" rel="me noopener noreferrer">{{ partial "icon.html" $name }}</a>
{{ end }}
</div>
</div>
</div>
</div>

View file

@ -1,6 +1,6 @@
{
"name": "hugo-blowfish-theme",
"version": "1.7.1",
"version": "1.8.0",
"description": "Blowfish theme for Hugo",
"scripts": {
"preinstall": "rimraf assets/vendor",