Skip to main content

Utiliser les archetypes

· 2 min read
j0rdan-m

Today I want to talk about the archetypes of the Hugo site generation engine. This very powerful engine is used to generate these pages.

The archetypes are the elements that generate the Hugo page headers, when created with the command hugo new my_file.md.

archetypes/Default.md

The default.md in the archetype applies to all the "new hugo" you will create. This default.md is customizable, as seen in the previous article, Managing content in a Hugo site, but it can also be multiplied.

archetypes/mon_mien.md

Let's imagine the case of an ESN site (at random ;) ), in which we will find a home page, a certain number of 'Products' pages, 'Offers' pages and a 'blog' page.

you just have to create, in the folder archetypes, three files :

  • product.md
  • offer.md
  • post.md

these three files will contain the appropriate archetypes according to the type of page.

It is very simple to apply an archetype to a page: the archetype must have the same name as the directory hosting the page type!

For example, to create a product page, an offer page and a blog post, we will use these three commands:

# Nouvelle page produit
hugo new produit/eaviz.md

# Nouvelle offre Marte
hugo new offre/expert_ansible.md

# Nouvel article de blog
hugo new post/gestion_archetype.md

Managing themes

Like the config.toml of the exampleSite section of a theme, I strongly advise you to start from the archetype(s) proposed by a theme. This will allow you to know the right working directories to see your pages appear in the places provided by the theme.