Minimal URL shortener that can be entirely hosted on GitHub pages.
This is a minimal URL shortener that can be entirely hosted on GitHub pages. It does not need the maintenance of any servers or databases and can be hosted entirely on GitHub for free!
And on GitHub trending!
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 database uses 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.
- 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. Do proceed at your own risk!
CNAME
file to your domain.https://<username>.github.io/<repo-name>/
CNAME
file.var PATH_SEGMENTS_TO_SKIP = 0;
at the top of 404.html
to
var PATH_SEGMENTS_TO_SKIP = 1;
.
var GITHUB_ISSUES_LINK = "<your-github-issues-link>";
at the top
of 404.html
accordingly afterwards.
GITHUB_ISSUES_LINK
:
https://api.github.com/repos/{owner}/{repo}/issues/
/
!To feature your fork here, edit this section and open a PR!