« YAML’s Folded Block Scalars
  
∞♾️ »

Hugo’s data Directory (featuring Nitter instances)
Updated  2022-August-14

Page contents

News

2022-August-5  Published this evolving⁠[1] article.

 

Hugo’s default directory structure

When you create a Hugo project with this command:

hugo new site --format=extension directory-name

This directory structure is created:

.
└── directory-name/
    ├── archetypes/
    ├── content/
    ├── data/
    ├── layouts/
    ├── public/
    ├── static/
    ├── themes/
    └── config.extension

 

💡
  • You can think of the config.extension file as Hugo’s default data file.

  • Possible values of extension are json, toml, yaml or yml.

 

About the data directory

If you want to access the contents of a non-⁠config JSON, TOML, YAML or XML file in your Hugo layout files (including in your shortcodes), you can put the file in your project’s data directory. For example:

.
└── directory-name/
    ├── archetypes/
    ├── content/
    ├── data/
    │   └── nitter.yaml     ⟵👀
    ├── layouts/
    ├── public/
    ├── static/
    ├── themes/
    └── config.yaml

 

To learn about this nitter.yaml file, see the next section.

To learn about the data directory, see…

 

Example

In July 2022, I started including Nitter links on some Infinite Ink portals. Nitter is a Twitter front-⁠end focused on privacy, which you can learn about at…

Because Nitter instances are often overloaded, I use Hugo’s shuffle function to select a random Nitter instance for each timeline that I link to. Below are the steps I used to set this up.

 

1. Create data/nitter.yaml

First, I created the following YAML⁠[2] file that lists Nitter instances.

data/nitter.yaml
instances:
 - nitter.net
 - nitter.42l.fr
 - nitter.pussthecat.org
 - nitter.kavin.rocks
 - nitter.unixfox.eu
 - nitter.namazso.eu
 - nitter.hu
 - nitter.moomoo.me
 - nitter.it
 - twitter.censors.us
 - nitter.grimneko.de
 - nitter.ca
 - nitter.fly.dev
 - notabird.site
 - nitter.weiler.rocks
 - nitter.sethforprivacy.com
 - nttr.stream
 - nitter.cutelab.space
 - nitter.nl
 - nitter.mint.lgbt
 - nitter.bus-hit.me
 - nitter.esmailelbob.xyz
 - tw.artemislena.eu
 - de.nttr.stream
 - nitter.winscloud.net
 - nitter.tiekoetter.com
 - nitter.spaceint.fr
 - twtr.bch.bar
 - nitter.privacy.com.de
 - nitter.mastodon.pro
 - nitter.notraxx.ch
 - nitter.poast.org
 - nitter.bird.froth.zone
 - nitter.dcs0.hu
 - twitter.dr460nf1r3.org
 - nitter.garudalinux.org
 - twitter.beparanoid.de
 - n.ramle.be
 - nitter.cz
 - nitter.privacydev.net
 - tweet.lambda.dance
 - nitter.ebnar.xyz
 - nitter.kylrth.com
 - nitter.foss.wtf
 - nitter.priv.pw
 - nt.vern.cc
 - nitter.wef.lol
 - nitter.tokhmi.xyz
 - nitter.catalyst.sx
 - unofficialbird.com
 - nitter.projectsegfau.lt
 - singapore.unofficialbird.com
 - nitter.fprivacy.com
 - canada.unofficialbird.com
 - india.unofficialbird.com
 - nederland.unofficialbird.com
 - uk.unofficialbird.com
 - n.l5.ca
 - nitter.slipfox.xyz
 - nitter.soopy.moe
 - nitter.qwik.space

 

2. Create get-nitter-instance shortcode

Next, I created something like the following Hugo shortcode.

To view @nm's <i>gohugo</i> Twitter list on a random
<a href="https://github.com/zedeus/nitter/wiki/Instances">Nitter instance</a>,
go to
{{ range site.Data.nitter.instances | shuffle | first 1 -}}
 <a href="https://{{ . }}/nm/lists/gohugo">
  {{- . -}}/nm/lists/gohugo
 </a>.
{{ end }}

 

Note that the emphasized line uses Hugo’s contextless global site function[3] to access site.Data.nitter.instances.

 

3. Results of get-nitter-instance shortcode

Here is a result of this get-⁠nitter-⁠instance shortcode:

To view @nm's gohugo Twitter list on a random Nitter instance, go to nitter.42l.fr/nm/lists/gohugo .

Note that each time Hugo builds this website, the Nitter instance (nitter.42l.fr in this case)  changes.

 

See also

Endnotes


1. Many Infinite Ink articles, including this one, are evergreen and regularly updated.
3. You can tell that the Hugo site function is contextless by noticing that it does not have a leading dot (.). To learn about this global function, see the Hugo v0.53 release notes, especially the relevant GitHub commit and GitHub issues.

Comments and questions 📝 🤔 👎 👍

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