Skip to content

Commit

Permalink
add configurable meta-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
JugglerX committed Mar 1, 2019
1 parent ba4d045 commit df5531f
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 7 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,42 @@ hugo server
```

Now enter [`localhost:1313`](http://localhost:1313) in the address bar of your browser.

# Configuring theme features

### Homepage meta tags

Often a homepage requires special meta tags such as a meta description or og meta data for twitter, facebook etc. You can configure these values in the `config.toml`

```
// config.toml
[params]
google_analytics_id=""
[params.homepage_meta_tags]
meta_description = "a description of your website."
meta_og_title = "My Theme"
meta_og_type = "website"
meta_og_url = "https://www.mywebsite.com"
meta_og_image = "https://www.mywebsite.com/images/tn.png"
meta_og_description = "a description of your website."
meta_twitter_card = "summary"
meta_twitter_site = "@mytwitterhandle"
meta_twitter_creator = "@mytwitterhandle"
```

### Set meta tags on a per template/page basis

You can set meta tags on a per template basis using a block. For example, you might want to write a custom meta description for the `/services` page. You can insert any valid HTML meta data inside the `{{ define "meta_tags }}` block at the top of a template.

```
// layouts/services/list.html
...
{{ define "meta_tags" }}
<meta name="description" content="We offer a variety of services in the finance industry" />
{{ end }}
{{ define main }}
...
```
13 changes: 12 additions & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ themesDir = "../.."
theme = "hugo-serif-theme"

[params]
google_analytics_id=""
google_analytics_id=""

[params.homepage_meta_tags]
meta_description = "Serif is a beautiful small business theme for Hugo (Static Site Generator). It contains content types for the archetypical small business website. The theme is fully responsive, blazing fast and artfully illustrated."
meta_og_title = "Hugo Serif Theme"
meta_og_type = "website"
meta_og_url = "https://hugo-serif.netlify.com"
meta_og_image = "https://raw.githubusercontent.com/JugglerX/hugo-serif-theme/master/images/tn.png"
meta_og_description = "Serif is a beautiful small business theme for Hugo (Static Site Generator). It contains content types for the archetypical small business website. The theme is fully responsive, blazing fast and artfully illustrated."
meta_twitter_card = "summary"
meta_twitter_site = "@zerostaticio"
meta_twitter_creator = "@zerostaticio"

[[menu.main]]
name = "Services"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Target":"css/style.min.d10d2f6c383f9abe07dcfa1800a72f582ff39c51785787b0e731f6401c43bc99.css","MediaType":"text/css","Data":{"Integrity":"sha256-0Q0vbDg/mr4H3PoYAKcvWC/znFF4V4ew5zH2QBxDvJk="}}
{"Target":"css/style.min.86ae9969a9d827177d9bc22b206a6cbba9411c96e8a2e3b65dbe509613edb11f.css","MediaType":"text/css","Data":{"Integrity":"sha256-hq6ZaanYJxd9m8IrIGpsu6lBHJboouO2Xb5QlhPtsR8="}}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Target":"css/style.min.5ff9ab1c2a7b76b6cdc181aef5b639d8fad30127381226dd2b1af203e4a91743.css","MediaType":"text/css","Data":{"Integrity":"sha256-X/mrHCp7drbNwYGu9bY52PrTASc4EibdKxryA+SpF0M="}}
{"Target":"css/style.min.66d2a2d57ed39ba1b6d523fef1f7b51c4c3825c5a7c299e4df07ea49e5ff92a1.css","MediaType":"text/css","Data":{"Integrity":"sha256-ZtKi1X7Tm6G21SP+8fe1HEw4JcWnwpnk3wfqSeX/kqE="}}
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{ block "title" . }}{{ .Title }} - {{ .Site.Title }}{{ end }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ block "meta" . }}{{end}}
{{ block "meta_tags" . }}{{end}}
<link rel="icon" href="{{ .Site.BaseURL }}favicon.png">

<!-- CSS -->
Expand Down
1 change: 0 additions & 1 deletion layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{{ define "header_css" }}{{ end }}
{{ define "body_classes" }}page-home{{ end }}
{{ define "header_classes" }}header-transparent{{ end }}
{{ define "meta"}}<meta name="description" content="Live demo of the Hugo Serif Theme">{{ end }}

{{ define "main" }}

Expand Down

0 comments on commit df5531f

Please sign in to comment.