1.0.5 • Published 11 months ago

simple-url-shortener v1.0.5

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
11 months ago

Simple URL Shortener

NPM Version

simple-url-shortener is a simple tool that build shorten urls for GitHub page without magic.

Here are steps:

  1. 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.

  1. Create GitHub action build.yml (just copy the content and change the branch name if neccessary).

  2. 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:

1.0.5

11 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago