2.5 KiB
Adding or Removing Hugo Modules
Hugo Modules (https://github.com/gethugothemes/hugo-modules) provide most non-trivial functionality — search, SEO, images, PWA, accordions/tabs/modals, shortcodes, announcement bar, analytics, etc. Each is a separate Go module declared as an [[imports]] block in config/_default/module.toml.
Enable a module
-
In
config/_default/module.toml, either uncomment an existing# [[imports]]/# path = "..."pair, or add a new block:[[imports]] path = "github.com/gethugothemes/hugo-modules/<module-name>"Module names are paths under
github.com/gethugothemes/hugo-modules/(e.g.search,pwa,icons/themify-icons,seo-tools/plausible-analytics,components/crisp-chat). -
Run
pnpm update-modulesto fetch the module and rewritego.mod/go.sum. -
Restart the dev server (
npx kill-port 1313 -y && pnpm dev). -
Use the partials/shortcodes/config the module adds — check the module's source (URL is the
pathvalue) for its partial names, shortcode names, and anyparams/configblock it expects inconfig/_default/params.tomlor similar and what kind of data it expects accoding to its docs (e.g.imagesmodule'simagepartial expects a dict withSrc,Alt,Loading,Class, andDisplayXLkeys).
Disable or delete a module
- Delete or comment out its
[[imports]]block inconfig/_default/module.toml. - Remove anything in the site that depends on it —
partial/partialCachedcalls, shortcodes used in content, and any related config block (e.g.[search]inparams.toml). Leaving these in place causes build errors ("partial not found") once the module is gone. - Run
pnpm update-modules. - Restart the dev server.
Currently available but disabled (commented out in module.toml)
icons/themify-icons, components/valine-comment, components/crisp-chat, seo-tools/baidu-analytics, seo-tools/matomo-analytics, seo-tools/plausible-analytics, seo-tools/counter-analytics — uncomment + pnpm update-modules to enable.
DO NOT
- Hand-edit
go.mod/go.sum— they're regenerated bypnpm update-modules. - Edit a module's files under the Go module cache or
themes/<theme>/— modules are read-only dependencies; override their partials via rootlayouts/_partials/instead (seereferences/component-usage.md). - Remove an
[[imports]]block while partials/shortcodes from that module are still referenced — fix or remove those usages first.