Created
February 12, 2015 10:09
-
-
Save tomalrussell/0828db8491b99db032fe to your computer and use it in GitHub Desktop.
Jekyll New Post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import sys | |
import datetime | |
import os | |
# set title to command-line argument, or default | |
if (len(sys.argv) > 1): | |
title = sys.argv[1] | |
else: | |
title = "New Post" | |
# use the rest of the arguments for categories | |
categories = " ".join(sys.argv[2:]) | |
# standard filename format: date and title | |
filename = datetime.datetime.now().strftime('%Y-%m-%d-') + title.lower().replace(" ","-") + '.md' | |
# standard front matter: title, full date, categories | |
front_matter = '''\ | |
--- | |
layout: post | |
title: %s | |
date: %s | |
categories: %s | |
--- | |
''' % (title, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), categories) | |
# if we're in a jekyll root, pop it in ./_posts | |
if(os.path.exists(os.getcwd() + '/_posts')): | |
filepath = os.getcwd() + '/_posts/' + filename | |
else: | |
filepath = os.getcwd() + '/' + filename | |
# check if this post exists already, otherwise create and write! | |
if(os.path.exists(filepath)): | |
print ("Looks like this post already exists: " + filepath) | |
else: | |
with open(filepath,'w') as f: | |
print( front_matter, file=f) | |
print ("Post created! " + filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, Tom,
I've encountered a time zone problem. Jekyll told me one of the new post "Skipping: _posts/2020-09-26-test-time-zone.md has a future date"
There's two way to solve this problem
Add time zone to line 27:
Or just add below to
_config.yml
, Jekyll will reading future posts.