simple-url-shortener
v1.0.5
Published
A simple URL shortener without magic.
Downloads
9
Readme
Simple URL Shortener
simple-url-shortener is a simple tool that build shorten urls for GitHub page without magic.
Here are steps:
- Create shorten url mapping urls.json:
{
"home": "https://liaoxuefeng.com",
"BTC": "https://bitcoin.org"
}
The case-sensitive key is composed by 1 ~ 6 characters of a ~ z, A ~ Z and 0 ~ 9.
Create GitHub action build.yml (just copy the content and change the branch name if neccessary).
Set GitHub pages:
- Settings - Pages - Build and deployment - Source: GitHub Actions;
- Custom domain: set your custom domain and enable "Enforce HTTPS".
You can then access shorten URL like https://redirect.liaoxuefeng.com/BTC after build.
You can find the example repo.
Shorten URL
The urls.json
contains key - url mapping. simple-url-shortener will generate HTML files for each shorten URL. The generated GitHub pages structure:
_site/
├── 404.html
├── index.html
├── BTC
│ └── index.html
└── home
└── index.html
The HTML file uses <meta http-equiv="refresh" content="0;URL=xxx"/>
for redirect:
$ curl https://redirect.liaoxuefeng.com/BTC/index.html
<html>
<head>
<meta http-equiv="refresh" content="0;URL='https://bitcoin.org/'" />
...
Configuration
You can also set a config.json for configuration:
{
"wait": 0, // auto redirect in seconds, 0 = immediately, n = display link and wait for n seconds, -1 = display link only.
"generate404": true, // generate a 404 page, default to true.
"generateIndex": true // generate an index page, default to true.
}
Customize
If you want to use your own designed template to generate pages, copy the following template files to your repo's root dir and make some change: