Skip to content

Commit

Permalink
Miscellaneous edits
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed May 25, 2024
1 parent 35849e5 commit b76e816
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 176 deletions.
19 changes: 13 additions & 6 deletions content/en/content-management/summaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ It is natural to accompany the summary with links to the original content, and a

### Automatic summary splitting

By default, Hugo automatically takes the first 70 words of your content as its summary and stores it into the `.Summary` page variable for use in your templates. You may customize the summary length by setting `summaryLength` in your [site configuration](/getting-started/configuration/).
By default, Hugo automatically takes the first 70 words of your content as its summary. Access this value from a template using the [`Summary`] method on a `Page` object. You may customize the summary length by setting [`summaryLength`] in your site configuration.

[`Summary`]: /methods/page/summary
[`summaryLength`]: /getting-started/configuration/#summarylength

{{% note %}}
You can customize how HTML tags in the summary are loaded using functions such as `plainify` and `safeHTML`.
{{% /note %}}

{{% note %}}
The Hugo-defined summaries are set to use word count calculated by splitting the text by one or more consecutive whitespace characters. If you are creating content in a `CJK` language and want to use Hugo's automatic summary splitting, set `hasCJKLanguage` to `true` in your [site configuration](/getting-started/configuration/).
The Hugo-defined summaries are set to use word count calculated by splitting the text by one or more consecutive whitespace characters. If you are creating content in a [`CJK`] language and want to use Hugo's automatic summary splitting, set [`hasCJKLanguage`] to `true` in your site configuration.

[`CJK`]: /getting-started/glossary/#cjk
[`hasCJKLanguage`]: /getting-started/configuration/#hascjklanguage
{{% /note %}}

### Manual summary splitting
Expand All @@ -63,7 +69,7 @@ Be careful to enter `<!--more-->` exactly; i.e., all lowercase and with no white

### Front matter summary

You might want your summary to be something other than the text that starts the article. In this case you can provide a separate summary in the `summary` variable of the article front matter.
You might want your summary to be something other than the text that starts the article. In this case you can provide a separate summary in the `summary` field in front matter.

Pros
: Complete freedom of text independent of the content of the article. Markup can be used within the summary.
Expand All @@ -76,11 +82,11 @@ Cons
Because there are multiple ways in which a summary can be specified it is useful to understand the order of selection Hugo follows when deciding on the text to be returned by `.Summary`. It is as follows:

1. If there is a `<!--more-->` summary divider present in the article, the text up to the divider will be provided as per the manual summary split method
2. If there is a `summary` variable in the article front matter the value of the variable will be provided as per the front matter summary method
2. If there is a `summary` field in the article front matter the value of the variable will be provided as per the front matter summary method
3. The text at the start of the article will be provided as per the automatic summary split method

{{% note %}}
Hugo uses the _first_ of the above steps that returns text. So if, for example, your article has both `summary` variable in its front matter and a `<!--more-->` summary divider Hugo will use the manual summary split method.
Hugo uses the _first_ of the above steps that returns text. So if, for example, your article has both `summary` field in its front matter and a `<!--more-->` summary divider Hugo will use the manual summary split method.
{{% /note %}}

## Example: first 10 articles with summaries
Expand All @@ -105,8 +111,9 @@ You can show content summaries with the following code. You could use the follow
{{ end }}
{{< /code >}}

Note how the `.Truncated` boolean variable value may be used to hide the "Read More..." link when the content is not truncated; i.e., when the summary contains the entire article.
Note how the `Truncated` method may be used to hide the "Read More..." link when the content is not truncated; i.e., when the summary contains the entire article.

[`Truncated`]: /methods/page/truncated
[`Permalink`]: /methods/page/permalink/
[`RelPermalink`]: /methods/page/relpermalink/
[`Summary`]: /methods/page/summary/
Expand Down
23 changes: 6 additions & 17 deletions content/en/content-management/taxonomies.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,15 @@ If you want to disable all taxonomies altogether, see the use of `disableKinds`
You can add content and front matter to your taxonomy list and taxonomy terms pages. See [Content Organization](/content-management/organization/) for more information on how to add an `_index.md` for this purpose.
{{% /note %}}

## Add taxonomies to content
## Assign terms to content

Once a taxonomy is defined at the site level, any piece of content can be assigned to it, regardless of [content type] or [content section].

Assigning content to a taxonomy is done in the [front matter]. Simply create a variable with the *plural* name of the taxonomy and assign all terms you want to apply to the instance of the content type.

{{% note %}}
If you would like the ability to quickly generate content files with preconfigured taxonomies or terms, read the docs on [Hugo archetypes](/content-management/archetypes/).
{{% /note %}}

### Example: front matter with taxonomies
To assign one or more terms to a page, create a front matter field using the plural name of the taxonomy, then add terms to the corresponding array. For example:

{{< code-toggle file=content/example.md fm=true >}}
title = "Hugo: A fast and flexible static site generator"
tags = [ "Development", "Go", "fast", "Blogging" ]
categories = [ "Development" ]
series = [ "Go Web Dev" ]
slug = "hugo"
project_url = "https://github.com/gohugoio/hugo"
{{</ code-toggle >}}
title = 'Example'
tags = ['Tag A','Tag B']
categories = ['Category A','Category B']
{{< /code-toggle >}}

## Order taxonomies

Expand Down
113 changes: 0 additions & 113 deletions content/en/content-management/toc.md

This file was deleted.

2 changes: 1 addition & 1 deletion content/en/functions/global/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Do not use the global `page` function in shortcodes, partials called by shortcod

## Explanation

Hugo almost always passes a `Page` as the data context into the top level template (e.g., `single.html`). The one exception is the multihost sitemap template. This means that you can access the current page with the `.` variable in the template.
Hugo almost always passes a `Page` as the data context into the top level template (e.g., `single.html`). The one exception is the multihost sitemap template. This means that you can access the current page with the `.` in the template.

But when you are deeply nested inside of a [content view], [partial], or [render hook], it is not always practical or possible to access the `Page` object.

Expand Down
1 change: 1 addition & 0 deletions content/en/methods/page/TableOfContents.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ action:
- methods/page/Fragments
returnType: template.HTML
signatures: [PAGE.TableOfContents]
aliases: [/content-management/toc/]
---

The `TableOfContents` method on a `Page` object returns an ordered or unordered list of the Markdown [ATX] and [setext] headings within the page content.
Expand Down
70 changes: 34 additions & 36 deletions content/en/templates/404.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Custom 404 page
linkTitle: 404 page
description: If you know how to create a single page template, you have unlimited options for creating a custom 404.
linkTitle: 404 template
description: Create a template to render a 404 error page.
categories: [templates]
keywords: ['404',page not found]
menu:
Expand All @@ -11,45 +11,43 @@ menu:
weight: 220
---

