Skip to content

liqwang/link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

link

Use Git commit message to store the short URL on GitHub, host the redirector on GitHub Pages

This interesting tool is from the article: https://www.v2ex.com/t/1105845

How it works?

branch description
page 404.html redirector
url store URLs

The GitHub API currently(2025.2.1) allows the request to specify the Git commit in two simpler ways than the full SHA-1 hash 9fc3741bbf92219dd53278f447e124d2d3fdf5df:

It's impossible to redirect the short URL using index.html on GitHub Pages, because it only serves the root path /, other requests will respond 404.html

---
config:
  theme: neutral
  mirrorActors: false
---
sequenceDiagram
    %% autonumber
    Broswer ->>+ liqwang.github.io: GET /9fc3
    liqwang.github.io ->>- Broswer: 404.html
    Broswer ->>+ api.github.com: GET /commits/9fc3
    api.github.com ->>- Broswer: target URL
    Broswer ->> target website: redirect

Loading

TODO

  • Use IndexedDB or localStorage to cache the target URL in the client browser, which can reduce the invocations of GitHub API

About

Short URL stored in GitHub commit

Topics

Resources

License

Stars

Watchers

Forks

Languages