Mass Adding YAML To Markdown Files (C# App To Generate FrontMatter)

After starting my digital garden with Jekyll, I stumbled upon a little repetition problem.

I had to manually add a front-matter section to each file, written in YAML.

Also, I had to rename the files for the Jekyll implementation to “see” them as posts.

I don’t alway have the patience to search for ready-made solutions.

I set out to make my own app – in C#.

Here’s is how it looks like (it’s May 2024).

But before giving you the tour…

What’s a digital garden?

Let’s say you love to take notes. You study a lot, you find interesting stuff online and you just love taking notes. And saving your best ideas.

And maybe you’d like to share some ideas with the world or with your peers.

One thing you can do is to create a public digital garden. You then upload  some of these notes and make them available for others.

And you keep re-engaging with those ideas over time. It’s kind of like … learning in public.

You expose your thinking process. And let others discover how your ideas evolve over time.

You allow them to see how you reach results.

Here are some of my files. They’re full of ideas and notes.

The digital garden I created requires the files I upload to respect a specific format.

All the files need to include a special section at the beginning, called the front matter.

The front matter gives instructions to the digital garden implementation on what to do with these files, how to process them.

The front matter is written with YAML, a human-readable configuration language.

And this YAML front matter must contain a few basic fields for the digital garden to pick it up.

The YAML Section

A minimal YAML section must include:

  • Title
  • Author
  • Date
  • Category
  • Layout

As for the files that will become posts:

  • The file name must start with a date prefix (e.g. 2024-05-09-)
  • The file extension must be .md (supports Markdown notation)

Here is a yaml frontmatter example from one of my files:

The YAML section must start with 3 dashes (—).

And it must end with 3 dashes as well (—).

Everything between the dashes is YAML code.

And below the dashes, we have the actual contents of the file.

It’s quite simple to write this yaml section by hand.

But when you have 20 files you want to update at the same time, things get tedious.

I wrote a program to generate YAML data for every file I specify.

The Tour Of The App

Here is how the app looks like in the Visual Studio UI Designer:

It’s developed with C# on Windows.

On the left, there’s the list for all the files to update.

On the right, a bunch of settings for the YAML front matter generation.

Below the settings, the MASS ADD YAML button will start processing all the files from the list.

Before going into detail, let me show you how it works.

We drag and drop text files to the list (.md or .txt extensions only).

We can also add folders using the + (ADD) button in the bottom left corner.

We can also drag and drop folders from windows explorer and the app will search for text files in those folders.

When we press the button to start processing, it will generate YAML and add it to each file.

Also, you can select the folder where to output the files that have been processed.

Now let’s have a look at the…

Application Settings

The Title field is generated based on the file name
The Author field adds the author field to the front matter

Author, Layout, Date are added based on the values entered in the field.
If any option is unchecked, it will not be added to the YAML section.

Also there are 3 options below
– Overwrite FrontMatter will overwrite any previous YAML front matter if it finds it
– Rename txt to md: if you have this checked, all .txt files will be renamed to .md upon processing
– Add File Name prefix will add a date prefix to the file name

As for categories, the functionality is not fully implemented yet, and it will add only a simple default category.

Leave a Reply

Your email address will not be published. Required fields are marked *