When using Hugo with [GitHub Pages](https://pages.github.com/), you can provide your own template for a [custom 404 error page](https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-custom-404-page-for-your-github-pages-site) by creating a 404.html template file in the root of your `layouts` folder. When Hugo generates your site, the `404.html` file will be placed in the root.

404 pages will have all the regular [page variables][pagevars] available to use in the templates.

In addition to the standard page variables, the 404 page has access to all site content accessible from `.Pages`.

```txt
▾ layouts/
404.html
```

## 404.html

This is a basic example of a 404.html template:
To render a 404 error page in the root of your site, create a 404 template in the root of the layouts directory. For example:

{{< code file=layouts/404.html >}}
{{ define "main" }}
<main id="main">
<div>
<h1 id="title"><a href="{{ "" | relURL }}">Go Home</a></h1>
</div>
</main>
<h1>404 Not Found</h1>
<p>The page you requested cannot be found.</p>
<p>
<a href="{{ .Site.Home.RelPermalink }}">
Return to the home page
</a>
</p>
{{ end }}
{{< /code >}}

## Automatic loading
For multilingual sites, add the language key to the file name:

Your 404.html file can be set to load automatically when a visitor enters a mistaken URL path, dependent upon the web serving environment you are using. For example:

* [GitHub Pages](/hosting-and-deployment/hosting-on-github/), [GitLab Pages](/hosting-and-deployment/hosting-on-gitlab/) and [Cloudflare Pages](/hosting-and-deployment/hosting-on-cloudflare-pages/). The 404 page is automatic.
* Apache. You can specify `ErrorDocument 404 /404.html` in an `.htaccess` file in the root of your site.
* Nginx. You might specify `error_page 404 /404.html;` in your `nginx.conf` file. [Details here](https://nginx.org/en/docs/http/ngx_http_core_module.html#error_page).
* Amazon AWS S3. When setting a bucket up for static web serving, you can specify the error file from within the S3 GUI.
* Amazon CloudFront. You can specify the page in the Error Pages section in the CloudFront Console. [Details here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html)
* Caddy Server. Use the `handle_errors` directive to specify error pages for one or more status codes. [Details here](https://caddyserver.com/docs/caddyfile/directives/handle_errors)
* Netlify. Add `/* /404.html 404` to `content/_redirects`. [Details Here](https://www.netlify.com/docs/redirects/#custom-404)
* Azure Static Web App. set `responseOverrides.404.rewrite` and `responseOverrides.404.statusCode` in configfile `staticwebapp.config.json`. [Details here](https://docs.microsoft.com/en-us/azure/static-web-apps/configuration#response-overrides)
* Azure Storage as Static Web Site Hosting. You can specify the `Error document path` in the Static website configuration page of the Azure portal. [Details here](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website).
* DigitalOcean App Platform. You can specify `error_document` in your app specification file or use control panel to set up error document. [Details here](https://docs.digitalocean.com/products/app-platform/how-to/manage-static-sites/#configure-a-static-site).
* [Firebase Hosting](https://firebase.google.com/docs/hosting/full-config#404): `/404.html` automatically gets used as the 404 page.
```text
layouts/
├── 404.de.html
├── 404.en.html
└── 404.fr.html
```

[pagevars]: /methods/page/
Your production server redirects the browser to the 404 page when a page is not found. Capabilities and configuration vary by host.

Host|Capabilities and configuration
:--|:--
Amazon CloudFront|See [details](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/GeneratingCustomErrorResponses.html).
Amazon S3|See [details](https://docs.aws.amazon.com/AmazonS3/latest/userguide/CustomErrorDocSupport.html).
Apache|See [details](https://httpd.apache.org/docs/2.4/custom-error.html).
Azure Static Web Apps|See [details](https://learn.microsoft.com/en-us/azure/static-web-apps/configuration#response-overrides).
Azure Storage|See [details](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website#setting-up-a-static-website).
Caddy|See [deatils](https://caddyserver.com/docs/caddyfile/directives/handle_errors).
Cloudflare Pages|See [details](https://developers.cloudflare.com/pages/configuration/serving-pages/#not-found-behavior).
DigitalOcean App Platform|See [details](https://docs.digitalocean.com/products/app-platform/how-to/manage-static-sites/#configure-a-static-site).
Firebase|See [details](https://firebase.google.com/docs/hosting/full-config#404).
GitHub Pages|Redirection to is automatic and not configurable.
GitLab Pages|See [details](https://docs.gitlab.com/ee/user/project/pages/introduction.html#custom-error-codes-pages).
NGINX|See [details](https://nginx.org/en/docs/http/ngx_http_core_module.html#error_page).
Netlify|See [details](https://docs.netlify.com/routing/redirects/redirect-options/).
2 changes: 1 addition & 1 deletion content/en/templates/embedded.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ To include the embedded template:

### Configure Open Graph

Hugo's Open Graph template is configured using a mix of configuration variables and [front-matter](/content-management/front-matter/) on individual pages.
Hugo's Open Graph template is configured using a mix of configuration settings and [front matter](/content-management/front-matter/) on individual pages.

{{< code-toggle file=hugo >}}
[params]
Expand Down
2 changes: 1 addition & 1 deletion content/en/templates/menu-templates.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Menu templates
description: Use menu variables and methods in your templates to render a menu.
description: Create templates to render one or more menus.
categories: [templates]
keywords: [lists,sections,menus]
menu:
Expand Down
2 changes: 1 addition & 1 deletion content/en/templates/partials.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ As shown in the above example directory structure, you can nest your directories

The second argument in a partial call is the variable being passed down. The above examples are passing the `.`, which tells the template receiving the partial to apply the current [context][context].

This means the partial will *only* be able to access those variables. The partial is isolated and *has no access to the outer scope*. From within the partial, `$.Var` is equivalent to `.Var`.
This means the partial will *only* be able to access those variables. The partial is isolated and cannot access the outer scope. From within the partial, `$.Var` is equivalent to `.Var`.

## Returning a value from a partial

Expand Down

0 comments on commit b76e816

Please sign in to comment.