Displaying author and date in content

I’m using the relearn theme , which is a fork of the learn theme.

If an .MD file has author and date, how do I display the author and date as shown in an example at Format usage please ?

I have seen this done in a number of other themes.

If I look at the Bootstrap blog theme at Online IDE Shortcodes - Hugo Bootstrap , it uses a Boolean value of postDate to control the display of date and reading time, etc

In /layouts/partials/post/meta.html

<div class="post-meta mb-3">
  {{- if and (default true (default .Site.Params.postDate .Params.postDate)) -}}
  <span class="post-date me-2">
    <i class="fas fa-fw fa-calendar-alt"></i>{{ .Date.Format (default "Jan 2, 2006" $.Site.Params.dateFormat) }}
  </span>
  {{- end -}}
  {{- if and (default true (default .Site.Params.readingTime .Params.readingTime)) -}}
  <span class="post-reading-time me-2">
    <i class="fas fa-fw fa-coffee"></i>{{ i18n "reading_time" . }}
  </span>
  {{- end -}}
  <span class="post-taxonomies">
  {{- range $key, $value := .Site.Taxonomies -}}
    {{- range ($.GetTerms $key) -}}
    <a href="{{ .Permalink }}" class="post-taxonomy">{{ .Name }}</a>
    {{- end -}}
  {{- end -}}
  </span>
</div>

Have checked with the author of the TShark site , and the front matter I’m using in the .MD files are the same formats.

So, there must be either a slight code difference between the learn and relearn themes, or some config setting, or both maybe ?

An interesting read on front matter at Front Matter | Hugo

From what I can tell of the theme’s documentation, this isn’t a feature of the theme. If you want pages to display author and date based on frontmatter, you’ll have to edit the theme yourself.

I’d be looking at overriding either tags.html and/or header.html.

To override something from the theme, make a copy of the file from the theme (e.g. /themes/hugo-theme-relearn/layouts/partials/tags.html and put it in layouts/partials/tags.html. Then edit ‘your’ version of the file to include author name and date.

If you incorporate some of the things you’ve seen in the other theme’s you’ve linked to, you should be able to work it out.

1 Like

@funkydan2 Thanks for your help and those tips

If you incorporate some of the things you’ve seen in the other theme’s you’ve linked to, you should be able to work it out.

I’ve installed a theme where the front matter details are displayed ( hugo-theme-bootstrap ), so should be able to work out how it is done. Just how well that will ‘fit’ into the relearn theme though I don’t know yet.

Hey @jehoshua7, partials aren’t well documented at the moment. Addtionally, the content partial was newly introduced with the last release.

Create a new file layouts/partials/content.html in your site’s root directory with the following content:

{{- .Content -}}

<div class="author">{{- .Params.author -}}</div>

Add a author field to the front matter in each of your pages.

That should do the job.

1 Like

Thanks @McShelby . That works fine, and I added the date …

<div class="page-description"><i class="fas fa-clock"></i> {{ .ReadingTime }} min | <i class="fas fa-feather-alt"></i> {{ .Params.Author }} | <i class="far fa-calendar-check"></i> {{ .Date.Format "January 1, 2006"}}</div>

{{- .Content -}}

Not sure if it needs other (conditional) code, as not everyone wants this displayed in the content.

Thanks for your help. :smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.