# Modules

Customize and extend Hinode with Hugo modules.

Added in v0.16.0

Hinode supports [Hugo modules](https://gohugo.io/hugo-modules/) to provide a flexible and extensible modular framework. By default, Hinode includes core building blocks for [Bootstrap](https://getbootstrap.com), [FlexSearch](https://github.com/nextapps-de/flexsearch), and [Font Awesome](https://fontawesome.com). The following paragraphs explain how to customize the module configuration.

## Importing modules

By default, the Hinode template imports Hinode as module itself. In this approach, the modules that Hinode includes are imported as transitive modules. Adjust the `module` section in your site's configuration file `config/_default/hugo.toml` to import or adjust the required modules. Visit the Hugo documentation to [review all available configuration settings](https://gohugo.io/hugo-modules/configuration/). You can [disable individual modules](https://gohugo.io/hugo-modules/configuration/#module-configuration-imports) by setting `disable` to `true`.

```toml
  [[module.imports]]
    path = "github.com/gethinode/hinode/v3"
```

The main repository of Hinode imports the following modules by default.

```toml
  [[module.imports]]
    path = "github.com/gethinode/mod-bootstrap"
  [[module.imports]]
    path = "github.com/gethinode/mod-csp"
  [[module.imports]]
    path = "github.com/gethinode/mod-flexsearch/v5"
  [[module.imports]]
    path = "github.com/gethinode/mod-fontawesome/v6"
  [[module.imports]]
    path = "github.com/gethinode/mod-google-analytics/v2"
  [[module.imports]]
    path = "github.com/gethinode/mod-katex"
  [[module.imports]]
    path = "github.com/gethinode/mod-leaflet/v3"
  [[module.imports]]
    path = "github.com/gethinode/mod-lottie/v3"
  [[module.imports]]
    path = "github.com/gethinode/mod-mermaid/v5"
  [[module.imports]]
    path = "github.com/gethinode/mod-simple-datatables/v4"
  [[module.imports]]
    path = "github.com/gethinode/mod-utils/v6"
```

## Configuring modules

> [!NOTE]
> Hinode uses the default configuration defined in each referenced module since release Added in v0.24.0. You can override these settings in your site parameters.

You can choose to either fully integrate compatible modules or to include them on a page-by-page basis. For example, you might only want to display an interactive map on a few pages. In this case, you could choose to include the `leaflet` module on an opt-in basis. This ensures the page size is minimized. On the other hand, as `bootstrap` is used on every single page, it makes sense to include it as a core module.

For core modules, Hinode bundles the provided [stylesheet files](styles) and [JavaScript files](scripts) into the main stylesheet and core script bundles. For optional modules, Hinode prepares separate stylesheet files and JavaScript files for each individual module. The configuration order of the core modules is important: **the first module is processed before the next modules**.

> [!NOTE]
> Hugo uses two different algorithms to merge the filesystems, depending on the file type:
>
> - For `i18n` and `data` files, Hugo merges deeply using the translation ID and data key inside the files.
> - For `static`, `layouts` (templates), and `archetypes` files, these are merged on file level, so the left-most file will be chosen.

Adjust the `modules` section in your site's parameter configuration file `config/_default/params.toml` to configure the various modules. Modules can include files for each of the following folders: `archetypes`, `assets`, `content`, `data`, `i18n`, `layouts`, `static`. Modules can also have their own configuration files. Each module needs to be imported as well ([see the previous paragraph](#configuring-modules)).

Added in v0.24.0

The following table provides an overview of the available settings for each module. Omit the `mod-` prefix of the module's name.

| Setting           | Default  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|-------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `integration`     | optional | Module integration, either `core` or `optional`. Core modules are fully integrated with the Hinode site, including stylesheets and Javascript bundles. The modules are processed in order of priority, with the first module taking precedence. Optional modules are only included on those pages that reference the module in the frontmatter. Hinode includes the following core modules by default: ["bootstrap", "flexsearch", "fontawesome"]. |
| `excludeSCSS`     | false    | Excludes the module from the stylesheet processing pipeline. Use this setting to get more control of when and where to include the module's stylesheet. For example, the Bootstrap stylesheet is imported by the main stylesheet after initializing the theme variables, but before the custom component styles.                                                                                                                                   |
| `disableTemplate` | false    | Excludes all scripts files from processing as Hugo template. The scripts are bundled as-is instead. This only applies to optional modules.                                                                                                                                                                                                                                                                                                         |
| `localize`        | false    | {{< release version="v0.25.0" short="true" button-size="sm" inline="true" >}} Triggers the creation of a language-specific bundle file. The language code is appended as suffix to the base name. For example, the English version of `js/main.bundle.js` becomes `js/main.bundle.en.js`.                                                                                                                                                      |
| `category`        | other    | {{< release version="v0.27.0" short="true" button-size="sm" inline="true" >}} Assigns the module's scripts to a category used for cookie consent. Available values are `necessary`, `functional`, `analytics`, `performance`, `advertisement`, and `other`. See {{< link "cookie-consent" />}} for more details.                                                                                                                           |
| `local`           | false    | {{< release version="v0.27.0" short="true" button-size="sm" inline="true" >}} Includes an external URL in local mode too. By default, external scripts are only included in the built site.                                                                                                                                                                                                                                                    |
| `url`             |          | {{< release version="0.27.0" short="true" button-size="sm" inline="true" >}} Optional url for an external link. If set, the link is included in the page header or page body, pending `integration` type. See the {{< link "/docs/advanced-settings/scripts" >}}scripts documentation{{< /link >}} for more information.                                                                                                                   |

> [!IMPORTANT]
> Since release Added in v3.7.0, an unrecognized `integration` value causes the build to fail. Previous releases silently dropped the module from the script bundles instead.

For example, Bootstrap uses the following configuration in its module configuration:

```toml
[params.modules.bootstrap]
  integration = "core"
  excludeSCSS = true
```

## Configuring module-specific extensions

Several modules support additional, module-specific configurations. Review them in the next paragraphs.

### Blocks

The `blocks` module (imported as `mod-blocks`) provides Bookshop content blocks for visual page building. Its configuration is nested under `params.modules.bookshop`.

| Setting                          | Default    | Description                                                                                    |
|----------------------------------|------------|------------------------------------------------------------------------------------------------|
| `bookshop.hero.align`            | `start`    | Default horizontal alignment of hero content: `start`, `center`, or `end`.                    |
| `bookshop.hero.overlayMode`      | `dark`     | Default overlay mode applied to the hero background: `dark` or `light`.                       |
| `bookshop.hero.section`          | true       | If set, wraps the hero block in an HTML `<section>` element.                                  |
| `bookshop.hero.default`          | `[section]`| Default CSS classes applied to the hero block.                                                |
| `bookshop.articles.moreButton`   | true       | If set, displays a "read more" button below the articles block.                               |
| `bookshop.title.arrangement`     | `above`    | Position of the title label relative to the heading: `above` or `below`.                     |

### Clarity

> [!WARNING]
> This module assumes you have properly configured a Cookie Consent Manager. The Clarity script is assigned to the category `analytics`. Cookie consent is automatically given when this script is loaded. Do not load this script without explicit consent from the user. See the [Hinode docs](docs/configuration/cookie-consent/) for more details.

This module supports the following parameters (see the section `params.modules` in `config.toml`):

| Setting         | Default | Description                                                                                                                |
|-----------------|---------|----------------------------------------------------------------------------------------------------------------------------|
| `clarity.id`    |         | Tracking code of Microsoft Clarity (see [installation instructions](https://learn.microsoft.com/en-us/clarity/setup-and-installation/clarity-setup#install-manually))               |
| `clarity.force` | false   | Trigger to force include the analytics scripts, bypassing other settings. Use this setting for debugging and testing only. |

### CookieYes

Added in v0.27.0

The `cookieyes` module requires the following settings:

| Setting           | Default | Description                                                                                                                                                                                                                                                                                                         |
|-------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cookieyes.local` | false   | Trigger to force include the CookieYes scripts, bypassing other settings. Use this setting for debugging and testing only.                                                                                                                                                                                          |
| `cookieyes.url`   |         | Link to your personalized CookieYes script. See the installation code in the advanced settings of your CookieYes account. The code is available by clicking the button next to the cookie banner status. The link has the following pattern: `https://cdn-cookieyes.com/client_data/{installation code}/script.js`. |

### Flexsearch

The `flexsearch` module supports the following parameters.

| Setting                   | Default  | Description |
|---------------------------|----------|-------------|
| `flexsearch.canonifyURLs` | false    | If set, uses absolute URLs for the indexed pages instead of relative URLs. |
| `flexsearch.frontmatter`  | false    | If set, includes front matter in the page content. The search index function adds all parameters with the name `content`, `heading`, `title`, `preheading` recursively. |
| `flexsearch.filter`       | "params" | Restricts the scanned frontmatter variables to the named filter. By default, all front matter variables are scanned. Only applicable when `flexsearch.frontmatter` is set. |
| `flexsearch.summaryOnly`  | false    | If set, indexes each page's summary instead of its full content. Reduces the size of the generated search index considerably on large sites, at the cost of matching only summary text. |
| `flexsearch.lazyLoad`     | false    | If set, the search index is emitted as a separate per-language JSON file and fetched on the visitor's first search interaction, instead of being bundled into the core script loaded on every page. See the note below on Content Security Policy. |

> [!NOTE]
> With `flexsearch.lazyLoad` enabled the search index is fetched at runtime. A
> site that sets a strict Content Security Policy must allow `connect-src 'self'`.
> The module declares this directive in its `csp` block, so sites using the
> Hinode CSP module pick it up automatically.

In addition, the module recognizes the following site parameters (see the section `params.navigation` in `config.toml`):.

| Setting          | Default | Description |
|------------------|---------|-------------|
| `search.enabled` | false   | If set, enables search in the site's main navigation. |
| `search.modal`   | false   | If set, uses a modal form for search queries. Defaults to an embedded input field. |

The icon used by modal search is read from the central `[icons]` section in `params.toml`:

| Setting         | Default                | Description |
|-----------------|------------------------|-------------|
| `icons.search`  | `fas magnifying-glass` | Defines the icon used in the site's main navigation. Only applicable to `modal` search. |

### Font Awesome

Added in v0.17.0

The `fontawesome` module supports the following additional settings:

| Setting                     | Default     | Description                                                                                                                                                                                                                             |
|-----------------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fontawesome.mode`          | `symbols`   | Rendering mode: `symbols` generates an SVG symbol map (most efficient, requires the partial `assets/symbols.html` in the page context), `svg` uses per-icon inline SVG, `webfonts` uses CSS web fonts. Aliases are not supported in SVG modes; use the canonical icon name instead. |
| `fontawesome.debug`         | false       | If set, prints the original code `<i class="[...]" style=[...]></i>` as comments next to the rendered icon.                                                                                                                            |
| `fontawesome.skipMissing`   | false       | If set, displays a warning when an icon cannot be found. The missing icon is replaced with a dummy. By default, Hinode exits with an error when an icon is missing.                                                                     |
| `fontawesome.defaultFamily` | `fas`       | Default icon family used when none is specified in the shortcode, e.g. `fas`, `fab`, or `bi`.                                                                                                                                          |

### Google Analytics

Added in v0.27.0

> [!NOTE]
> By convention, Hinode uses kebab case as naming convention for module names. However, the module name in the site parameters is renamed to `GoogleAnalytics` to align with Hugo's privacy settings.

Set your `G-tag` in your site configuration (usually `hugo.toml`) in the following section:

```toml
[services]
  [services.googleAnalytics]
    ID = "G-xxxxxxxxxx"
```

You can modify the privacy configuration in the following section:

```toml
[privacy]
  [privacy.googleAnalytics]
    disable = false
    respectDoNotTrack = false
```

The `google-analytics` module supports the following additional settings:

| Setting                 | Default | Description                                                                                                                |
|-------------------------|---------|----------------------------------------------------------------------------------------------------------------------------|
| `GoogleAnalytics.force` | false   | Trigger to force include the analytics scripts, bypassing other settings. Use this setting for debugging and testing only. |

### Hanko

Added in v1.8.0

A login template is available in the `layouts` folder, which is automatically mounted into your site. You can reference this template by setting `layout: login` in the frontmatter of your content page. For example, create a login page `content/login.md` with the following content.

```yml
---
title: Login
description: Login page
layout: login
---
```

The `hanko` module supports the following parameters:

| Setting            | Default | Description                                                                                                                                            |
|--------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `endpoint`         |         | Hanko API URL, such as `https://f4****-4802-49ad-8e0b-3d3****ab32.hanko.io`. Check the [Hanko console](https://cloud.hanko.io/) to retrieve the value. |
| `login-redirect`   |         | Redirect destination after a successful login, e.g. `/` to redirect to the site's homepage.                                                            |
| `logout-redirect`  |         | Redirect destination after a successful logout, e.g. `/login/` to redirect to the login page.                                                          |
| `timeout-redirect` |         | Redirect destination when the session has expired, e.g. `/login/` to redirect to the login page. A modal dialog is shown to confirm the redirect.      |

When using Content Security Policies, be sure to add the endpoint to the `connect-src` safelist. For example, the following configuration in your site parameters will enable connections to the example Hanko API URL.

```toml
[modules.hanko.csp]
    connect-src = [
        "f4****-4802-49ad-8e0b-3d3****ab32.hanko.io"
    ]
```

### Mermaid

Added in v1.7.0

The `mermaid` module supports the following parameters:

| Setting          | Default   | Description                                                                                                                                                                                  |
|------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mermaid.elk`    | false     | If set, installs the layout engine for Mermaid based on the ELK layout engine.                                                                                                               |
| `mermaid.layout` | `dagre`   | Defines which layout algorithm to use for rendering Mermaid diagrams. The default algorithm is `dagre`. Additional options are available when `mermaid.elk` is enabled, see the table below. |
| `mermaid.look`   | `classic` | Defines the default look for Mermaid diagrams, either `classic` or `handDrawn`.                                                                                                              |

The following table defines the available layout algorithms. The `elk` values require installation of the ELK layout engine (set `mermaid.elk` to `true`).

| Layout             | Description                                     |
|--------------------|-------------------------------------------------|
| `dagre`            | The default Mermaid layout.                     |
| `elk`              | The default ELK layout, which is `elk.layered`. |
| `elk.layered`      | Layered layout.                                 |
| `elk.stress`       | Stress layout.                                  |
| `elk.force`        | Force layout.                                   |
| `elk.mrtree`       | Multi-root tree layout.                         |
| `elk.sporeOverlap` | Spore overlap layout.                           |

### Utils

Added in v0.22.5

The `utils` module supports the following additional settings:

| Setting        | Default                      | Description                                                                                                                                                                                                                                                                                                      |
|----------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `utils.filter` | `[^0-9A-Za-zŽžÀ-ÿ ;.,\/'’"]` | Defines the regular expression for characters to remove from page descriptions. These page descriptions are used to define card content and metadata for search indexes. Adjust the filter to define which characters to support. You may need to adjust these settings to support specific diacritical letters. |
| `utils.raw`    | false                        | Flag to indicate page descriptions should be returned as-is. In this setting, the filter is ignored.                                                                                                                                                                                                             |

## Enabling optional modules

You can enable an optional module for a specific page by setting the following value in the page's frontmatter:

```yml
---
modules: ["simple-datatables"]
---
```

Since release Added in v3.7.0, several optional modules register themselves when their content is used on a page. Pages using the `map` shortcode (Leaflet), the `animation` shortcode (Lottie), Mermaid diagrams, or mathematical formulas (KaTeX) no longer need to list these modules in their frontmatter. The frontmatter setting remains available for the other optional modules, and for pages that use a module without invoking its shortcode.
