File Structure

File Structure

Directory Structure

By default, Hugo searches for Markdown files in the content directory, and the structure of the directory determines the final output structure of your website. Take the example site as an example:

    • _index.md
      • _index.md
      • getting-started.md
        • _index.md
        • organize-files.md
      • _index.md
      • post-1.md
  • Each of the _index.md files is the index page for the corresponding section. The other Markdown files are regular pages.

    content
    ├── _index.md // <- /
    ├── docs
    │   ├── _index.md // <- /docs/
    │   ├── getting-started.md // <- /docs/getting-started/
    │   └── guide
    │       ├── _index.md // <- /docs/guide/
    │       └── organize-files.md // <- /docs/guide/organize-files/
    └── blog
        ├── _index.md // <- /blog/
        └── post-1.md // <- /blog/post-1/

    Sidebar Navigation

    The sidebar navigation is generated automatically based on the content organization alphabetically. To manually configure the sidebar order, we can use the weight parameter in the front matter of the Markdown files.

    content/docs/guide/_index.md
    ---
    title: Guide
    weight: 2
    ---
    ℹ️

    It is recommended to keep the sidebar not too deep. If you have a lot of content, consider splitting them into multiple sections.

    Configure Content Directory

    If we need to use a different directory for our content, we can do so by setting the contentDir parameter in our site configuration file.

    Add Images

    To add images, the easiest way is to put the image files in the same directory as the Markdown file. For example, add an image file image.png alongside the my-page.md file:

      • my-page.md
      • image.png
  • Then, we can use the following Markdown syntax to add the image to the content:

    content/docs/my-page.md
    ![](image.png)

    We can also utilize the page bundles feature of Hugo to organize the image files together with the Markdown file. To achieve that, turn the my-page.md file into a directory my-page and put the content into a file named index.md, and put the image files inside the my-page directory:

        • index.md
        • image.png
  • content/docs/my-page/index.md
    ![](image.png)

    Alternatively, we can also put the image files in the static directory, which will make the images available for all pages:

      • image.png
      • my-page.md
  • Note that the image path begins with a slash / and is relative to the static directory:

    content/docs/my-page.md
    ![](/images/image.png)