hugo/content/en/getting-started/directory-structure.md
Bjørn Erik Pedersen 9aec42c545 Squashed 'docs/' changes from 686c7b6eb..7ef2dbce4
7ef2dbce4 Cleanup RSS templates page
0e23d5e1a Fix multilingual permalinks example
b3c342b07 Update faq.md
f73109ae2 Regen CLI docs
ac6ee2027 Fix minor nitpicks (#2233)
f24fcffe1 Mention the Giscus comments system (#2234)
418fa981e Remove reference to Ghost migration tool
94a76df29 Adjust table layout
e263ad6b9 content: Fix typos
fd1eb26b5 Update featured image in digital.gov showcase
d3d946555 Correct directory description
bbe1dff56 Use sentence case for heading
acfa0be54 Add hosting provider fetch depth to GitInfo variables page
d78c427e6 Fix typo
751517fea Fix spelling mistake
cdd77aa9a Update content for v0.118.0
c77d09b1c Format netlify.toml
d5a6c4f51 netlify: Hugo 0.118.1
8c717301a Revert "netlify: Hugo 0.118.0"
a9b2ef5c2 netlify: Hugo 0.118.0
61959591c Merge commit '77b976dd92b4f66657d83d875aef0c617df492d9'
95f2029a1 docs: Regen docs helper
fd57ba960 markup/goldmark: Add CJK extension
2bfb3bf4c docshelper: Improve template lookup order descriptions
b0baa890e cache: Hide IsResourceDir from the exported config
b4b071ea0 docs: Replace docs.json with docs.yaml

git-subtree-dir: docs
git-subtree-split: 7ef2dbce4ad728d32c218761c6cfbe2f58f8da16
2023-09-24 11:54:45 +02:00

7.6 KiB

title description categories keywords menu weight aliases toc
Directory structure Each Hugo project is a directory, with subdirectories that contribute to the content, structure, behavior, and presentation of your site.
fundamentals
getting started
source
organization
directories
docs
parent weight
getting-started 30
30
/overview/source-directory/
true

Site skeleton

Hugo generates a project skeleton when you create a new site. For example, this command:

hugo new site my-site

Creates this directory structure:

my-site/
├── archetypes/
│   └── default.md
├── assets/
├── content/
├── data/
├── i18n/
├── layouts/
├── static/
├── themes/
└── hugo.toml         <-- site configuration

Depending on requirements, you may wish to organize your site configuration into subdirectories:

my-site/
├── archetypes/
│   └── default.md
├── assets/
├── config/           <-- site configuration
│   └── _default/
│       └── hugo.toml
├── content/
├── data/
├── i18n/
├── layouts/
├── static/
└── themes/

When you build your site, Hugo creates a public directory, and typically a resources directory as well:

my-site/
├── archetypes/
│   └── default.md
├── assets/
├── config/       
│   └── _default/
│       └── hugo.toml
├── content/
├── data/
├── i18n/
├── layouts/
├── public/       <-- created when you build your site
├── resources/    <-- created when you build your site
├── static/
└── themes/

Directories

Each of the subdirectories contributes to the content, structure, behavior, or presentation of your site.

archetypes
The archetypes directory contains templates for new content. See details.
assets
The assets directory contains global resources typically passed through an asset pipeline. This includes resources such as images, CSS, Sass, JavaScript, and TypeScript. See details.
config
The config directory contains your site configuration, possibly split into multiple subdirectories and files. For projects with minimal configuration or projects that do not need to behave differently in different environments, a single configuration file named hugo.toml in the root of the project is sufficient. See details.
content
The content directory contains the markup files (typically markdown) and page resources that comprise the content of your site. See details.
data
The data directory contains data files (JSON, TOML, YAML, or XML) that augment content, configuration, localization, and navigation. See details.
i18n
The i18n directory contains translation tables for multilingual sites. See details.
layouts
The layouts directory contains templates to transform content, data, and resources into a complete website. See details.
public
The public directory contains the published website, generated when you run the hugo command. 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.
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. See details.
themes
The themes directory contains one or more themes, each in its own subdirectory.

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:

{{< code-toggle file=hugo copy=false >}} module.mounts source = 'content' target = 'content'

module.mounts source = '/home/user/shared-content' target = 'content' {{< /code-toggle >}}

{{% note %}} When you overlay one directory on top of another, you must mount both directories.

If you think you need a symbolic link in your project directory, use Hugo's union file system instead. {{% /note %}}

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

{{% note %}} 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. {{% /note %}}

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.

Theme skeleton

Hugo generates a functional theme skeleton when you create a new theme. For example, this command:

hugo new theme my-theme

Creates this directory structure (subdirectories not shown):

my-theme/
├── archetypes/
├── assets/
├── content/
├── data/
├── i18n/
├── layouts/
├── static/
├── LICENSE
├── README.md
├── hugo.toml
└── theme.toml

Using the union file system described above, Hugo mounts each of these directories to the corresponding location in the project. When two files have the same path, the file in the project directory takes precedence. This allows you, for example, to override a theme's template by placing a copy in the same location within the project directory.

If you are simultaneously using components from two or more themes or modules, and there's a path collision, the first mount takes precedence.