Mike Slinn
Mike Slinn

Bash Script to Create a New Jekyll Post

Published 2020-08-16.

This article is categorized under Jekyll, Open Source, Scripting

I use Jekyll to build this website. Some material is published as articles, some as blog posts. I wrote a script called newPost that creates a new draft blog post with SEO considerations. SEO rankings are improved when the description and title tag are neither too long nor too short.

Sample Usage

Here is an example of how I used it on 2020-08-16:

$ _bin/newPost
Post Title (30-60 characters):
______________________________123456789012345678901234567890
This is a test of newPost for the greater good
46 characters, excellent!

Post Description (30-60 characters):
____________________________________________________________123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
I wish newPost used some sort of web service to generate an SEO-optimized description
85 characters, excellent!

Post Categories (comma delimited):
Post Tags (comma delimited):
Post Keywords (comma delimited): Goofiness, Silliness
Banner image (bg_ .jpg):

For the above example the generated file is called _drafts/2020-08-16-this-is-a-test-of-newpost-for-the-greater-good.html. When you are happy with the new posting, move it from _drafts to _posts like this:

$ mv _drafts/2020-08-16-new-jekyll-post.html _posts/

Generated Posting

Here is the generated file:

---
categories: []
description: I wish newPost used some sort of web service to generate an SEO-optimized description
image:
keywords: [Goofiness, Silliness]
last_modified_at: 2020-08-16
layout: blog
title: This is a test of newPost for the greater good
tags: []
---

Error Handling

The script checks the length of the title and the posting description for SEO purposes. If either of these are too long or too short, the script allows the user to edit their input over and over until they get it right. For example, here you can see that at first the user just types in xx for the title, then they provide a string that is too long, then they edit it until it has an acceptable length:

$ _bin/newPost
Post Title (30-60 characters):
______________________________123456789012345678901234567890
xx
28 characters too short, please edit
Post Title (30-60 characters):
______________________________123456789012345678901234567890
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
14 characters too long, please edit
Post Title (30-60 characters):
______________________________:123456789012345678901234567890
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
59 characters, excellent!

Source Code

This is the source code for the newPost bash script.