Last active
February 21, 2021 03:15
-
-
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.
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
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