This is a minimal URL shortener that can be entirely hosted on GitHub pages.
-
nlsn.cf/1 should link to this repo.
-
To add a new short link, add an issue with the title being the link you want to shorten (including the
http(s)://
) to https://github.com/nelsontky/gh-pages-url-shortener-db/issues. -
The newly created short url can be accessed via
nlsn.cf/{issue_number}
-
Unlike many URL shorteners, this
one does not need a databaseuses a "database" in the form of GitHub issues and can be entirely hosted on GitHub pages. -
There is no need for the pound symbol - short URLs look clean like this:
nlsn.cf/1
instead of looking like this:nlsn.cf/#1
.
Thanks to @kidGodzilla for the pretty neat explanation here.
- CNAME points URL to
gh-pages
branch- 404.html handles all requests
- Small javascript snippet fetches a JSON representation of the GitHub issue via the JSON API, and redirects to the issue title, as a URL.
- Profit?
Disclaimer: This method of creating a URL shortener is hacky and not meant to be reliable or used in production. Do proceed at your own risk!
-
Fork the repo before cloning your fork.
-
npm run install
- I know that for such a small project, the usage of
node
is a bit of an overkill. However,node
is only involved in the deployment process, namely transpiling the.js
files with babel and then using thegh-pages
module to push the build folder to thegh-pages
branch.
- I know that for such a small project, the usage of
-
If you are using your own domain:
- Set your domain up for GitHub pages.
- Change the URL in
src/CNAME
to your domain. - Change
const HOST = "nlsn.cf";
insrc/config.js
toconst HOST = "<your-domain>";
.
-
If you are using GitHub page's default domain i.e. Something like
https://<username>.github.io/<repo-name>/
- Remove the command
cp CNAME build/
from line 8 ofpackage.json
. - Change
const HOST = "nlsn.cf";
insrc/config.js
toconst HOST = "<username>.github.io"
. - Change
const PATH_SEGMENTS_TO_SKIP = 0;
insrc/config.js
toconst PATH_SEGMENTS_TO_SKIP = 1;
.- This is as GitHub domains have an additional path segment (the repo name) after the host name.
- Remove the command
-
Create a new repo as a database. (Or you could use your forked repo)
- Update
const GITHUB_ISSUES_LINK
insrc/config.js
accordingly afterwards.
- Update
-
npm run deploy
, and your low cost and cool as heck URL shortener will be ready for use!