brandur.org

Follow up from yesterday’s note on atom reslugging: Short, friendly base32 slugs from timestamps, discussing how unique slugs are generated for each atom on this page.

A published timestamp is changed to bytes then encoded to base32 similar to RFC 4648, except with digits leading so that output slugs sort in the same order as the input timestamps. Implemented in ~4 lines of Go:

var lexicographicBase32 = "234567abcdefghijklmnopqrstuvwxyz"

var lexicographicBase32Encoding = base32.
    NewEncoding(lexicographicBase32).
    WithPadding(base32.NoPadding)

func atomSlug(publishedAt time.Time) string {
    i := big.NewInt(publishedAt.Unix())
    return lexicographicBase32Encoding.EncodeToString(i.Bytes())
}