Skip to content

Instantly share code, notes, and snippets.

@anapaulagomes
Created May 31, 2018 07:41
Show Gist options
  • Save anapaulagomes/6d5c6eb679dabb9243f596ca7e7a5f6e to your computer and use it in GitHub Desktop.
Save anapaulagomes/6d5c6eb679dabb9243f596ca7e7a5f6e to your computer and use it in GitHub Desktop.
Friendly command to create new posts on Hugo
"""
Hugo new post
> python newpost.py --title="Regex pra quem não sabe Regex" --lang=pt-br --editor=atom
Same of:
hugo new regex-pra-quem-não-sabe-regex.pt-br.md --editor=atom
"""
import argparse
import subprocess
parser = argparse.ArgumentParser(description='Create new post on Hugo')
parser.add_argument('--title', required=True, help='post title')
parser.add_argument('--lang', default='pt-br', help='post language')
parser.add_argument('--editor', default='macdown', help='where would you like to edit it?')
args = parser.parse_args()
title = args.title.lower().replace(' ', '-')
language = args.lang
editor = args.editor
command = f'hugo new {title}.{language}.md --editor={editor}'.split(' ')
print(' '.join(command))
output = subprocess.run(command, stdout=subprocess.PIPE)
print(output.stdout.decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment