この記事を書いた動機
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
+++
補足(2025年5月8日)
nicotalk&キャラ素材配布所
http://www.nicotalk.com/charasozai_kt.html (2024年5月16日)
├── archetypes
│ ├── Images
│ │ └── MMD.md
│ ├── default.md
│ ├── posts.md
│ └── think.md
Leaf bundles
hugo new --kind Images/MMD content/Images/MMD/DIYUSI.md
archetypes/Images/MMD.md
+++
date = '{{ .Date }}'
draft = false
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
+++
## data
\{\{<Images/MMD/Data folder="\{\{.File.ContentBaseName}}">}}
## Images and Videos
\{\{<Images/MMD/ShowImageAndVideo folder="\{\{.File.ContentBaseName}}">}}
https://gohugo.io/content-management/archetypes/#specify-archetype
関係のありそうなページ
参考にしたサイトとか
- Archetypes | hugo
https://gohugo.io/content-management/archetypes/#article (2025年3月16日)