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?

thanks

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?

thanks

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: https://someapi.com/path/?q=title 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.

Thanks

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 "https://www.example.com/some-api-with-data/data.json" }}

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

-------------------------------------------------------------------
 {{ .name }}
 {{.description}}
{{ end }}

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

does this make sense?

archetypes/hugo-release-notes.md

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

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

command

HUGO_REMOTE_URL="https://api.github.com/repos/gohugoio/hugo/releases/tags/v0.92.0" hugo new hugo-release-notes/v0.92.0.md

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.

archetypes/hugo-release-notes.md

+++
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.

4 Likes

@jmooring

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.