π GitHub Pages URL Shortener
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!
π¨πΏβπ« Demo
-
u.iwill.im/1 should link to this repo, and u.iwill.im/2 should link to an awesome Calculator.
-
To add a new short link, add an issue with the body or title being the full URL you want to shorten to iwill/url-db.
-
The newly created short URL can be accessed via
u.iwill.im/{issue_number}
βοΈ Features
-
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:
u.iwill.im/1
instead of looking like this:u.iwill.im/#1
.
π‘ How does this work?
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 body or title, as a URL.
- Profit?
π This is so cool! How can I use this with my own domain?!
Disclaimer: This method of creating a URL shortener is hacky and not meant to be reliable. Do proceed at your own risk!
- Fork the repo before cloning your fork.
- Set up GitHub pages for your forked repo.
- If you are using your own domain:
- Set your domain up for GitHub pages.
- Change the URL in
CNAME
file to your domain.
- If you are using GitHub page's default domain i.e. Something like
https://<username>.github.io/<repo-name>/
- Delete the
CNAME
file. - Change
var PATH_SEGMENTS_TO_SKIP = 0;
at the top of404.html
tovar PATH_SEGMENTS_TO_SKIP = 1;
.- This is as GitHub domains have an additional path segment (the repo name) after the host name.
- Delete the
- Create a new repo as a database. (Or you could use your forked repo)
- Update
var GITHUB_ISSUES_LINK = "<your-github-issues-link>";
at the top of404.html
accordingly afterwards.- Format for
GITHUB_ISSUES_LINK
:https://api.github.com/repos/{owner}/{repo}/issues/
- Remember the trailing
/
!
- Format for
- Update
- Push your changes to your forked repo, and your low cost and cool as heck URL shortener will be ready for use!
π΄ Featured forks
To feature your fork here, edit this section and open a PR!
- nlsn.cf - The repo which I forked from.
- u.iwill.im - This repo, which supports loooong URL by using issue body (or use title if body is not a valid URL, body/title accepts up to 65536/256 characters), e.g. u.iwill.im/2 shortened a super long URL.