diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 4154eb4709..23e6ffc571 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -15,7 +15,14 @@ {{ partialCached "favicons.html" . }} {{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}{{ end }} - + +{{ if .Page.Description }} + +{{ else }} + {{ $desc := (.Page.Content | safeHTML | truncate 150) }} + +{{ end }} + {{- template "_internal/opengraph.html" . -}} {{- template "_internal/google_news.html" . -}} {{- template "_internal/schema.html" . -}} diff --git a/userguide/content/en/docs/Adding content/content.md b/userguide/content/en/docs/Adding content/content.md index 4c3be38b09..a5dc3b4b96 100644 --- a/userguide/content/en/docs/Adding content/content.md +++ b/userguide/content/en/docs/Adding content/content.md @@ -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 diff --git a/userguide/content/en/docs/Adding content/feedback.md b/userguide/content/en/docs/Adding content/feedback.md index d40cc67b02..0edfb61079 100644 --- a/userguide/content/en/docs/Adding content/feedback.md +++ b/userguide/content/en/docs/Adding content/feedback.md @@ -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 @@ -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 }} + +{{ else }} + {{ $desc := (.Page.Content | safeHTML | truncate 150) }} + +{{ 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 + +``` + +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. +