Importing Markdown Files Into Kirby

Hi there!

I’m researching the possibility of moving a website to Kirby. I don’t see any official/unofficial importer plugins in my searching, but I could have missed something obvious. I’m coming from a static site generator, so I have a pile of markdown files to work with. The site is about 600-plus total pages/posts. I’m not hoping for perfection, but maybe a head start. :sweat_smile: How have folks handled this in the past?

Appreciate any guidance you all have.

Basically, the procedure is always the same, no matter from what source you start:

  1. Read the original content/front matter
  2. Convert this import data into Kirby pages, using Page::create() (Page::create() | Kirby CMS). This takes care of creating the page folder with the content text file inside.

So the basic procedure is fairly easy. I’m not familiar with static site generators, but I guess information about the page structure is somewhere in the front-matter? So that would then help to determine the site structure.

But then in a site there are usually files as well. So you would have to copy them into the page folders as well.

While there are WordPress importers out there, I haven’t seen an importer for static site generators, although I’m pretty sure there are people who’ve done it.

I would write a quick python script to rename / modify the files to the desired folder structure / file name / file content structure that you would need with Kirby.
This will depend widely on what your pages contain, and how you plan on editing the content with Kirby.
If all your files are a single Title and full markdown content, you could go with a single kirby blueprint and template with title and a markdwon field. This would be the quickest way.
If however you have a lot of page specific fields/settings you need to reproduce, it would require a bit more tweeking.

Thanks for the help you all. I’m going to dig in more and see if I can write some kind of script myself.

If you get stuck, we are here to help.

Okay, I cooked up something that has mostly worked. :sweat_smile:

I posted the script over on GitHub as a gist. It’s certainly not the most elegant code, but a few hours of work saved me many hours of manual editing.

I did have some things not come out perfectly, likely because of my code:

  • In some cases, the spacing between the “----” was off because some files didn’t have the text I searched for each time.
  • Some of my tags didn’t get removed completely, leaving a stray word here or there. Seemed to only happen with one or two tags.

I manually checked and edited anything that looked off. Still was quick, considering I have hundreds of files.

Happy to have someone use this or turn it into something better.

1 Like

That’s why I suggested to use Kirby’s Page::create() method, in which you just pass an array with your data, then Kirby takes care of the rest, including the separation dashes…

Fair point! :upside_down_face: I should have explored that route some more. I went with what I got working quickest.

Thanks so much for sharing this. I’m converting a site with hundreds of YAML files at the moment, and this saved me a huge amount of headache :folded_hands:

Glad it helped someone, Dave! Good luck with the site.

1 Like