From 1cb88d9e6c12899f68274169ad0141f022bd5332 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 22 Jul 2020 10:51:13 +0200 Subject: [PATCH] add meta elements and fix title --- CHANGELOG.md | 6 ++++- exampleSite/content/posts/how-to-use.md | 16 ++++++++++++++ .../content/posts/post-with-image/index.md | 1 + layouts/partials/head.html | 22 +++++++++++++++++-- layouts/partials/title.html | 10 ++++++--- 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 343b317..84cc354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,5 @@ -- initial release +- ENHANCEMENT + - allow setting some common meta elements e.g. description and authors + - prevent duplicate title on the start page +- BUGFIX + - dont display duplicate title on home page diff --git a/exampleSite/content/posts/how-to-use.md b/exampleSite/content/posts/how-to-use.md index 75fa609..8a89867 100644 --- a/exampleSite/content/posts/how-to-use.md +++ b/exampleSite/content/posts/how-to-use.md @@ -128,6 +128,14 @@ enableGitInfo = true [geekblogContentLicense] name = "CC BY-SA 4.0" link = "https://creativecommons.org/licenses/by-sa/4.0/" + + # (Optional, default none) Default meta description used for the start page and as a fallback for + # every site without an own description. + geekblogDescription = "This is my personal blog about tech." + + # (Optional, default none) Default meta keywords used for the start page and as a fallback for + # every site without own keywords. Note: Meta keywords seems to be ignored by most modern search engines. + geekblogKeywords = ``` {{< /tab >}} @@ -231,6 +239,14 @@ params: geekblogContentLicense: name: CC BY-SA 4.0 link: https://creativecommons.org/licenses/by-sa/4.0/ + + # (Optional, default none) Default meta description used for the start page and as a fallback for + # every site without an own description. + geekblogDescription: "This is my personal blog about tech." + + # (Optional, default none) Default meta keywords used for the start page and as a fallback for + # every site without own keywords. Note: Meta keywords seems to be ignored by most modern search engines. + geekblogKeywords: [] ``` {{< /tab >}} diff --git a/exampleSite/content/posts/post-with-image/index.md b/exampleSite/content/posts/post-with-image/index.md index cd8af95..ef0cab1 100644 --- a/exampleSite/content/posts/post-with-image/index.md +++ b/exampleSite/content/posts/post-with-image/index.md @@ -3,6 +3,7 @@ title: "Post with image" date: 2020-06-22T20:00:00+02:00 authors: - richard-roe + - john-doe tags: - Open Source - Development diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 24dcdb0..e7cb127 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,8 +1,26 @@ - +{{ $description := default .Site.Params.GeekblogDescription (default .Summary .Description) }} +{{ $keywords := default .Site.Params.GeekblogKeywords .Keywords }} +{{ $author := default (slice .Site.Params.GeekblogAuthor) .Params.authors }} +{{ with $description }} + +{{ end }} +{{ with $keywords }} + +{{ end }} +{{ with $author }} + {{ $authors := slice }} + {{ range sort . }} + {{ $author := index $.Site.Data.authors . }} + {{ $authors = $authors | append $author.name }} + {{ end }} -{{ partial "title" . }} | {{ .Site.Title -}} + {{ with $authors }} + + {{ end }} +{{ end }} +{{ if not (eq .Kind "home") }}{{ partial "title" . }} | {{ end }}{{ .Site.Title -}} diff --git a/layouts/partials/title.html b/layouts/partials/title.html index a792c04..0c677b0 100644 --- a/layouts/partials/title.html +++ b/layouts/partials/title.html @@ -1,11 +1,15 @@ {{ $title := "" }} {{ if .Title }} - {{ $title = .Title }} + {{ $title = .Title }} {{ else if and .IsSection .File }} - {{ $title = path.Base .File.Dir | humanize | title }} + {{ $title = path.Base .File.Dir | humanize | title }} {{ else if and .IsPage .File }} - {{ $title = .File.BaseFileName | humanize | title }} + {{ $title = .File.BaseFileName | humanize | title }} +{{ end }} + +{{ if eq .Kind "term" }} + {{ $title = $title | humanize | title }} {{ end }} {{ return $title }}