Skip to content

Instantly share code, notes, and snippets.

@tomvon
Last active February 21, 2021 03:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomvon/9470b67f3b3f1df53651 to your computer and use it in GitHub Desktop.
Save tomvon/9470b67f3b3f1df53651 to your computer and use it in GitHub Desktop.
Create a default post for a Jekyll instance using Python, save it and open it in BBEdit.
import os
from datetime import datetime
import time
import slugify
#Generate timestamps for post id and date.
ts = time.time()
timeid = datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timestamp = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
title = raw_input("What's the title of this post? ")
#Generate the post id based on Jekyll's requirements.
postid = timeid+'-'+slugify.slugify(title)+'.md'
#Generate post meta. I've included custom image and caption tags.
contents = """---
layout: post
title: """+title+"""
date: """+timestamp+"""
categories: uncategorized
tags:
- random
image: /img/image.jpg
caption: This is a picture
---
"""
app_path = '/path/to/your/app/_posts/'
post = app_path+postid
#Create the post.
file = open(post,'w')
file.write(contents)
file.close()
#Change 'bbedit' to your text editor of choice.
os.system('bbedit '+post)
print 'file added.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment