Skip to content

theNewDynamic/hugo-module-tnd-iubenda

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

iubenda Hugo Module

This module facilitates setting up Iubenda on a Hugo project through the use of a simple shortcode.

Requirements

Requirements:

  • Go 1.14
  • Hugo 0.64.0

Installation

If not already, init your project as a Hugo Module:

$: hugo mod init {repo_url}

Configure your project's module to import this module:

# config.yaml
module:
  imports:
  - path: github.com/theNewDynamic/hugo-module-tnd-iubenda

Usage

You can invoke Iubenda content with using the Module's built-in shortcode.

tnd-iubenda Shortcode

The shortcode takes only one argument, the type of document to be printed. Available document types are:

  • privacy-policy
  • cookie-policy
  • terms-and-conditions

Examples

---
# content/privacy-policy.md
title: We Respect your Privacy
description: We really do. We're not collecting any data from you that you don't know about, and we keep that data to ourselves.
---

{{< tnd-iubenda "privacy-policy" >}}

API KEY

To obfuscate the API Key from the repo, the Module uses Environment variables to read you Iubenda's API Key.

Monolingual site

Store your key in TND_IUBENDA_KEY

Multilingual sites

Iubenda provides one key per language.

Store your key in TND_IUBENDA_KEY_{LANG} where LANG is the language code of the page as registered through HUGO. Ex: For a multilingual site with english and french versions of Iubenda documents, you should use: TND_IUBENDA_KEY_FR and TND_IUBENDA_KEY_EN

Access KEYS from local while maintaining obfuscation.

The module uses a partial at tnd-iubenda/private/GetAPIKey.html.

By adding an homonymous partial to your project's layouts/partials directory, it will supersede the module's when found.

{{/* layouts/partials/tnd-iubenda/private/GetAPIKey.html */}}
{{ $key := "" }}
{{ if eq site.Language.Lang "en" }}
  {{ $key = "9XXXXXX9" }}
{{ else }}
  {{ $key = "4XXXXXX4" }}
{{ end }}

{{ return $key }}

You can then and add the file to your .gitignore and maintain your API key's obfuscation.

From now on, your local build will use your project's partial while your deployment service will use the Module's own GetAPIKey partial which relies on environment variables.

Caching

The module uses Hugo's getJSON to grab the document content using Iubenda's API. In order to avoid calling the API on every build we rely on Hugo's cache default configuration. (unlimited cache).

It does mean though, that from now on, we must bust this cache. The easiest way to do that is by using the version setting described bellow.

If the version settings is not used, you should edit your project's File Caches settings accordlingly.

Settings

Settings are added to the project's parameter under the tnd_iubenda map as shown below.

# config.yaml
params:
  tnd_iubenda:
    version: v1.0
    no_markup: true

version

Allow's cache busting by updating the parameter with a new value whenever the Iubenda API response needs to be refreshed --- most likey after editing the settings of any given document.

no_markup

If you need to print documents free of any iubenda default markup, no_markup should be set to true.

Styling

Users are free to add any styling involving Iubenda to their own styling pipeline. Bot for ease of use, the module will print in a style tag the content of an asset file named assets/tnd-iubenda/style.css if found on the project.

So for:

/* assets/tnd-iubenda/style.css */
.iub_content h1{
  margin-top: 2rem;
  font-size: 2.25rem;
}

The module will print above the Iubenda document the following:

<style>
.iub_content h1{
  margin-top: 2rem;
  font-size: 2.25rem;
}
</style>

theNewDynamic

This project is maintained and love by thenewDynamic.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages