1
mirror of https://github.com/jakejarvis/jrvs.io.git synced 2025-04-26 06:35:23 -04:00

convert to a dead simple bash script

This commit is contained in:
Jake Jarvis 2023-02-04 09:21:35 -05:00
parent 57ec85ae45
commit 4b09f98468
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
11 changed files with 55 additions and 47 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
node_modules/

1
.npmrc
View File

@ -1 +0,0 @@
package-lock=false

View File

@ -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 ## Usage
### View existing shortcodes: ### Create a new shortlink
[See `_redirects`.](_redirects)
### Create a new shortcode:
```bash ```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 ```bash
npm link # run once to set up short() {
shorten https://github.com/jakejarvis gh # parentheses let us cd to this directory without changing our current working directory
( cd <LOCAL_PATH_TO_THIS_REPO> && bash -c "./short.sh $*" )
}
``` ```
### View existing shortlinks
See [`src/_redirects`](src/_redirects).
## License ## License
MIT MIT

View File

@ -1,5 +0,0 @@
/*
X-Robots-Tag: noindex
Content-Security-Policy: default-src 'none';
Referrer-Policy: no-referrer
x-got-milk: 2%

2
cli.js
View File

@ -1,2 +0,0 @@
#!/usr/bin/env node
require('netlify-shortener')

View File

8
netlify.toml Normal file
View File

@ -0,0 +1,8 @@
[build]
publish = "src"
[[headers]]
for = "/*"
[headers.values]
X-Robots-Tag = "noindex, nofollow"
Referrer-Policy = "no-referrer"

View File

@ -1,25 +0,0 @@
{
"name": "jrvs.io",
"version": "1.0.0",
"author": "Jake Jarvis <jake@jarv.is>",
"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": "*"
}
}

View File

@ -1,2 +0,0 @@
User-Agent: *
Disallow: /

28
short.sh Executable file
View File

@ -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"