adding a page bundle with `hugo new`

Viewed 465

I can add a new page with hugo new posts/new-page. But I want to add a page bundle. None of the following work

hugo new posts/2021/10/new-page creates a single new-page.md hugo new posts/2021/10/new-page/ does the same as above hugo new posts/2021/10/new-page/index.md works, kind. It creates index.md in the correct path and populates index.md with the archetypes/default.md except, it set the title to index instead of new page

so, how can I add a page bundle with hugo new

2 Answers

You can achieve that using Archetypes , quoting from the docs:

Since Hugo 0.49 you can use complete directories as archetype templates.

  • in the archetypes/ folder create a new folder named post-bundle/
  • inside it create a new file index.md

archetypes/post-bundle/index.md :

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---
  • Then to create a page bundle:
    hugo new --kind post-bundle posts/new-page

Notice: I don't think the approach you're doing to set the date in the url is correct , the above method will give a post with the following Permalink : example.com/posts/new-page you can then do the following to get the desired Permalink:

config.toml :

[permalinks]
  posts = '/:year/:month/:title/'

In support of Mossab's answer...

a page bundle has three categories: Branch, headless and leaf.

So if you made a file _index.md - it's a Branch bundle, off-the-bat. So viola that's how you make it with hugo new.

If you want a headless bundle, I believe you first need a leaf bundle, and then add: headless = true to the front matter.

If you want a lead bundle you create an index.md file at any directory level.

So, I believe my point in this is, the way you do this is:

hugo new _index.md
Or
hugo new index.md

and if you want it headless, you use an archetype with the front matter (as Mossab desribes).

Please let me know if I'm possibly misunderstanding something.

Related