Use case
In my presentation slides, I would like to refer people to the site where they can find the slides, but avoid those very long URLs that nobody can remember. So, instead of:
https://github.com/pjastam/talks/subdirectory/with/a/very/long/name/for/these/nice/slides
I want to have something like this:
https://pst.am/nice-presentation
Inspired by Andrew Heiss1, Kent C. Dodds2 and Adrian Henry3, I managed to do so and will tell you how. In addition, since I was in the mood to make my workflow as short as possible, I went on to shorten the keystrokes in my local browser. There is a bonus section about this.
1 The shortened personal URL at this slide triggered me
2 GitHub repository for netlify-shortener
3 Blog on building your own link shortener with Netlify
Prerequisites
Step-by-step guide: URL shortener
Purchase a domain to use as your short link domain
Make up a very, very domain name (in my case, I imagined
pst.am
would be nice)Set up a new site at
Netlify Buy your domain name from
Netlify during this set up Alternatively, buy your domain name from another registrar, which is what I did
I went to iwantmyname.com and registered the domain name
At
Netlify, after the new site has been set up, find out how the name servers are called At iwantmyname.com, delegate the DNS of yor domain name to
Netlify
Create a private git repository called
url-shortener
at GitHubCreate a
_redirects
file and add some initial configuration lines to map short links to full URLsEnable automatic TLS certificates with Let’s Encrypt for your short domain name at
Netlify Wait until the domain name is served by
Netlify’s DNS - This may take up to 24 hours, depending on your registrar processing the change in nameservers
The first line of code in the
_redirects
file is a helper function for easily editing the_redirects
file in your GitHub repository online- Open your browser
- Type
pst.am/edit
- Commit your changes
The second line of code in the
_redirects
file links to a default page, in this case the homepage of my website, if you type the short domain name without extension- Open your browser
- Type
pst.am
- Hit the enter key
To add new redirects, start editing the
_redirects
file and add a line of code starting with a\
followed bya short word or abbreviation
, then at least one space, and finally theURL
to which the short word or abbreviation should redirect.
Step-by-step guide: Keystrokes-shortener
Open your Brave/Chrome browser
Navigate to: Settings -> Search Engine -> Manage Search Engines and Safe Search -> Site Search -> Click the
Add
buttonFill out
pst.am
as the search engine,:x
as the shortcut and the URLhttps://pst.am/%s
Click the
Add
buttonNote that in this guide I use
:x
as a shortcut, you can use this too or replace it by another shortcut if you likeYou can now edit the
_redirects
file in your GitHub repository online as follows- Open your browser
- Type
:x
- Press space bar or tab key
- Type
edit
- Hit return key
Or, if you want to go to my homepage
- Open your browser
- Type
:x
- Hit return key
A next step?
I occasionally use my workflow to shorten a URL for a new presentation. Setting up new presentation slides does not happen every day in my case, so editing the _redirects file online at GitHub every now and then is no bother.
But you may like to automate this part of the workflow if you need to shorten URLs on a more frequent basis, for example in case of creating your daily posts. Kent C. Dodds shows you how in his video at YouTube. The downside of this is that those links will be rather cryptic. Like the ones you get if you use the bit.ly shortened URLs, for example. This makes the shortened URL difficult to remember.
Citation
@online{stam2022,
author = {Stam, Piet},
title = {Shortening My {URL} Shortener},
date = {2022-09-04},
url = {https://www.pietstam.nl/posts/2022-09-04-url-shortener},
langid = {en}
}