hugo-module-example

An example of a Hugo module that provides partial and shortcode templates

APACHE-2.0 License

Stars
2
Committers
1

Hugo Module – Example

This is an example of a Hugo module that provides partial and shortcode templates, as well as some miscellaneous files.

layouts/
├── partials/
│   └── hme/
│       └── greeting.html
└── shortcodes/
    └── hme/
        └── greeting.html
miscellaneous/
└── sass/
    └── bar/
        └── _index.scss

The hme subdirectory provides a namespace to avoid collisions with other modules, themes, or custom templates.

Configuration

To add this module to your project, initialize your project as a Hugo module:

hugo mod init foo

In the above, foo is typically something like github.com/user/project.

Then add this to your site configuration:

[[module.imports]]
path = 'github.com/jmooring/hugo-module-example'

Usage

To use the greeting partial:

{{ partial "hme/greeting.html" "John" }}

To use the greeting shortcode:

{{< hme/greeting John >}}

Inspection

To inspect the module components:

hugo mod vendor

This will "vendor" all of the module dependencies into a _vendor directory in the root of your project. When you build your site, Hugo looks for modules in the _vendor directory, falling back to the module cache.

When you have finished inspecting the files, remove the _vendor directory so that you can update the module as needed.

Update

To update the module to the latest version:

hugo mod get -u github.com/jmooring/hugo-module-example

To update the module to a specific version:

hugo mod get -u github.com/jmooring/[email protected]

To update all modules to the latest version:

hugo mod get -u ./...