Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Titles for pages are broken, title tags are duplicated, and messes up bookmarks #16

Open
roberto-mello opened this issue Jan 24, 2023 · 0 comments

Comments

@roberto-mello
Copy link

The layouts/_default/baseof.html file incorrectly defines the <title> tag, making it so all generated pages end up with the site title, as opposed to the page's title.

Later on, a duplicate <title> tag is inserted through layout/partials/flex/head.html, but is ignored by most browsers (tested: Firefox, Brave, Chrome)

This becomes extremely annoying after you realize that you bookmarked a bunch of documentation pages and they all have the same title in your bookmarks. Plus, it probably messes up SEO.

The attached patch fixes the problem by removing the duplicate tag, and adding back a conditional.

diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 1fea0e8..057f440 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -4,7 +4,7 @@
     {{ if (fileExists "layouts/partials/google-analytics.html") -}}
         {{ partial "google-analytics.html" . }}
     {{- end }}
-    <title>{{ block "title" . }}{{ .Site.Title }}{{ end }}</title>
+    <title>{{ block "title" . }}{{ if .IsHome }}{{ .Site.Title }}{{else}}{{ .Title }} :: {{ .Site.Title }}{{ end }}{{ end }}</title>
     {{if .Site.Params.themeStyle}}
       {{ partial (printf "%s/head.html" .Site.Params.themeStyle) . }}
     {{else}}
diff --git a/layouts/partials/flex/head.html b/layouts/partials/flex/head.html
index 21f7497..c0c7842 100644
--- a/layouts/partials/flex/head.html
+++ b/layouts/partials/flex/head.html
@@ -1,7 +1,6 @@
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
 {{ site.Hugo.Generator }}
-<title>{{ .Title }} :: {{ .Site.Title }}</title>
 <link rel="shortcut icon" href="{{"favicon.png" | relURL}}" type="image/x-icon" />
 <link href="{{"css/nucleus.css" | relURL}}" rel="stylesheet">
 <link href="{{(printf "theme-%s/style.css" (.Site.Params.themeStyle| default "flex")  ) | relURL}}" rel="stylesheet">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant