Home page does not have title, description and keywords from yaml header

I am using the RStudio> RMarkdown> Blogdown> Github> Netlify flow to publish a website.

The top of the RMarkdown document has yaml to define the title, description, and keywords, like so:

---
title: "The Best GIC and Savings Rates in Canada"
description: "WhatBank compares the best GIC and high-interest savings accounts in Canada. Setup personalized email notifications to stay informed."
keywords: "gic, gics, term deposit, guaranteed investment certificate, rates, canada, comparison, compare, highest, best, email alerts, 1 year, 2, year, 3 year, 4 year, 5 year, long term, high-interest, savings, high-interest savings"
author: "WhatBank"
date: "2021-03-27"
slug: "home"
output:
  html_document:
  includes: header.html
---

This seems to work OK for every page except the home page. I think that this has to do with the file: layouts/partials/head.html
At some point, the title tag was edited:

<meta charset="utf-8">

<title>{{ if .IsHome }}Highest GIC and Savings Rates in Canada - {{ else }}{{ if .Page.Title }}{{ .Page.Title }} - {{ end }}{{ end }}{{ .Site.Title }}</title>

<!--
<title>{{ if .Page.Title }}{{ .Page.Title }} - {{ end }}{{ .Site.Title }}</title>
-->

<meta name="description"
    content="{{ with .Description }}{{ . }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}">
    
{{ with .Site.Params.author }}
<meta name="author" content="{{ . }}">{{ end }}

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="keywords"
    content="{{ with .Keywords }}{{ . }}{{ else }}{{ with .Site.Params.keywords }}{{ . }}{{ end }}{{ end }}">
...

The above hardcoded title works but is not ideal because it is hardcoded. More importantly, the description and keywords tags are empty when I View Source:

<meta name="description"
    content="">
    
<meta name="keywords"
    content="">

and author never appears on any page, but I’m not sure that is important since this is a website and not a blog.

Question: How do I modify head.html so the HTML of every page will have the title, description and keywords that are reflected in the yaml of the RMarkdown pages?

hugo env
Hugo Static Site Generator v0.79.1-EDB9248D/extended linux/amd64 BuildDate: 2020-12-19T15:50:19Z
GOOS=“linux”
GOARCH=“amd64”
GOVERSION=“go1.15.1”

git version 2.25.1

Hi,

You can try something like this:

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>{{ with .Title }}{{ . }} -- {{ end }}{{ with site.Title }}{{ . }}{{ end }}</title>

{{ $description := .Params.description | default site.Params.description }}
{{ with $description }}<meta name="description" content="{{ . }}">{{ end }}
    
{{ $author := .Params.author | default site.Params.author }}
{{ with $author }}<meta name="author" content="{{ . }}">{{ end }}

<meta name="keywords" content="{{ with .Params.keywords }}{{ range $i, $e := . }}{{ if $i }}, {{ end }}{{ . }}{{ end }}{{ else }}{{ with site.Params.keywords }}{{ range $i, $e := . }}{{ if $i }}, {{ end }}{{ . }}{{ end }}{{ end }}{{ end }}">
...

Unfortunately that is worse.
View Source of the home page is now:

<title>WhatBank -- WhatBank</title>
<meta name="keywords" content="">

Not picking up the title and no mention of description or keywords.

Well it all depends on your .Page.Params (defined in the page front matter) and site.Params (defined in your configuration file)… You should probably read the documentation.

Meanwhile you can try this:

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>{{ if not .IsHome }}{{ with .Title }}{{ . }} -- {{ end }}{{ end }}{{ with site.Title }}{{ . }}{{ end }}</title>

{{ $description := .Params.description | default site.Params.description }}
{{ with $description }}<meta name="description" content="{{ . }}">{{ end }}
    
{{ $author := .Params.author | default site.Params.author }}
{{ with $author }}<meta name="author" content="{{ . }}">{{ end }}

<meta name="keywords" content="{{ with .Params.keywords }}{{ range $i, $e := . }}{{ if $i }}, {{ end }}{{ . }}{{ end }}{{ else }}{{ with site.Params.keywords }}{{ range $i, $e := . }}{{ if $i }}, {{ end }}{{ . }}{{ end }}{{ end }}{{ end }}">
...

Note that in this layout title, description and author are expected to be strings while keywords are expected to be a slice (list of strings).

So in you page front matter (if YAML):

title: "A title"
description: "A description"
author: "An author"
keywords: ["a","list","of","keywords"]

Or even

title: title
description: page description
author: page author
keywords: 
  - a
  - list
  - of
  - keywords

and fallbacks in config.toml (if TOML):

title = "Site Title"
[params]
  author = "site author"
  description = "site description"
  keywords = ["a","list","of","keywords"]

or if your site is multilingual:

[languages]
  [languages.en]
    description = "site description in english"
    keywords = ["a","list","of","keywords"]
  [languages.fr]
    description = "description du site en français"
    keywords = ["une","liste","de","mots-clefs"]

Can’t help much more without seeing your files.

Quite helpful. Almost there.

This line:

<title>{{ if not .IsHome }}{{ with .Title }}{{ . }} -- {{ end }}{{ end }}{{ with site.Title }}{{ . }}{{ end }}</title>

Uses the title = "My title" defined in the config.toml page for the home page.

For all other pages it uses:
Title defined in yaml of RMarkdown -- Title defined in the config.toml

This makes the titles too long in all but the home page.

How do I:

  1. Only use the the title defined in the yaml in the RMarkdown

or

  1. Not append the title defined in the config.toml if there is already a title defined in the yaml of the RMarkdown?