GithubHelp home page GithubHelp logo

nelsontky / gh-pages-url-shortener Goto Github PK

View Code? Open in Web Editor NEW
1.3K 12.0 481.0 85 KB

Minimal URL shortener that can be entirely hosted on GitHub pages.

Home Page: https://nlsn.cf/1

License: GNU General Public License v3.0

HTML 100.00%
url-shortener tinyurl bitly urlshortener shorten-urls self-hosted url-shorteners github-page shorturl short-url

gh-pages-url-shortener's Introduction

License: GPL v3 Total Lines GitHub stars

๐Ÿ”— 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!

Yay! We got to the top of HN!

Top of HN

And on GitHub trending!

GitHub Trending

๐Ÿ‘จโ€๐Ÿซ Demo

  1. nlsn.cf/1 should link to this repo.

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

  3. The newly created short url can be accessed via nlsn.cf/{issue_number}

โ˜•๏ธ Features

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

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

๐Ÿ’ก How does this work?

Thanks to @kidGodzilla for the pretty neat explanation here.

  1. 404.html handles all requests
  2. Small javascript snippet fetches a JSON representation of the GitHub issue via the JSON API, and redirects to the issue title, as a URL.
  3. 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!

  1. Fork the repo before cloning your fork.
  2. Set up GitHub pages for your forked repo.
    1. In your forked repo, click the Settings tab and scroll down to the GitHub Pages section.
    2. Then select the main branch source and click on the Save button.
    3. How to create GitHub page
  3. If you are using your own domain:
    1. Set your domain up for GitHub pages.
    2. Change the URL in CNAME file to your domain.
  4. If you are using GitHub page's default domain i.e. Something like https://<username>.github.io/<repo-name>/
    1. Delete the CNAME file.
    2. Change var PATH_SEGMENTS_TO_SKIP = 0; at the top of 404.html to var PATH_SEGMENTS_TO_SKIP = 1;.
      1. This is as GitHub domains have an additional path segment (the repo name) after the host name.
  5. Create a new repo as a database. (Or you could use your forked repo)
    1. Update var GITHUB_ISSUES_LINK = "<your-github-issues-link>"; at the top of 404.html accordingly afterwards.
      1. Format for GITHUB_ISSUES_LINK: https://api.github.com/repos/{owner}/{repo}/issues/
      2. Remember the trailing /!
  6. 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!

  • eexit.github.io/s - Created a bash script that allows for shortening of URLs straight on the command line! Check out his script here.
  • gh-short-url - A npm command line tool that uses GitHub pages to convert short URLs.

gh-pages-url-shortener's People

Contributors

eexit avatar fredster33 avatar mayandev avatar nelsontky avatar olekenneth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gh-pages-url-shortener's Issues

You can write a bot to create PRs from the issues and update a json file in the repo

Currently you are sending a request to Github API to read repos and do the redirecting. I assume you don't do caching, (maybe github does), so you add latency to every request and consume your github api rate limit.

Instead, you can write a github bot that takes issues in the other repo and opens a PR to this repo where it submits redirections to a json file. This workflow is automated as well and will fixes all the problems above. The only problem is the delay between adding the issue and it being submitted to repo and the initial bot development time.

  • I know this project is experimenting only and there is no need for what I explained above, It's actually very smart the way it is, but just wanted to put it here.

Thought exercise: Make a dating site

Per your experience, is it feasible to make a simple serverless dating site+app which uses Issues for hosting? It could encode each user's profile as an issue, and the pictures as encoded comments to the issue. Categories and classifications can be made using Labels. Age and height search can perhaps be implemented using Milestones or any other means of range matching, although I'm not sure. Sent and received messages can be hosted as comments to the issue as well. I'm sure there will be more ideas as it's implemented.

This is a bit trickier because users of the site would expect to be able to remove or edit their profile, without anyone else except the admin being able to do the same. The same user-level security restriction also applies for reading and deleting one's messages.

Up to ten new prospective matches can be given to each active user daily using a matching job which runs nightly using Actions.

Shorten from your CLI

Hey,

I created a small bash script to automate this, based on GitHub CLI:

#!/bin/bash
[[ ! -z "$@" ]] && (gh issue create --repo eexit/s --label "cli" --title "$@" --body "" | sed -e 's/github.com\/eexit\/s\/issues/eexit.github.io\/s/g') || (echo "Forgot URL?"; exit 1)

Screenshot 2020-11-17 at 11 18 35 PM

Note: my repo is https://github.com/eexit/s

How?

How did you use a package.json, github.io dosen't have support for that right?

https://html5zombo.com/

Welcome ... to ZomboCom.

This ... is ... ZomboCom. Welcome. This is ZomboCom; welcome ... to ZomboCom. You can do anything at ZomboCom. Anything at all. The only limit is yourself. Welcome ... to ZomboCom.

Welcome ... to ZomboCom. This is ... ZomboCom. Welcome ... to ZomboCom! This is ZomboCom, welcome! Yes ... This ... is ZomboCom.

This is ZomboCom! And welcome to you, who have come to ZomboCom. Anything ... is possible ... at ZomboCom. You can do ... anything at ZomboCom. The infinite is possible at ZomboCom. The unattainable is unknown at ZomboCom. Welcome to ZomboCom. This ... is ZomboCom.

Welcome to ZomboCom. Welcome. This ... is ... ZomboCom. Welcome ... to ZomboCom!

Welcome ... to ZomboCom.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.