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:
parent
57ec85ae45
commit
4b09f98468
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
node_modules/
|
|
30
README.md
30
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/)).
|
[](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
|
||||||
|
5
_headers
5
_headers
@ -1,5 +0,0 @@
|
|||||||
/*
|
|
||||||
X-Robots-Tag: noindex
|
|
||||||
Content-Security-Policy: default-src 'none';
|
|
||||||
Referrer-Policy: no-referrer
|
|
||||||
x-got-milk: 2%
|
|
8
netlify.toml
Normal file
8
netlify.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[build]
|
||||||
|
publish = "src"
|
||||||
|
|
||||||
|
[[headers]]
|
||||||
|
for = "/*"
|
||||||
|
[headers.values]
|
||||||
|
X-Robots-Tag = "noindex, nofollow"
|
||||||
|
Referrer-Policy = "no-referrer"
|
25
package.json
25
package.json
@ -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": "*"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
User-Agent: *
|
|
||||||
Disallow: /
|
|
28
short.sh
Executable file
28
short.sh
Executable 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"
|
Loading…
x
Reference in New Issue
Block a user