diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-07-24 19:44:57 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-07-25 13:21:30 +0200 |
commit | 77bf2991b1690bcde8c6570cd4c12f2041d93096 (patch) | |
tree | 2d46c4f845892e6d4e6c8c3ac6d9786094842da5 /docs/content/en | |
parent | e5f229974166402f51e4ee0695ffb4d1e09fa174 (diff) |
docs: Add Hugo Modules docs
Diffstat (limited to 'docs/content/en')
-rw-r--r-- | docs/content/en/getting-started/configuration.md | 19 | ||||
-rw-r--r-- | docs/content/en/hugo-modules/_index.md | 24 | ||||
-rw-r--r-- | docs/content/en/hugo-modules/configuration.md | 126 | ||||
-rw-r--r-- | docs/content/en/hugo-modules/theme-components.md (renamed from docs/content/en/themes/theme-components.md) | 13 | ||||
-rw-r--r-- | docs/content/en/hugo-modules/use-modules.md | 122 | ||||
-rw-r--r-- | docs/content/en/themes/_index.md | 26 | ||||
-rw-r--r-- | docs/content/en/themes/creating.md | 75 | ||||
-rw-r--r-- | docs/content/en/themes/installing-and-using-themes.md | 114 |
8 files changed, 292 insertions, 227 deletions
diff --git a/docs/content/en/getting-started/configuration.md b/docs/content/en/getting-started/configuration.md index 4119ae8ef..1cf692382 100644 --- a/docs/content/en/getting-started/configuration.md +++ b/docs/content/en/getting-started/configuration.md @@ -38,7 +38,7 @@ hugo --config a.toml,b.toml,c.toml Multiple site config files can be specified as a comma-separated string to the `--config` switch. {{% /note %}} -TODO: distinct config.toml and others (the root object files) +{{< todo >}}TODO: distinct config.toml and others (the root object files){{< /todo >}} ## Configuration Directory @@ -76,10 +76,10 @@ value in parentheses. Users may choose to override those values in their site config file(s). archetypeDir ("archetypes") -: The directory where Hugo finds archetype files (content templates). +: The directory where Hugo finds archetype files (content templates). {{% module-mounts-note %}} assetDir ("assets") -: The directory where Hugo finds asset files used in [Hugo Pipes](/hugo-pipes/). +: The directory where Hugo finds asset files used in [Hugo Pipes](/hugo-pipes/). {{% module-mounts-note %}} baseURL : Hostname (and path) to the root, e.g. http://bep.is/ @@ -103,10 +103,10 @@ canonifyURLs (false) : Enable to turn relative URLs into absolute. contentDir ("content") -: The directory from where Hugo reads content files. +: The directory from where Hugo reads content files. {{% module-mounts-note %}} dataDir ("data") -: The directory from where Hugo reads data files. +: The directory from where Hugo reads data files. {{% module-mounts-note %}} defaultContentLanguage ("en") : Content without language indicator will default to this language. @@ -190,6 +190,9 @@ menu metaDataFormat ("toml") : Front matter meta-data format. Valid values: `"toml"`, `"yaml"`, or `"json"`. +module +: Module config see [Module Config](/hugo-modules/configuration/). + newContentEditor ("") : The editor to use when creating new content. @@ -245,7 +248,7 @@ sitemap : Default [sitemap configuration](/templates/sitemap-template/#configure-sitemap-xml). staticDir ("static") -: A directory or a list of directories from where Hugo reads [static files][static-files]. +: A directory or a list of directories from where Hugo reads [static files][static-files]. {{% module-mounts-note %}} summaryLength (70) : The length of text in words to show in a [`.Summary`](/content-management/summaries/#hugo-defined-automatic-summary-splitting). @@ -470,9 +473,11 @@ maxAge = -1 [caches.assets] dir = ":resourceDir/_gen" maxAge = -1 +[caches.modules] +dir = ":cacheDir/modules" +maxAge = -1 ``` - You can override any of these cache setting in your own `config.toml`. ### The keywords explained diff --git a/docs/content/en/hugo-modules/_index.md b/docs/content/en/hugo-modules/_index.md new file mode 100644 index 000000000..1d870d12d --- /dev/null +++ b/docs/content/en/hugo-modules/_index.md @@ -0,0 +1,24 @@ +--- +title: Hugo Modules +linktitle: Hugo Modules Overview +description: How to use Hugo Modules. +date: 2017-02-01 +publishdate: 2017-02-01 +menu: + docs: + parent: "modules" + weight: 01 +weight: 01 +sections_weight: 01 +categories: [hugo modules] +keywords: [themes,modules] +draft: false +aliases: [/themes/overview/,/themes/] +toc: true +--- + +**Hugo Modules** are the core building blocks in Hugo. A _module_ can be your main project or a smaller module providing one or more of the 7 component types defined in Hugo: **static**, **content**, **layouts**, **data**, **assets**, **i18n**, and **archetypes**. + +You can combine modules in any combination you like, and even mount directories from non-Hugo projects, forming a big, virtual union file system. + + diff --git a/docs/content/en/hugo-modules/configuration.md b/docs/content/en/hugo-modules/configuration.md new file mode 100644 index 000000000..293aa2ca7 --- /dev/null +++ b/docs/content/en/hugo-modules/configuration.md @@ -0,0 +1,126 @@ +--- +title: Configure Modules +linktitle: Configure Modules +description: This page describes the configuration options for a module. +date: 2019-07-24 +categories: [hugo modules] +keywords: [themes, source, organization, directories] +menu: + docs: + parent: "modules" + weight: 10 +weight: 10 +sections_weight: 10 +toc: true +--- + +## Module Config: Top level + +{{< code-toggle file="config">}} +[module] +proxy = "direct" +noProxy = "none" +private = "*.*" +{{< /code-toggle >}} + +proxy +: Defines the proxy server to use to download remote modules. Default is `direct`, which means "git clone" and similar. + +noProxy +: Comma separated glob list matching paths that should not use the proxy configured above. + +private +: Comma separated glob list matching paths that should be treated as private. + +Note that the above terms maps directly to their counterparts in Go Modules. Some of these setting may be natural to set as OS environvent variables. To set the proxy server to use, as an example: + +``` +env HUGO_MODULE_PROXY=https://proxy.example.org hugo +``` + +{{< gomodules-info >}} + +## Module Config: 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. + +{{< code-toggle file="config">}} +[module] +[module.hugoVersion] + min = "" + max = "" + extended = false + +{{< /code-toggle >}} + +Any of the above can be omitted. + +min +: The minimum Hugo version supported, e.g. `0.55.0` + +max +: The maximum Hugo version supported, e.g. `0.55.0` + +extended +: Whether the extended version of Hugo is required. + +## Module Config: imports + +{{< code-toggle file="config">}} +[module] +[[module.imports]] + path = "github.com/gohugoio/hugoTestModules1_linux/modh1_2_1v" + ignoreConfig = false + disable = false +[[module.imports]] + path = "my-shortcodes" +{{< /code-toggle >}} + +path +: Can be either a valid Go Module module path, e.g. `github.com/gohugoio/myShortcodes`, or the directory name for the module as stored in your themes folder. + +ignoreConfig +: If enabled, any module configuration file, e.g. `config.toml`, will not be loaded. Note that this will also stop the loading of any transitive module dependencies. + +disable +: Set to `true` to disable the module off while keeping any version info in the `go.*` files. + +{{< gomodules-info >}} + + +## Module Config: mounts + +{{< code-toggle file="config">}} +[module] +[[module.mounts]] + source="content" + target="content" +[[module.mounts]] + source="static" + target="static" +[[module.mounts]] + source="layouts" + target="layouts" +[[module.mounts]] + source="data" + target="data" +[[module.mounts]] + source="assets" + target="assets" +[[module.mounts]] + source="i18n" + target="i18n" +[[module.mounts]] + source="archetypes" + target="archetypes" +{{< /code-toggle >}} + +source +: The source direcory of the mount. For the main project, this can be either project-relative or absolute and even a symbolic link. For other modules it must be project-relative. + +target +: Where it should be mounted into Hugo's virtual filesystem. It must start with one of Hugo's component folders: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, or `archetypes`. E.g. `content/blog`. + +lang +: The language code, e.g. "en". Only relevant for `content` mounts, and `static` mounts when in multihost mode. + diff --git a/docs/content/en/themes/theme-components.md b/docs/content/en/hugo-modules/theme-components.md index 98072c533..f1feb636a 100644 --- a/docs/content/en/themes/theme-components.md +++ b/docs/content/en/hugo-modules/theme-components.md @@ -3,19 +3,22 @@ title: Theme Components linktitle: Theme Components description: Hugo provides advanced theming support with Theme Components. date: 2017-02-01 -categories: [themes] +categories: [hugo modules] keywords: [themes, theme, source, organization, directories] menu: docs: - parent: "themes" - weight: 20 -weight: 20 -sections_weight: 20 + parent: "modules" + weight: 50 +weight: 50 +sections_weight: 50 draft: false 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 %}} Since Hugo `0.42` a project can configure a theme as a composite of as many theme components you need: {{< code-toggle file="config">}} diff --git a/docs/content/en/hugo-modules/use-modules.md b/docs/content/en/hugo-modules/use-modules.md new file mode 100644 index 000000000..ed467c512 --- /dev/null +++ b/docs/content/en/hugo-modules/use-modules.md @@ -0,0 +1,122 @@ +--- +title: Use Hugo Modules +linktitle: Use Hugo Modules +description: How to use Hugo Modules to build and manage your site. +date: 2019-07-24 +categories: [hugo modules] +keywords: [install, themes, source, organization, directories,usage,modules] +menu: + docs: + parent: "modules" + weight: 20 +weight: 20 +sections_weight: 20 +draft: false +aliases: [/themes/usage/,/themes/installing/,/installing-and-using-themes/] +toc: true +--- + +## Prerequisites + +{{% gomodules-info %}} + + + +## 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.: + +```bash +hugo mod init github.com/gohugoio/myShortcodes +``` + + +Also see the [CLI Doc](/commands/hugo_mod_init/). + +## 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). + +To update or manage versions, you can use `hugo mod get`. + +Some examples: + +### Update All Modules + +```bash +hugo mod get -u +``` +### Update One Module + +```bash +hugo mod get -u github.com/gohugoio/myShortcodes +``` +### Get a Specific Version + +```bash +hugo mod get github.com/gohugoio/myShortcodes@v1.0.7 +``` + +Also see the [CLI Doc](/commands/hugo_mod_get/). + +## Make and test changes in a module + +One way to do local development of a module imported in a project is to add a replace directive to a local directory with the source in `go.mod`: + +```bash +github.com/bep/hugotestmods/mypartials => /Users/bep/hugotestmods/mypartials +``` + +If you have the `hugo server` running, the configuration will be reloaded and `/Users/bep/hugotestmods/mypartials` put on the watch list. + + +## 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. + +E.g.: + +``` +hugo mod graph + +github.com/bep/my-modular-site github.com/bep/hugotestmods/mymounts@v1.2.0 +github.com/bep/my-modular-site github.com/bep/hugotestmods/mypartials@v1.0.7 +github.com/bep/hugotestmods/mypartials@v1.0.7 github.com/bep/hugotestmods/myassets@v1.0.4 +github.com/bep/hugotestmods/mypartials@v1.0.7 github.com/bep/hugotestmods/myv2@v1.0.0 +DISABLED github.com/bep/my-modular-site github.com/spf13/hyde@v0.0.0-20190427180251-e36f5799b396 +github.com/bep/my-modular-site github.com/bep/hugo-fresh@v1.0.1 +github.com/bep/my-modular-site in-themesdir + +``` + +Also see the [CLI Doc](/commands/hugo_mod_graph/). + +## Vendor Your Modules + +`hugo mod vendor` will write all the module depencies to a `_vendor` folder, which will then be used for all subsequent builds. + +Note that: + +* You can run `hugo mod vendor` on any level in the module tree. +* Vendoring will not store modules stored in your `themes` folder. +* Most commands accept a `--ignoreVendor` flag, which will then run as if the none of the `_vendor` folders in the module tree did not exist. + +Also see the [CLI Doc](/commands/hugo_mod_vendor/). + + +## Tidy go.mod, go.sum + +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 + +Run `hugo mod clean` to delete the entire modules cache. + +Note that you can also configure the `modules` cache with a `maxAge`, see [File Caches](/configuration/#configure-file-caches). + + + +Also see the [CLI Doc](/commands/hugo_mod_clean/). diff --git a/docs/content/en/themes/_index.md b/docs/content/en/themes/_index.md deleted file mode 100644 index 6a135dd39..000000000 --- a/docs/content/en/themes/_index.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: Themes -linktitle: Themes Overview -description: Install, use, and create Hugo themes. -date: 2017-02-01 -publishdate: 2017-02-01 -lastmod: 2017-02-01 -menu: - docs: - parent: "themes" - weight: 01 -weight: 01 -sections_weight: 01 -categories: [themes] -keywords: [themes,introduction,overview] -draft: false -aliases: [/themes/overview/] -toc: false ---- - -Hugo provides a robust theming system that is easy to implement yet feature complete. You can view the themes created by the Hugo community on the [Hugo themes website][hugothemes]. - -Hugo themes are powered by the excellent Go template library and are designed to reduce code duplication. They are easy to both customize and keep in sync with the upstream theme. - -[goprimer]: /templates/introduction/ -[hugothemes]: http://themes.gohugo.io/ diff --git a/docs/content/en/themes/creating.md b/docs/content/en/themes/creating.md deleted file mode 100644 index d96942a58..000000000 --- a/docs/content/en/themes/creating.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: Create a Theme -linktitle: Create a Theme -description: The `hugo new theme` command will scaffold the beginnings of a new theme for you to get you on your way. -date: 2017-02-01 -publishdate: 2017-02-01 -lastmod: 2017-02-01 -categories: [themes] -keywords: [themes, source, organization, directories] -menu: - docs: - parent: "themes" - weight: 30 -weight: 30 -sections_weight: 30 -draft: false -aliases: [/themes/creation/,/tutorials/creating-a-new-theme/] -toc: true -wip: true ---- - -{{% warning "Use Absolute Links" %}} -If you're creating a theme with plans to share it on the [Hugo Themes website](https://themes.gohugo.io/) please note the following: -- If using inline styles you will need to use absolute URLs, for the linked assets to be served properly, e.g. `<div style="background: url('{{ "images/background.jpg" | absURL }}')">` -- Make sure not to use a forward slash `/` in the beginning of a `URL`, because it will point to the host root. Your theme's demo will be available in a subdirectory of the Hugo website and in this scenario Hugo will not generate the correct `URL` for theme assets. -- If using external CSS and JS from a CDN, make sure to load these assets over `https`. Please do not use relative protocol URLs in your theme's templates. -{{% /warning %}} - -Hugo can initialize a new blank theme directory within your existing `themes` using the `hugo new` command: - -``` -hugo new theme [name] -``` - -## Theme Folders - -A theme component can provide files in one or more of the following standard Hugo folders: - -layouts -: Templates used to render content in Hugo. Also see [Templates Lookup Order](/templates/lookup-order/). - -static -: Static files, such as logos, CSS and JavaScript. - -i18n -: Language bundles. - -data -: Data files. - -archetypes -: Content templates used in `hugo new`. - - -## Theme Configuration File - -A theme component can also provide its own [Configuration File](/getting-started/configuration/), e.g. `config.toml`. There are some restrictions to what can be configured in a theme component, and it is not possible to overwrite settings in the project. - -The following settings can be set: - -* `params` (global and per language) -* `menu` (global and per language) -* `outputformats` and `mediatypes` - - -## Theme Description File - -In addition to the configuration file, a theme can also provide a `theme.toml` file that describes the theme, the author and origin etc. See [Add Your Hugo Theme to the Showcase](/contribute/themes/). - - -{{% note "Use the Hugo Generator Tag" %}} -The [`.Hugo.Generator`](/variables/hugo/) tag is included in all themes featured in the [Hugo Themes Showcase](http://themes.gohugo.io). We ask that you include the generator tag in all sites and themes you create with Hugo to help the core team track Hugo's usage and popularity. -{{% /note %}} - - diff --git a/docs/content/en/themes/installing-and-using-themes.md b/docs/content/en/themes/installing-and-using-themes.md deleted file mode 100644 index 93d814231..000000000 --- a/docs/content/en/themes/installing-and-using-themes.md +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: Install and Use Themes -linktitle: Install and Use Themes -description: Install and use a theme from the Hugo theme showcase easily through the CLI. -date: 2017-02-01 -publishdate: 2017-02-01 -lastmod: 2017-02-01 -categories: [themes] -keywords: [install, themes, source, organization, directories,usage] -menu: - docs: - parent: "themes" - weight: 10 -weight: 10 -sections_weight: 10 -draft: false -aliases: [/themes/usage/,/themes/installing/] -toc: true -wip: true ---- - -{{% note "No Default Theme" %}} -Hugo currently doesn’t ship with a “default” theme. This decision is intentional. We leave it up to you to decide which theme best suits your Hugo project. -{{% /note %}} - -## Assumptions - -1. You have already [installed Hugo on your development machine][install]. -2. You have git installed on your machine and you are familiar with basic git usage. - -## Install Themes - -{{< youtube L34JL_3Jkyc >}} - -The community-contributed themes featured on [themes.gohugo.io](//themes.gohugo.io/) are hosted in a [centralized GitHub repository][themesrepo]. The Hugo Themes Repo at <https://github.com/gohugoio/hugoThemes> is really a meta repository that contains pointers to a set of contributed themes. - -{{% warning "Get `git` First" %}} -Without [Git](https://git-scm.com/) installed on your computer, none of the following theme instructions will work. Git tutorials are beyond the scope of the Hugo docs, but [GitHub](https://try.github.io/) and [codecademy](https://www.codecademy.com/learn/learn-git) offer free, interactive courses for beginners. -{{% /warning %}} - -### Install All Themes - -You can install *all* available Hugo themes by cloning the entire [Hugo Theme repository on GitHub][themesrepo] from within your working directory. Depending on your internet connection the download of all themes might take a while. - -``` -git clone --depth 1 --recursive https://github.com/gohugoio/hugoThemes.git themes -``` - -Before you use a theme, remove the .git folder in that theme's root folder. Otherwise, this will cause problem if you deploy using Git. - -### Install a Single Theme - -Change into the `themes` directory and download a theme by replacing `URL_TO_THEME` with the URL of the theme repository: - -``` -cd themes -git clone URL_TO_THEME -``` - -The following example shows how to use the "Hyde" theme, which has its source hosted at <https://github.com/spf13/hyde>: - -{{< code file="clone-theme.sh" >}} -cd themes -git clone https://github.com/spf13/hyde -{{< /code >}} - -Alternatively, you can download the theme as a `.zip` file, unzip the theme contents, and then move the unzipped source into your `themes` directory. - -{{% note "Read the `README`" %}} -Always review the `README.md` file that is shipped with a theme. Often, these files contain further instructions required for theme setup; e.g., copying values from an example configuration file. -{{% /note %}} - -## Theme Placement - -Please make certain you have installed the themes you want to use in the -`/themes` directory. This is the default directory used by Hugo. Hugo comes with the ability to change the themes directory via the [`themesDir` variable in your site configuration][config], but this is not recommended. - -## Use Themes - -Hugo applies the decided theme first and then applies anything that is in the local directory. This allows for easier customization while retaining compatibility with the upstream version of the theme. To learn more, go to [customizing themes][customizethemes]. - -### Command Line - -There are two different approaches to using a theme with your Hugo website: via the Hugo CLI or as part of your [site configuration file][config]. - -To change a theme via the Hugo CLI, you can pass the `-t` [flag][] when building your site: - -``` -hugo -t themename -``` - -Likely, you will want to add the theme when running the Hugo local server, especially if you are going to [customize the theme][customizethemes]: - -``` -hugo server -t themename -``` - -### `config` File - -If you've already decided on the theme for your site and do not want to fiddle with the command line, you can add the theme directly to your [site configuration file][config]: - -``` -theme: themename -``` - -{{% note "A Note on `themename`" %}} -The `themename` in the above examples must match the name of the specific theme directory inside `/themes`; i.e., the directory name (likely lowercase and urlized) rather than the name of the theme displayed in the [Themes Showcase site](http://themes.gohugo.io). -{{% /note %}} - -[customizethemes]: /themes/customizing/ -[flag]: /getting-started/usage/ "See the full list of flags in Hugo's basic usage." -[install]: /getting-started/installing/ -[config]: /getting-started/configuration/ "Learn how to customize your Hugo website configuration file in yaml, toml, or json." -[themesrepo]: https://github.com/gohugoio/hugoThemes |