Publish

static

  • The static  directory contains files that will be copied to the public  directory when you build your site.

  • For example: favicon.ico , robots.txt , and files that verify site ownership.

  • Before the introduction of page bundles  and asset pipelines , the static  directory was also used for images, CSS, and JavaScript.

public

  • The public  directory contains the published website, generated when you run the hugo  or hugo server  commands.

  • Hugo recreates this directory and its content as needed.

  • SeeΒ  details .

resources

  • The resources  directory contains cached output from Hugo’s asset pipelines, generated when you run the hugo  or hugo server  commands.

  • By default this cache directory includes CSS and images. Hugo recreates this directory and its content as needed.

Host Locally

  • Used to view your site while developing layouts or creating content

hugo server
    # Only worked for hugo extended.
  • Life Reload :

    • While the server is running, it watches your project directory for changes to assets, configuration, content, data, layouts, translations, and static files. When it detects a change, the server rebuilds your site and refreshes your browser using LiveReload .

    • While the server is running, Hugo injects JavaScript into the generated HTML pages. The LiveReload script creates a connection from the browser to the server via web sockets. You do not need to install any software or browser plugins, nor is any configuration required.

    • Automatic Redirection :

      • If you want your browser to automatically redirect to the page you last modified, run:

      hugo server --navigateToChanged
      
  • New notes are created as drafts. If you want to see those, use:

hugo server --buildDrafts

Host Remote

Publish

hugo
  • Directories :

    • Default publish directory:

      • /public .

    • To publish your site to a different directory, use the --destination  flag or set publishDir  in your site configuration.

    • This is also used, I think:

      • /resources .

  • Inside the /public :

    public/
    β”œβ”€β”€ categories/
    β”‚   β”œβ”€β”€ index.html
    β”‚   └── index.xml  <-- RSS feed for this section
    β”œβ”€β”€ posts/
    β”‚   β”œβ”€β”€ my-first-post/
    β”‚   β”‚   └── index.html
    β”‚   β”œβ”€β”€ index.html
    β”‚   └── index.xml  <-- RSS feed for this section
    β”œβ”€β”€ tags/
    β”‚   β”œβ”€β”€ index.html
    β”‚   └── index.xml  <-- RSS feed for this section
    β”œβ”€β”€ index.html
    β”œβ”€β”€ index.xml      <-- RSS feed for the site
    └── sitemap.xml
    
  • Watch out! :

    • Hugo does not  clear the public  directory before building your site. Depending on the current  evaluation of the four conditions above, after the build your public  directory may contain extraneous files from a previous build.

    • A common practice is to manually clear the contents of the public  directory before each build to remove draft, expired, and future content.

Union File System

  • Hugo creates a union file system, allowing you to mount two or more directories to the same location.

  • For example, let’s say your home directory contains a Hugo project in one directory, and shared content in another:

home/
└── user/
    β”œβ”€β”€ my-site/            
    β”‚   β”œβ”€β”€ content/
    β”‚   β”‚   β”œβ”€β”€ books/
    β”‚   β”‚   β”‚   β”œβ”€β”€ _index.md
    β”‚   β”‚   β”‚   β”œβ”€β”€ book-1.md
    β”‚   β”‚   β”‚   └── book-2.md
    β”‚   β”‚   └── _index.md
    β”‚   β”œβ”€β”€ themes/
    β”‚   β”‚   └── my-theme/
    β”‚   └── hugo.toml
    β””── shared-content/     
        β””── films/
            β”œβ”€β”€ _index.md
            β”œβ”€β”€ film-1.md
            β””── film-2.md
  • You can include the shared content when you build your site using mounts. In your site configuration:

[module]
  [module.mounts](module.mounts)
    source = 'content'
    target = 'content'
  [module.mounts](module.mounts)
    source = '/home/user/shared-content'
    target = 'content'
  • When you overlay one directory on top of another, you must mount both directories.

  • Hugo does not follow symbolic links. If you need the functionality provided by symbolic links, use Hugo’s union file system instead.

  • After mounting, the union file system has this structure:

home/
└── user/
    β””── my-site/
        β”œβ”€β”€ content/
        β”‚   β”œβ”€β”€ books/
        β”‚   β”‚   β”œβ”€β”€ _index.md
        β”‚   β”‚   β”œβ”€β”€ book-1.md
        β”‚   β”‚   └── book-2.md
        β”‚   β”œβ”€β”€ films/
        β”‚   β”‚   β”œβ”€β”€ _index.md
        β”‚   β”‚   β”œβ”€β”€ film-1.md
        β”‚   β”‚   └── film-2.md
        β”‚   └── _index.md
        β”œβ”€β”€ themes/
        β”‚   └── my-theme/
        β””── hugo.toml
  • When two or more files have the same path, the order of precedence follows the order of the mounts. For example, if the shared content directory contains books/book-1.md , it will be ignored because the project’s content  directory was mounted first.

  • You can mount directories to archetypes , assets , content , data , i18n , layouts , and static . SeeΒ  details .

  • You can also mount directories from Git repositories using Hugo Modules. SeeΒ  details .