Add a date to default filename

I add a date string to a filename like 2021-02-05-my-post.md, so that content files are easily managed.
Is there a way to add the current date to the filename when creating a new content file by hugo new?

I’m expecting to config like contentName = "%Y-%m-%d-:title".

Maybe should I post this to feature category?

1 Like

You can use a dateobject with formats in your archetype file. Then when you call new post/blabla/filename.md the frontmatter will set the URL to the format you want. There is no way to have Hugo output another filename than the one you give to hugo new, so this is more or less a workaround.

url: /{{ now.Format "2006" }}/{{ now.Format "01" }}/{{ .Name }}
1 Like

I see. Thanks for the answer!
I gonna type the date string myself then.

In Windows I use a script

@echo off
@set /p id=Enter Title: 
@set temp=%DATE:.=%
@set title=%id: =_%
@set dirname=%temp:~4,4%-%temp:~2,2%-%temp:~0,2%_%title%
@set now=%temp:~4,4%
hugo new post\%now%\%dirname%\index.md

In Linux analog way …

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.