How does Hugo work?

Sure, most web developers know what a static site generator is.
Comparison with other static generators is fine as well.

But you cannot say that web developers easily get it. Otherwise we would not have all these quite basic questions in this forum.

The title of this post is ‘How does Hugo work’? And then I asked for the “algorithm”.

This means

  • What does Hugo do?

  • Which are the steps involved - Such as

    1. reading the config file,
    2. going through the contents directory and its subdirectories
    3. Construct the site object which contains all the parameters (and more??) to be accessed through the context (a dot) in the templates.
    4. Searching for templates and applying them with the Markdown input supplied from the contents directory
    5. Applying the default taxonomy (unless otherwise stated) to the tags and categories given in the Markdown files and creating static web pages for each tag and category.
    6. Create a folder structure in the public folder folder which follows the structure of the contents folder and write the generated html files and the files copied from the static folder.
  • Something worth explaining: Hugo uses the golang template system. (Golang developer perspective here: template package - html/template - Go Packages ; template package - text/template - Go Packages Templates are executed by applying them to a data structure. Annotations in the template refer to elements of the data structure to control execution and derive values to be displayed. Execution of the template walks the structure and sets the cursor, represented
    by a period ‘.’ and called “dot”, to the value at the current location in the structure as execution proceeds.
    ). How does this look like from the web developer perspective?

A description from web developer perspective is not the same as a description for a business user.

The descriptions in the documentation and in this thread so far have been quite vague.

One has to find out by trail and error by …

  • trying out different themes and identifiying which type of web site they support
  • changing them here and there and test if it still works
  • finding out what is a hard coded convention and what may be changed

The explanations could start from a very basic explanation such as

And then proceed to more detailed descriptions what Hugo does.

For example when I started it was not clear to me that the layouts directory may be empty as the theme has a layout directory and the layouts are taken from there. It is not necessary to copy the layouts from the theme layouts directory to the layouts directory as there is a lookup process for layouts which depends on naming conventions.

Of course good example themes are helpful as well (see other recent thread on this).

@regis

Your explanation of the dot object is most helpful

But in Hugo Templates, most of the time, only one object is available to you: the context.
And it is stored in a dot.Yep, that dot. {{.}}

What would be good to know how Hugo constructs this dot object and then how it processes it.