2020 has been a personal milestone year of blogging for me. I’m proud of what I’ve been able to accomplish and humbled by the many folks who read and promote my work. Thank you to all my champions! In a show of gratitude, I want to share my blogging workflow with you, my readers. In a previous post, I talked about using Thor, a ruby library for performing basic tasks like creating a new post, scheduling an upcoming post on a schedule, and outputting general diagnostic about my current writing.
We’ll look at my current command line actions so folks can build their custom supercharged writing workflow.
Prerequisites
I’ve taken the liberty of creating a repo where you can get started with the code found in this post. Fork it and enjoy the polyglot madness!.
For first-time folks, as of writing this post, this blog is powered by Jekyll, a static site generator. It might not be the newest tool on the block, but I find it generally stays out of my way when writing. Markdown support is top-notch, and plugins are aplenty.
The idea behind my workflow is to lean on Jekyll for static site generation but to automate most of the tedious work of managing files, thinking about publishing dates, and in the future to expand functionality.
If you don’t have a current blog, I recommend the following setup.
- Platform: Ruby
- Platform: Jekyll
- Platform: .NET
- Package: Oakton
- Package: Spectre.Console
- Package: SimpleExec
After installing Ruby and .NET, folks can create a starter project with the following commands in a terminal.
Congratulations! You now have a Frankenproject of Ruby and .NET. Now we can start looking at some of the code that I use to power this blog.
You will also need to exclude
files from the Jekyll build pipeline, or Jekyll may attempt to copy our C# files to the final target folder.
Blog Helpers
.NET developers know that our .NET apps’ working directory is within the bin
directory. For Jekyll sites, all the essential files sit at the root of our initial directory. To make commands work, we need to set up a Settings
class. The first significant helper methods are to change our work on the files in our Jekyll blog.
Great! I have more settings specific to my blog, but these properties are foundational values. The Blog
class holds helper methods to perform the following actions:
- Retrieve All The Posts From our
_posts
directory - Get The latest blog post
- Get The next publish date, based on my
Tuesday
andThursday
schedule - Create a new post file
Here is the code for working with posts. Folks should modify these helpers to match their writing schedule and update the Jekyll front matter to fit their particular Jekyll theme.
Info Command
The info
command helps me understand my current progress and helping to plan my next posts. I use this command more than I thought I would, as it helps me feel calm and less pressured when I see the backlog of posts that I have created. Here is the resulting output.
The command uses Oakton and Spectre.Console and we can execute it with the following command.
Here is the code to make the info command work.
New Post Command
As mentioned earlier in the post, my writing schedule dictates that I publish a new post on Tuesday
and Thursday
. Instead of sitting down and looking at a calendar, we can automate that by using the Blog.Next
method. Here is my command for creating a new post within the schedule.
If I need to get my thoughts out immediately, I can use the now
flag.
I can also start my favorite editor.
Let’s look at the code for the command.
I cannot overstate how awesome it is for this command to do the date mathematics for me. When I want to write or schedule a post, it just works!
Server Command
Jekyll has a few flags we need to pass in to make local rendering of future posts possible. I encapsulated that logic into the ServerCommand
.
Conclusion
There you have it! By leaning on Jekyll and .NET, you can create your writing Frankenblog just like me. By depending on .NET OSS, I can automate tedious actions like scheduling and creating files. If you use my workflow, please let me know what things you add to your workflow and find it helpful for others.
Remember, you can fork this starter template from this GitHub repository called Frankenblog.
Please leave a comment below on your thoughts.
Also checkout out some of my previous posts about Oakton: