arrow_back
Back

Hugo content syntax: Markdown, shortcodes, and front matter

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Front matter

Front matter is optional, but useful. When draft: true, Hugo skips the page during a normal build (unless you pass -D / --buildDrafts).

Summaries

{{ .Summary }} uses the front-matter summary field when present, otherwise an auto-generated excerpt. To control the cut-off in the body, insert:



Sections

Content directories under content/ become open_in_new sections .

Template helpers

String comparison:

{{ if (eq "hello" "hello") }}
    ...
{{ end }}

Logical operations:

{{ if not .Params.showIndex }}
    ...
{{ end }}

Current year / page date:

{{ now.Format "2006" }}
{{ .Date.Format "January 2, 2006" }}

Home vs inner page title:

{{- if .Page.IsHome -}}
    {{ .Site.Title }}
{{- else -}}
    {{ .Title }}  {{ .Site.Title }}
{{- end -}}

Approximate reading time (≈200 words per minute):

Reading time: {{ math.Round (div (countwords .Content) 200.0) }} minutes.

Syntax highlighting (Chroma)

Hugo highlights fenced code blocks with open_in_new Chroma (Pygments-compatible).

Enable class-based highlighting in config.toml:

pygmentsUseClasses = true

Generate a stylesheet (open_in_new styles list ):

hugo gen chromastyles --style=github > syntax.css

Include that CSS in your head partial. Fenced blocks then pick up the classes:

```javascript
let x = 25;
let y = 30;
```
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Tailwind CSS with Hugo: PostCSS, build pipeline, and integration

arrow_forward