I’m currently available for hire.
You can read more about it here, head directly to my résumé, or email me.

Nik Kantar

Thursday, October 15, 2020

Introducing sus

I made a URL shortener with a static site generator.

Before we begin, it’s pronounced “suss”. There’s a whole section about it in the documentation.


URL shorteners can be pretty useful. Static site generators are awesome. Why not combine the two?

That isn’t what inspired sus, but doesn’t it read well?

What did inspire my newest project was—of all things—Instagram…sorta. Ugh, I know!

Instagram doesn’t really allow tappable links in a whole lot of places. It especially doesn’t let users link Stories unless they have a business account. I don’t, so two years ago I bought nik.pub to use for a URL shortener of my own. The “pub” part is meant to stand for “public”, but I’m not sure that comes across.

Anyway, I first made Publinker and used it for a while. Please don’t look at the project—it’s neither good nor complete. But it did the trick! The whole time I wanted something simpler, but couldn’t be bothered to change anything.

Recently I ran into di’s corvid project and switched to it for this very site just about immediately. It was nice to finally get off the thoroughly outdated Flask-based horror it was before, and I was exceedingly pleased with myself for being back on a static site. Shortly thereafter I made an http redirect page for another site and it hit me that an entire URL shortener could be build based on that. A flurry of commits later, here we are.

See, an http redirect is just this:

<meta
  http-equiv="refresh"
  content="0;url=http://some.example.com"
/>

On a static site, going to http://example.com/foo will load http://example.com/foo/index.html, and if that index.html has an http redirect, it’ll work like a charm! So that’s exactly what sus outputs.

In essence, you feed it an input file that looks something like this:

foo|http://some.example.com
bar|http://another.example.com

and it spits out an output/ directory that looks something like this:

output/
├── bar/
│   └── index.html
└── foo/
    └── index.html

with output/foo/index.html that look something like this:

<meta
  http-equiv="refresh"
  content="0;url=http://some.example.com"
/>

and output/bar/index.html that looks something like this:

<meta
  http-equiv="refresh"
  content="0;url=http://another.example.com"
/>

which means that going to http://example.com/foo will redirect the user to http://some.example.com" and going to http://example.com/bar will redirect the user to http://another.example.com".

Bonus: if you feed sus a home.html file, it’ll copy it to output/index.html, giving you a homepage. Brilliant, if I may say so myself!

There’s an example site at sus-example.nkantar.com and the source is on is on GitHub.

Happy redirecting!

P.S.: This project contains what may very well be my most pretentious commit ever. No, I’m not sorry.