Skip to content

Instantly share code, notes, and snippets.

@higby
Created May 19, 2021
Embed
What would you like to do?
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