Featured Content, Page Summary, Link Texts with Hugo
Promoting certain articles on the front page of your Hugo managed site will be the next step after creating some content. You will need a summary for each such page, and a text that will appear in links – a link title.
Page Title and Link Title
Yes, a page can have more than one title. There are linkTitle
and title
front matter parameters,
and there are corresponding {{.LinkTitle}}
and {{.Title}}
template variables. Always define
a title
in the front matter, and always use {{.LinkTitle}}
in templates for the link text. If
linkTitle
is not defined, {{.LinkTitle}}
will fall back to the value of title
. {{.Title }}
template variable should be used for HTML <title>
tag only.
This way, you can have different link text and HTML <title>
for a page, if need be.
Summary (or Summaries)
Typically, you need a summary of an article – to feature it on your front page.
Using page bundles allows for a flexible solution. Decide, what
you would call the summary files in your project (summary.md
sounds particularly creative), fetch
it as you would fetch any other page resource, and include its content where needed:
{{- with .Resources.GetMatch "summary.md" -}}
{{- .Content -}}
{{- end -}}
The translations will be picked according to the language of the page, of course, so for
index.ru.md
the summary.ru.md
will be looked up.
This approach also allows to even have multiple summaries if need be.
Hugo docs on summaries suggests a few other approaches, but I like mine better.
Selecting What to Feature
You need a way to select a few articles for the front page. I find using tags and weights the simplest solution.
By default, Hugo creates two taxonomies
:
categories and tags. We shall make use of tags in this example. You can create any number of tags
for any page in the front matter. For our particular purpose, we need to agree on some special tag
names, and then use them as filters. If we agree that featured
means exposure as a big box on the
front page, then in the front matter of the page include:
tags:
- featured
# ... other tags
Since taxonomies have their own listing pages, we can get our ‘featured’ articles by fetching a list page for the tag ‘featured’, and then iterating over the included pages, which will be first ordered by their weight, unless you define otherwise .
{{- with .GetPage "tags/featured" -}}
{{- range .Pages -}}
... deal with a featured page ...
{{- end}}