Go言語製のWebサイトエンジンHugoの機能整理をします。
今回はContent TypesとArchetypesです。
Hugoとは?
Content Typesとは?
Content Typesによって、
- Typeごとの独自なLayoutの適用
- MarkdownのContentのArchetypesを適用
によってDRYに静的コンテンツをメンテナンスできます。
また、この際に標準的な構成で作っておけば
Front Matterにtypeを指定せずとも、content配下のSection名が
そのままtypeとして扱われます。
任意のtypeのContentの生成
typeに対応したarchetypesを作成しておくことで、
$ hugo new your_section/specific_sectino_name.md
などを実行した際に、該当するtype専用のテンプレートを元にContentが生成されます。
archetypeが無い場合は、defaultのarchetypeが適用されます。
サンプル
- hugo_theme_begテーマを利用します
Layoutの確認
TypeごとのLayoutの設定および確認については、Sectionの記事をご確認ください。
以下は、TypeごとのArchetypesの設定・確認例です。
archetypesの作成
- themes/hugo_theme_beg/archetypes/post.md
+++
title = ""
date = ""
comments =true
tags = ["some_tag"]
+++
## some_title
detail
- themes/hugo_theme_beg/archetypes/member.md
+++
title = ""
date = ""
name ="suzuki"
age =99
+++
## 趣味
趣味を書く
archetypesを利用してContentを生成する
- postの生成
$ hugo new post/qiita_team.md path/to/content/post/qiita_team.md created $ cat content/post/qiita_team.md +++ comments = true date = "2015-08-12T15:51:00+09:00" tags = ["some_tag"] title = "qiita_team" +++ ## some_title detail
- memberの生成
$ hugo new member/nonomura.md path/to/content/member/nonomura.md created $ cat content/member/nonomura.md +++ age = 99 date = "2015-08-12T15:52:38+09:00" name = "nonomura" title = "nonomura" +++ ## 趣味 趣味を書く