From 9c0d14cda4299d6bc14bbb5e74b5456815aca65f Mon Sep 17 00:00:00 2001 From: Daniel Roy Date: Tue, 18 Sep 2018 14:53:13 -0400 Subject: [PATCH] Support custom site description and thumbnail image for SEO and sharing (#696) * Add `description` to config * Add `sharing_image` to config --- exampleSite/config.toml | 42 +++++++++++++++++++++++------------- layouts/partials/header.html | 30 ++++++++++++++++++-------- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index fe457e7e..fb51ea1e 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -48,13 +48,7 @@ enableGitInfo = false smartypants = true # `false` disables all smart punctuation substitutions (e.g. smart quotes, dashes, fractions). [params] - # Color theme. - # Choose from `default`, `ocean`, `forest`, `coffee`, `dark`, or `1950s`. - color_theme = "default" - - # Font style. - # Choose from `default`, `classic`, or `playfair`. - font = "default" + # AUTHOR SETUP # Your details. name = "Lena Smith" @@ -66,25 +60,20 @@ enableGitInfo = false gravatar = false # Get your avatar from Gravatar.com? (true/false) avatar = "portrait.jpg" # Specify an avatar image (in `static/img/` folder) or delete value to disable avatar. + + # Details for the Contact Widget email = "test@example.org" address = "Building 1 Room 1, Stanford University, California, 90210, USA" office_hours = "Monday 10:00 to 13:00 or email for appointment" phone = "888 888 88 88" - twitter = "" skype = "echo123" telegram = "" - - # Enable Keybase in Contact widget by entering your keybase.io username. - keybase = "" + keybase = "" # Your keybase.io username. # Discussion link (e.g. link to a forum, mailing list, or chat). # Uncomment line below to use. # discussion = { name = "Discuss", url = "https://discourse.gohugo.io" } - # Diplay a logo in navigation bar rather than title (optional). - # To enable, place an image in `static/img/` and reference its filename below. To disable, set the value to "". - logo = "" - # Enable/disable map in Contact widget. # To show your address on a map in the contact widget, you need to enter your latitude, longitude and choose # a map provider below. @@ -106,6 +95,29 @@ enableGitInfo = false longitude = "-122.1697" zoom = 15 + # SITE SETUP + + # Color theme. + # Choose from `default`, `ocean`, `forest`, `coffee`, `dark`, or `1950s`. + color_theme = "default" + + # Font style. + # Choose from `default`, `classic`, or `playfair`. + font = "default" + + # Description for social sharing and search engines. If undefined, author role is used in place. + description = "" + + # Default image for social sharing and search engines. Place image in `static/img/` folder and specify image name here. + sharing_image = "" + + # Twitter username (without @). Used when a vistor shares your site on Twitter. + twitter = "" + + # Diplay a logo in navigation bar rather than title (optional). + # To enable, place an image in `static/img/` and reference its filename below. To disable, set the value to "". + logo = "" + # Date and time format (refer to https://sourcethemes.com/academic/docs/customization/#date-format ) # Examples: "Mon, Jan 2, 2006" or "2006-01-02" date_format = "Jan 2, 2006" diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 9712a2ec..11459c27 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -11,15 +11,19 @@ {{ $scr := .Scratch }} {{/* Generate page description. */}} - {{ $scr.Set "description" .Site.Params.role }} - {{ if .Params.abstract }} - {{ $scr.Set "description" .Params.abstract }} - {{ else if .Params.summary }} - {{ $scr.Set "description" .Params.summary }} + {{ $desc := "" }} + {{ if .Params.summary }} + {{ $desc = .Params.summary }} + {{ else if .Params.abstract }} + {{ $desc = .Params.abstract }} {{ else if .IsPage }} - {{ $scr.Set "description" .Summary }} + {{ $desc = .Summary }} + {{ else if .Site.Params.description }} + {{ $desc = .Site.Params.description }} + {{ else }} + {{ $desc = .Site.Params.role }} {{ end }} - + {{ range .Translations }} @@ -125,8 +129,16 @@ - - {{- with .Params.header.image }}{{end}} + + {{ $og_image := "" }} + {{ if .Params.header.image }} + {{ $og_image = .Params.header.image }} + {{ else if .Site.Params.sharing_image }} + {{ $og_image = .Site.Params.sharing_image }} + {{ else }} + {{ $og_image = "icon-192.png" }} + {{ end }} + {{- with $og_image }}{{end}} {{ if .IsPage }} {{ if not .PublishDate.IsZero }}