« Linux Package Management
  
YAML’s Folded Block Scalars »

Hugo’s intersect Function ⛅
Updated  2022-June-27

Page contents

News

2022-May-14  Published this evolving⁠[1] article.

 

Prerequisites

This article assumes you know about…

{what you love}  {what the world needs}  {what you can be paid for}  {what you are good at}

This intersection can be represented by the following Venn diagram.

Ikigai Venn Diagram

 

Syntax

In a nutshell, the syntax of Hugo’s intersect function is this:

intersect SLICE1 SLICE2

Or, in a pipeline, this:

SLICE2 | intersect SLICE1

 

💡

The order of the slice that results from this intersection is the order of SLICE1. This means that…

  • Hugo’s intersect function is not commutative, i.e., intersect SLICE1 SLICE2 is not necessarily equal to intersect SLICE2 SLICE1,

  • and this is a way to force a particular order on a slice that is the result of an intersection.

 

To learn more about this function, see…

 

Example

On the Infinite Ink website, I tag an article by including something like this in the front matter of the article:

tags:
  - content
  - gohugo
  - tech
  - yaml
  - secret

Note that the value of this tags[2] key is a slice.

 

To hide Infinite Ink’s secret⁠[3] tags from the public, I do these two steps.

  1. In config.yaml, I create the following user-⁠defined listablePortals site-⁠wide parameter.

    params:
     listablePortals:
      - activism-hacktivism
      - asciidoc
      - backup-sync
      - business-economics-money
      - cheatsheet
      - cli
      - covid
      - emoji
      - forked
      - git
      - git-bash
      - gohugo
      - golang
      - intellij
      - iusethis
      - joplin
      - longform
      - markdown
      - mathematics
      - mathjax
      - messaging
      - meta
      - n2s
      - nix-nux
      - privacy-security
      - qutebrowser
      - tech
      - tumblelog
      - twitter-list
      - unicode
      - utf-8
      - vim
      - vscode
      - webdev
      - windows
      - words
      - zeitgeist

    Note that the value of this listablePortals key is a slice.

 

  1. In the relevant Hugo layout file, I include this Go Template code:

    {{ $tags := .Params.tags }}
    {{ $portals :=  intersect site.Params.listablePortals $tags }}
    
    {{ range $portals }}
    <a href="/portal/{{- . -}}/">#{{- . -}}</a>&thinsp;
    {{ end }}

 

For this article, this intersection code produces this:

  #gohugo     #tech

 

More examples of results of this intersection code is in each tumblelogged item in the Elsewhere Links News section of What’s New at Infinite Ink.

 

See also

Endnotes


1. Many Infinite Ink articles, including this one, are evergreen and regularly updated.
2. This tags front-⁠matter key is one of Hugo’s default taxonomies. To learn about this, see gohugo.io/content-management/taxonomies/ and www.ii.com/hugo-tutorial/#_taxonomies.
3. An Infinite Ink secret tag, for example yaml, is one that has not been turned into a portal. Most secret tags will eventually be portalized.⁠🤞

Comments and questions 📝 🤔 👎 👍

Your public comment or question might immediately improve this page or help me to (eventually) improve this page.