Hugo new command

I find that I can run

hugo new [path] [flags]

like: Hugo new site mynewsite

to create a website

hugo new theme [name] [flags]

to create a new theme but where can I find the full list of these commands

how can I create a Hugo new directory in layouts?


Well there is always: hugo --help for a top-level list of commands.

The docs have a list, and if you want shell completion you can generate a completions file via:

hugo completion \<shell> where <shell> is one of bash, fish, zsh, or powershell. Take the output of that command and ensure it is sourced by your shell (how is system and shell dependent) and you type hugo followed by the Tab key you get a list of command, and so on for subcommands.

There is not a hugo command for create a new directory under layouts though. For that use mkdir from your OS CLI, or using a GUI.

If you are familiar with the make command it may be helpful to think of hugo being like make with a couple of convenience functions for getting started, rather than thinking of it as a project builder.

Not with Hugo, as this is not a hugo task. mkdir layouts/directoryname on a shell CLI should do the trick. On Windows/Max it’s probably a different command.

there are Hugo specific command like to create an archetype file and then use the archetype type to create a new md file etc

One can create an archetype and then use that archetype that I know from the docs but what other types I can create and use?

can I create a data.json template and apply the template to the data fetched from and api in Hugo when running Hugo new can I combine Hugo new with Hugo get data from url command to prepopulate a file?

or the archetype and html layout the only type one can apply when running Hugo new command?


You can not create a data template with hugo new.

All hugo new can do is three things:

There is no other command to create new things.

That question about data.json is too broad to say anything useful. What I could think of is some form of frontmatter that gets created on hugo new saying things like api: and then a template that loads the API data via getJSON/getCSV. There is a new command that IIRC is named getRemote, but I can’t find it right now.

So the process of getting API data is done on creation of the website, not creation of the content. If you require an API request to create your content (like you create a new post about blafasel and the content of that post should be fetched from an API) then create a shell script or npm script that asks the API for content, then runs hugo new and then fills in the content. But that is stuff for a new thread :wink:

PS: getRemote is discussed in the release statement: Release v0.91.0 · gohugoio/hugo · GitHub

1 Like

Thanks @davidsneighbour for such a detailed response. it is really helpful.

I hope in future there will be more focus on remote data get at page creation time instead of current single option to fetch at build time

since Hugo have:

  • Layouts which can be applied to a page in front matter
  • Page with front matter can be created using archetype
  • And finally Hugo can get content from remote url

There must be a way to reverse the last step and populate the markdown file from remote content

The current option of resources.GetRemote is great if only there was a way to use this feature at the level of Hugo new page that would be great. ( I don’t know if my requirement make sense, if it does apologies in advance)

Hugo new creates a page is there an option to rebuild existing page using a different archetype or at least refresh using an updated previously applied archetype.


Well, as I was trying to imply: Hugo is a static WEBSITE generator, not a static CONTENT creator. :wink: Do your content from outside Hugo and all is well. The “egg-laying wool-milk-pig” is not part of Hugo.

My point is Hugo already have the possibility to fetch content from internet(Get.remote) and it can generate new pages using archetype.

Maybe maybe some one knows the trick on how to populate new page from remote at the time of

hugo new archetype/something

and use archetype like

title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true

**Content creation from remote url with json data**

# Restaurants 
{{ $remote := resources.GetRemote "" }}

// response received in json format
	"name": "some name",
	"description": "some long description here"

 {{ .name }}
{{ end }}

and the generated page will have the markdown file with appropriate content

does this make sense?


title = '{{ replace .Name "-" " " | title }}'
date = {{ .Date }}
draft = false

{{ with data.GetJSON (os.Getenv "HUGO_REMOTE_URL") }}
  {{ .body }}
{{ end }}


HUGO_REMOTE_URL="" hugo new hugo-release-notes/

The resulting page is static. If the remote data changes and you rebuild the site, the page will not change.

If you want the page to get the current remote data when you rebuild the site, store the env value in a page param, and use a shortcode to retrieve the data.


title = '{{ replace .Name "-" " " | title }}'
date = {{ .Date }}
draft = false
remote_url = "{{ os.Getenv "HUGO_REMOTE_URL" }}"

{{< shortcode-that-retrieves-data >}}

This works because the shortcode is not evaluated when creating the page with hugo new.



Mindblowing :star_struck:

I thought it was possible but wasn’t expecting a solution to be honest.

a simple script file with urls using your method I have test generated 3000+ pages

I can now bring thousands of blogs from Wordpress and respin using Hugo without much manual work

thanks alot :pray:

1 Like

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