Skip to content

Instantly share code, notes, and snippets.

@higby
Created May 19, 2021 20:01
Show Gist options
  • Save higby/1c5c226bd6ad5311fd13166fdbeee1eb to your computer and use it in GitHub Desktop.
Save higby/1c5c226bd6ad5311fd13166fdbeee1eb to your computer and use it in GitHub Desktop.
Automate new Short Links
// Menu: New Short Link
// Modified version of https://github.com/dealingwith's 'new-post.js'
let worked = "Short link added"
let link = await arg('Link to?')
let slug = await arg('Slug?')
let file_slug = slug.toLowerCase().replaceAll(' ', '-')
let redirect_path = '(( path to redirects folder))'
let file_path = redirect_path + file_slug + '.md'
let file_contents = `---
redirect_to: ${link}
---
`
await writeFile(file_path, file_contents)
terminal('cd ((path to repository folder));git add .;git commit -m "New short URL";git push origin main --force')
copy('((short-url url))'+slug)
notify('Short URL created @ ((short-url url))'+slug+'!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment