Merge commit '87de22d7464e239c775fbd48ebce1665d5b1e80d'

This commit is contained in:
Bjørn Erik Pedersen
2023-07-29 11:17:28 +02:00
177 changed files with 1623 additions and 1556 deletions

View File

@@ -1,12 +1,13 @@
---
title: Hugo Modules
linktitle: Hugo Modules Overview
linkTitle: Overview
description: How to use Hugo Modules.
menu:
docs:
identifier: hugo-modules-overview
parent: modules
weight: 01
weight: 01
weight: 10
weight: 10
categories: [hugo modules]
keywords: [themes,modules]
aliases: [/themes/overview/,/themes/]
@@ -22,7 +23,7 @@ Hugo Modules are powered by Go Modules. For more information about Go Modules, s
- [https://github.com/golang/go/wiki/Modules](https://github.com/golang/go/wiki/Modules)
- [https://go.dev/blog/using-go-modules](https://go.dev/blog/using-go-modules)
This is all very much brand new and there are only a few example projects around:
Some example projects:
- [https://github.com/bep/docuapi](https://github.com/bep/docuapi) is a theme that has been ported to Hugo Modules while testing this feature. It is a good example of a non-Hugo-project mounted into Hugos folder structure. It even shows a JS Bundler implementation in regular Go templates.
- [https://github.com/bep/my-modular-site](https://github.com/bep/my-modular-site) is a very simple site used for testing.

View File

@@ -1,17 +1,17 @@
---
title: Configure Modules
title: Configure Hugo modules
description: This page describes the configuration options for a module.
categories: [hugo modules]
keywords: [themes, source, organization, directories]
menu:
docs:
parent: modules
weight: 10
weight: 10
weight: 20
weight: 20
toc: true
---
## Module Config: Top level
## Module configuration: top level
{{< code-toggle file="hugo" >}}
[module]
@@ -39,10 +39,10 @@ private
: Comma separated glob list matching paths that should be treated as private.
workspace
: The workspace file to use. This enables Go workspace mode. Note that this can also be set via OS env, e.g. `export HUGO_MODULE_WORKSPACE=/my/hugo.work` This only works with Go 1.18+. In Hugo `v0.109.0` we changed the default to `off` and we now resolve any relative work filenames relative to the working directory.
: The workspace file to use. This enables Go workspace mode. Note that this can also be set via OS env, e.g. `export HUGO_MODULE_WORKSPACE=/my/hugo.work` This only works with Go 1.18+. In Hugo `v0.109.0` we changed the default to `off` and we now resolve any relative work file names relative to the working directory.
replacements
: A comma-separated list of mappings from module paths to directories, e.g. `github.com/bep/my-theme -> ../..,github.com/bep/shortcodes -> /some/path`. This is mostly useful for temporary local development of a module, in which case you might want to save it as an environment variable, e.g: `env HUGO_MODULE_REPLACEMENTS="github.com/bep/my-theme -> ../.."`. Relative paths are relative to [themesDir](https://gohugo.io/getting-started/configuration/#all-configuration-settings). Absolute paths are allowed.
: A comma-separated list of mappings from module paths to directories, e.g. `github.com/bep/my-theme -> ../..,github.com/bep/shortcodes -> /some/path`. This is mostly useful for temporary local development of a module, in which case you might want to save it as an environment variable, e.g: `env HUGO_MODULE_REPLACEMENTS="github.com/bep/my-theme -> ../.."`. Relative paths are relative to [themesDir](/getting-started/configuration/#all-configuration-settings). Absolute paths are allowed.
Note that the above terms maps directly to their counterparts in Go Modules. Some of these setting may be natural to set as OS environment variables. To set the proxy server to use, as an example:
@@ -52,7 +52,7 @@ env HUGO_MODULE_PROXY=https://proxy.example.org hugo
{{< gomodules-info >}}
## Module Config: hugoVersion
## Module configuration: hugoVersion
If your module requires a particular version of Hugo to work, you can indicate that in the `module` section and the user will be warned if using a too old/new version.
@@ -76,7 +76,7 @@ max
extended
: Whether the extended version of Hugo is required.
## Module Config: imports
## Module configuration: imports
{{< code-toggle file="hugo" >}}
[module]
@@ -109,10 +109,10 @@ noVendor
{{< gomodules-info >}}
## Module Config: mounts
## Module configuration: mounts
{{% note %}}
When the `mounts` config was introduced in Hugo 0.56.0, we were careful to preserve the existing `contentDir`, `staticDir`, and similar configuration to make sure all existing sites just continued to work. But you should not have both: if you add a `mounts` section you should remove the old `contentDir`, `staticDir`, etc. settings.
When the `mounts` configuration was introduced in Hugo 0.56.0, we were careful to preserve the existing `contentDir`, `staticDir`, and similar configuration to make sure all existing sites just continued to work. But you should not have both: if you add a `mounts` section you should remove the old `contentDir`, `staticDir`, etc. settings.
{{% /note %}}
{{% note %}}
@@ -157,7 +157,7 @@ lang
includeFiles (string or slice)
: One or more [glob](https://github.com/gobwas/glob) patterns matching files or directories to include. If `excludeFiles` is not set, the files matching `includeFiles` will be the files mounted.
The glob patterns are matched to the filenames starting from the `source` root, they should have Unix styled slashes even on Windows, `/` matches the mount root and `**` can be used as a super-asterisk to match recursively down all directories, e.g `/posts/**.jpg`.
The glob patterns are matched to the file names starting from the `source` root, they should have Unix styled slashes even on Windows, `/` matches the mount root and `**` can be used as a super-asterisk to match recursively down all directories, e.g `/posts/**.jpg`.
The search is case-insensitive.

View File

@@ -1,17 +1,20 @@
---
title: Theme Components
title: Theme components
description: Hugo provides advanced theming support with Theme Components.
categories: [hugo modules]
keywords: [themes, theme, source, organization, directories]
menu:
docs:
parent: modules
weight: 50
weight: 50
weight: 40
weight: 40
aliases: [/themes/customize/,/themes/customizing/]
toc: true
---
{{% note %}}
This section contain information that may be outdated and is in the process of being rewritten.
{{% /note %}}
@@ -40,6 +43,6 @@ Also note that a component that is part of a theme can have its own configuratio
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
The same rules apply here: The left-most parameter/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
[^1]: For themes hosted on the [Hugo Themes Showcase](https://themes.gohugo.io/) components need to be added as git submodules that point to the directory `exampleSite/themes`

View File

@@ -6,8 +6,8 @@ keywords: [install, themes, source, organization, directories,usage,modules]
menu:
docs:
parent: modules
weight: 20
weight: 20
weight: 30
weight: 30
aliases: [/themes/usage/,/themes/installing/,/installing-and-using-themes/]
toc: true
---
@@ -16,7 +16,7 @@ toc: true
{{< gomodules-info >}}
## Initialize a New Module
## Initialize a new module
Use `hugo mod init` to initialize a new Hugo Module. If it fails to guess the module path, you must provide it as an argument, e.g.:
@@ -26,9 +26,9 @@ hugo mod init github.com/gohugoio/myShortcodes
Also see the [CLI Doc](/commands/hugo_mod_init/).
## Use a Module for a Theme
## Use a module for a theme
The easiest way to use a Module for a theme is to import it in the config.
The easiest way to use a Module for a theme is to import it in the configuration.
1. Initialize the hugo module system: `hugo mod init github.com/<your_user>/<your_project>`
2. Import the theme:
@@ -39,33 +39,33 @@ The easiest way to use a Module for a theme is to import it in the config.
path = "github.com/spf13/hyde"
{{< /code-toggle >}}
## Update Modules
## Update modules
Modules will be downloaded and added when you add them as imports to your configuration, see [Module Imports](/hugo-modules/configuration/#module-config-imports).
Modules will be downloaded and added when you add them as imports to your configuration, see [Module Imports](/hugo-modules/configuration/#module-configuration-imports).
To update or manage versions, you can use `hugo mod get`.
Some examples:
### Update All Modules
### Update all modules
```bash
hugo mod get -u
```
### Update All Modules Recursively
### Update all modules recursively
```bash
hugo mod get -u ./...
```
### Update One Module
### Update one module
```bash
hugo mod get -u github.com/gohugoio/myShortcodes
```
### Get a Specific Version
### Get a specific version
```bash
hugo mod get github.com/gohugoio/myShortcodes@v1.0.7
@@ -83,9 +83,9 @@ replace github.com/bep/hugotestmods/mypartials => /Users/bep/hugotestmods/mypart
If you have the `hugo server` running, the configuration will be reloaded and `/Users/bep/hugotestmods/mypartials` put on the watch list.
Instead of modifying the `go.mod` files, you can also use the modules config [`replacements`](https://gohugo.io/hugo-modules/configuration/#module-config-top-level) option.
Instead of modifying the `go.mod` files, you can also use the modules configuration [`replacements`](/hugo-modules/configuration/#module-configuration-top-level) option.
## Print Dependency Graph
## Print dependency graph
Use `hugo mod graph` from the relevant module directory and it will print the dependency graph, including vendoring, module replacement or disabled status.
@@ -106,7 +106,7 @@ github.com/bep/my-modular-site in-themesdir
Also see the [CLI Doc](/commands/hugo_mod_graph/).
## Vendor Your Modules
## Vendor your modules
`hugo mod vendor` will write all the module dependencies to a `_vendor` folder, which will then be used for all subsequent builds.
@@ -124,7 +124,7 @@ Run `hugo mod tidy` to remove unused entries in `go.mod` and `go.sum`.
Also see the [CLI Doc](/commands/hugo_mod_clean/).
## Clean Module Cache
## Clean module cache
Run `hugo mod clean` to delete the entire modules cache.
@@ -132,7 +132,7 @@ Note that you can also configure the `modules` cache with a `maxAge`, see [File
Also see the [CLI Doc](/commands/hugo_mod_clean/).
## Module Workspaces
## Module workspaces
{{< new-in "0.109.0" >}}
@@ -144,7 +144,7 @@ A workspace can be configured in a `*.work` file and activated with the [module.
See the [hugo.work](https://github.com/gohugoio/hugo/blob/master/hugo.work) file in the Hugo Docs repo for an example:
```
```text
go 1.19
use .
@@ -155,7 +155,7 @@ Using the `use` directive, list all the modules you want to work on, pointing to
With that you can start the Hugo server with that workspace enabled:
```
```bash
HUGO_MODULE_WORKSPACE=hugo.work hugo server --ignoreVendorPaths "**"
```