この記事を書いた動機
hugoで書いているとき、以下のようにして、フォルダごとに分けることで、記事を管理しています。それで、それらフォルダ内に、新しく記事をhugo new
するときに、デフォルトで生成される記事のテンプレートを異なるものにして、管理できるらしいということがわかったので、メモを自分用に取るだけです。
やり方
hugo で作業しているルートディレクトリの “archetypes” というフォルダに、“content” 配下にあるフォルダ構造を意識して、[フォルダ名].mdのようにして、ファイルを作成し、テンプレートを作る。以下に、フォルダ構造やテンプレートファイルのマークダウンの例を一応乗せることにする。
archetypes
archetypes
├── default.md
├── images.md
└── posts.md
content
content
├── posts
└── images
posts.md
+++
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
date = {{ .Date }}
draft = true
ShowToc = true
+++
images.md
+++
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
date = {{ .Date }}
draft = true
ShowToc = false
+++
参考にしたサイトとか
- Archetypes | hugo
https://gohugo.io/content-management/archetypes/#article (2025年3月16日)