點燈坊

うまく使いさえすれば、時間はいつも十分にある

Understanding Archetype

Sam Xiao's Avatar 2022-03-03

Archetype is the template to create a markdown file. We can add more page variables for our convenience.

Version

Hugo 0.93.1

Default Archetype

archetypes/default.md

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

default.md is the default archetype file for hugo new to create markdown file.

  • replace .Name "-" " " | title : replace - in the filename into space, and then pipe to title
  • draft: false : Hugo doesn’t generate the page for this markdown file

type000

Modify default.md

archetypes/default.md

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: false
---
  • draft: true : modify draft to true to make Hugo generate the page for this markdown file

We can add more page variables on default.md

type001

Conclusion

  • There are still many features on archetype, but in most cases, simple default.md is enough

Reference

Hugo, Archetypes