diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c2658d7..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 43c97e7..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -package-lock=false diff --git a/README.md b/README.md index 189e35a..ae76c47 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,34 @@ -# [jrvs.io](https://jrvs.io/) 🔗 +# 🔗 [jrvs.io](https://jrvs.io/) -Personal link shortener powered by [@kentcdodds](https://kentcdodds.com/)'s clever [`netlify-shortener`](https://github.com/kentcdodds/netlify-shortener) (but deployed on [Cloudflare Pages](https://pages.cloudflare.com/)). +[![Netlify Status](https://api.netlify.com/api/v1/badges/6c1d7761-137b-40e8-b93a-1f6b06430e38/deploy-status)](https://app.netlify.com/sites/jrvs/deploys) + +Personal link shortener powered by Netlify and a caveman-esque shell script. ## Usage -### View existing shortcodes: - -[See `_redirects`.](_redirects) - -### Create a new shortcode: +### Create a new shortlink ```bash -npm run shorten https://github.com/jakejarvis gh +./short.sh https://github.com/jakejarvis git ``` -or: +🪄 [https://jrvs.io/git](https://jrvs.io/git) now points to [https://github.com/jakejarvis](https://github.com/jakejarvis)! + +#### Shell function + +Adding this function to `.bashrc`, `.zshrc`, etc. lets us run `short` from anywhere. ```bash -npm link # run once to set up -shorten https://github.com/jakejarvis gh +short() { + # parentheses let us cd to this directory without changing our current working directory + ( cd && bash -c "./short.sh $*" ) +} ``` +### View existing shortlinks + +See [`src/_redirects`](src/_redirects). + ## License MIT diff --git a/_headers b/_headers deleted file mode 100644 index 689df1b..0000000 --- a/_headers +++ /dev/null @@ -1,5 +0,0 @@ -/* - X-Robots-Tag: noindex - Content-Security-Policy: default-src 'none'; - Referrer-Policy: no-referrer - x-got-milk: 2% diff --git a/cli.js b/cli.js deleted file mode 100755 index 4c585cd..0000000 --- a/cli.js +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -require('netlify-shortener') diff --git a/favicon.ico b/favicon.ico deleted file mode 100644 index e69de29..0000000 diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 0000000..c254e20 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,8 @@ +[build] + publish = "src" + +[[headers]] + for = "/*" + [headers.values] + X-Robots-Tag = "noindex, nofollow" + Referrer-Policy = "no-referrer" diff --git a/package.json b/package.json deleted file mode 100644 index 65ea3f6..0000000 --- a/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "jrvs.io", - "version": "1.0.0", - "author": "Jake Jarvis ", - "description": "@jakejarvis's link shortener", - "homepage": "https://jrvs.io", - "private": true, - "license": "MIT", - "main": "cli.js", - "repository": { - "type": "git", - "url": "git+https://github.com/jakejarvis/jrvs.io.git" - }, - "bin": { - "shorten": "cli.js" - }, - "scripts": { - "shorten": "netlify-shortener", - "build": "mkdir dist && cp _headers _redirects robots.txt favicon.ico dist" - }, - "dependencies": {}, - "devDependencies": { - "netlify-shortener": "*" - } -} diff --git a/robots.txt b/robots.txt deleted file mode 100644 index c6742d8..0000000 --- a/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-Agent: * -Disallow: / diff --git a/short.sh b/short.sh new file mode 100755 index 0000000..c900603 --- /dev/null +++ b/short.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +# usage: `./short.sh https://github.com/jakejarvis git` +# inspired by https://github.com/caarlos0-graveyard/netlify-shortener-sh/blob/master/short.sh + +# make sure the first param is the URL since I may or may not consistently mix them up +url="$1" +if [[ ! "$url" =~ ^https?:// ]]; then + echo "First parameter must be a valid URL, dummy." + exit 1 +fi + +# generate a random 5-character path if unspecified +code="$2" +[[ -n "$code" ]] || code="$(openssl rand -hex 5 | head -c 5)" + +# prepend new shortlink to the _redirects file +printf "/%s %s\n%s\n" "$code" "$url" "$(cat src/_redirects)" > src/_redirects + +# netlify will take it from here... +git add src/_redirects +git commit -m "/$code -> $url" +git push -u origin main + +echo "" +echo "👍 https://jrvs.io/$code -> $url" diff --git a/_redirects b/src/_redirects similarity index 100% rename from _redirects rename to src/_redirects