Crosslinks by Title in Hugo

Another quick Hugo post. One thing I miss about my previous blogging platform(s) was the ability to generate quick links between posts just by using the title of the post. So rather than this:

a cool post
This is [a cool post]({{< ref "2021-07-15-crosslinks-by-title-in-hugo" >}}), go read it.

You could do this:

This is {{< crosslink title="Crosslinks by Title in Hugo" text="a cool post" >}}.

Or shorter: {{< crosslink "Crosslinks by Title in Hugo" >}}.

And it should just work.

read more...


Generating a Book Bingo Chart in Hugo

Another r/Fantasy 2021 Book Bingo post! How in the world am I generating this (updating) chart in Hugo?

2021 Book Bingo

SFF anthology or collection

Attack on Titan, Vol. 1

Set in Asia (Hard: by an Asian author)

r/Fantasy A to Z Genre Guide (Hard: by a BIPOC author)

Found Family (Hard: featuring an LGBTQ+ character)

First person POV (Hard: Multiple)

r/Fantasy Book Club (Hard: with participation)

New to you author (Hard: haven’t heard much about)

Gothic Fantasy (Hard: not in the Book Riot article)

Mexican Gothic

(Hard Mode)

Backlist book (Hard: published before 2000)

Revenge-seeking character (Hard: revenge as the major book plot)

Mystery plot (Hard: not primary world urban fantasy)

Six Wakes

(Hard Mode)

Comfort read (Hard: that isn’t a reread)

Wild Sign

(Hard Mode)

Debut novel (Hard: published in 2021)

Tales of Nezura: Book 1: The Zevolra

(Hard Mode)

Cat squasher (500+ pages; Hard: 800+ pages)

SFF-related nonfiction (Hard: published in the last 5 years)

Latinx or Latin American author (Hard: with fewer than 1000 Goodreads ratings)

Self published (Hard: with fewer than 50 Goodreads ratings)

Tales of Nezura: Book 1: The Zevolra

(Hard Mode)

Forest setting (Hard: for the entire book)

Annihilation

(Hard Mode)

Genre mashup (Hard: of three or more genres)

Gideon the Ninth

(Hard Mode)

Has chapter titles of more than one word (Hard: for every chapter)

The Midnight Library

(Hard Mode)

___ of ___ (Hard: and ___)

First contact (Hard: that doesn’t lead to war)

Project Hail Mary

(Hard Mode)

Trans or Nonbinary (Hard: protagonist)

Debut author (Hard: with an AMA)

Witches (Hard: as the main protagonist)

A Great and Terrible Beauty

(Hard Mode)

read more...


A Tabbed View for Hugo

One thing I’ve been using for a lot of my recent posts (such as Backtracking Worms) is a tabbed view of code that can show arbitrarily tabs full of code or other content and render them wonderfully! For example, we can turn: {{< tabs >}} {{< sourcetab ruby "examples/art-station.rune" >}} {{< tab "art-station.svg" >}} {{< include "output/art-station.svg" >}} {{< /tab >}} {{< sourcetab ruby "examples/astrology-and-moons.rune" >}} {{< tab "astrology-and-moons.svg" >}} {{< include "output/astrology-and-moons.

read more...


Prevent JavaScript links by parsing URLs

If you have a website that allows users to submit URLs, one of the (many many) things people will try to do to break your site is to submit URLs that use the javascript: protocol (rather than the more expected http: or https:). This is almost never something that you want, since it allows users to submit essentially arbitrary code that other users will run on click in the context of your domain (same origin policy).

So how do you fix it?

First thought would be to try to check the protocol:

> safe_url = (url) => !url.match(/^javascript:/)
[Function: safe_url]

> safe_url('http://www.example.com')
true

> safe_url('javascript:alert(1)')
false

read more...