Skip to content

A basic URL shortener using Github Pages, a catch-all 404 page, plain JS and a JSON file.

License

Notifications You must be signed in to change notification settings

ricksouth/ntms.link

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A basic URL shortener.

It gets the URLS to shorten from a JSON file:
 https://github.com/ricksouth/ntms.link/blob/main/urls/shortened_urls.json

{
	"github" : "https://github.com/ricksouth",
	"curseforge" : "https://curseforge.com/members/serilum/projects",
	"modrinth" : "https://modrinth.com/user/serilum"
}

 
Which a basic JavaScript turns into a new URL: (via a catch-all 404 page)
 https://github.com/ricksouth/ntms.link/blob/main/assets/js/script.js

document.addEventListener('DOMContentLoaded', function() {
	var url = document.URL + "";
	url = url.replaceAll("?p=/", "");

	loadJSON('/urls/shortened_urls.json',
		function(data) {
			var from = url.split("link/")[1]

			if (from in data) {
				var to = data[from];

				window.location.replace(to);
				return;
			}

			window.location.replace("https://github.com/ricksouth/ntms.link");
		},
		function(xhr) { }
	);
}, false);

 
These URLS are now shortened via Github Pages:

Anything else will link back to this repository:

That's it! 🤷

About

A basic URL shortener using Github Pages, a catch-all 404 page, plain JS and a JSON file.

Resources

License

Stars

Watchers

Forks