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

FIX: meta description tag creation in head.html (SEO) #662

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@

{{ partialCached "favicons.html" . }}
<title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}{{ end }}</title>
<meta name="description" content="{{ .Site.Params.Description }}">
<!-- for search engine optimization and third-party search engines like Elastic App Search-->
{{ if .Page.Description }}
<meta name="description" content="{{ .Page.Description }}">
{{ else }}
{{ $desc := (.Page.Content | safeHTML | truncate 150) }}
<meta name="description" content="{{ $desc }}">
{{ end }}

{{- template "_internal/opengraph.html" . -}}
{{- template "_internal/google_news.html" . -}}
{{- template "_internal/schema.html" . -}}
Expand Down
2 changes: 1 addition & 1 deletion userguide/content/en/docs/Adding content/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ description: >
---
```

The minimum frontmatter you need to provide is a title: everything else is up to you! (though if you leave out the page weight your [navigation](/docs/adding-content/navigation) may get a little disorganized).
The minimum frontmatter you need to provide is a title: everything else is up to you! However, if you leave out the page weight, your [navigation](/docs/adding-content/navigation) may get a little disorganized. You may also want to include `description` since Docsy uses that to generate the meta `description` tag used by search engines. See [Search Engine Optimization (SEO) meta tags]({{< ref "feedback#search-engine-optimization-meta-tags" >}}) for details.


## Page contents and markup
Expand Down
39 changes: 37 additions & 2 deletions userguide/content/en/docs/Adding content/feedback.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: "Analytics and User Feedback"
title: "Analytics, User Feedback, SEO"
date: 2019-06-05
weight: 8
description: >
Add Google Analytics tracking to your site, use the "was this page helpful?" widget data, disable the widget on a single
page or all pages, and change the response text.
page or all pages, and change the response text. See what data is used to create the `meta description` tag for SEO.
---

## Adding Analytics
Expand Down Expand Up @@ -131,3 +131,38 @@ Set `params.ui.feedback.enable` to `false` in `config.toml`:

[params.ui.feedback]
enable = false

## Search Engine Optimization meta tags

Check out Google's [Search Engine Optimization (SEO) Starter Guide](https://developers.google.com/search/docs/beginner/seo-starter-guide) for how to optimize your site for SEO.

Google [recommends](https://developers.google.com/search/docs/beginner/seo-starter-guide?hl=en%2F#descriptionmeta) using the `description` meta tag to tell search engines what your page is about. The Docsy theme creates and populates this meta tag for you in the `layouts/partials/head.html` file:

```html
{{ if .Page.Description }}
<meta name="description" content="{{ .Page.Description }}">
{{ else }}
{{ $desc := (.Page.Content | safeHTML | truncate 150) }}
<meta name="description" content="{{ $desc }}">
{{ end }}
```

`.Page.Description` is the text from the `description` [frontmatter field]({{< ref "content#page-frontmatter" >}}). If the page's frontmatter does not have a `description`, the first 150 characters of the page content is used instead.

For example, if your front matter `description` is:

```markdown
---
description: >
Add Google Analytics tracking to your site.
---
```

Then the meta `description` tag on the rendered page is:

```html
<meta name="description" content="Add Google Analytics tracking to your site.">
```

You can add additional meta tags to your own copy of the `head-end.html` partial. See [Customizing templates]({{< ref "lookandfeel#customizing-templates" >}}) for more information.