Importing Markdown Files

I have over 150 blog posts markdown files with YAML front matter. I either need to import them into Grav or run a script to create folders, move and rename these files. I’m sure I’m not the first person to have ever needed this feature, but I haven’t found anything searching discourse or the main site.

Any ideas?

well, the lack of response (or even people viewing my question) is a bit concerning. Can’t tell if no one visits because they never need help, or if the userbase is sparse.

I haven’t answered because I don’t know. I understand and agree with what you say. I would expect it’s been done before and you could find a tool, probably not Grav-oriented, not that that matters. You might need to write a short script. Please share if you do.

1 Like

Is there any way to simply drop all my markdown files into a folder (say, named ‘blog’) and serve them from there? Having to create a separate folder for each of the 155 files is the part I would like to avoid…


I don’t know it there is a specific tool to import your markdown files, but if you don’t want ton create a separate folder for each, you could use a command for that.

Let’s say that all your posts are in the same folder and you want to create a seperate folder for each and move the file in its new folder :

  1. Open the “Run window” (windows + r)
  2. Lauch a command prompt (write cmd, then press enter)
  3. Navigate to your folder using cd
  4. Let the magic begins : for %i in (*) do move “%i” “%~ni”

I’ll need to do this in linux:

1 - strip the date from the file name
2 - create a folder based on the remaining file name
3 - move the file into the new folder
4 - rename the file to ‘’

Preferably all in one command. Easy peasy…

I don’t use linux so I won’t be able to help you with that, but you could have a look to this question on stack overflow:

There is the “create folder and move file” part already.
If the date always has the same format, you could strip the corresponding number of characters.

That’s where my knowledge stop. You’ll need someone using linux from there. :wink:

1 Like

Thanks for the assist. I just finished testing a script I found on another StackOverflow question - very concise and works very well!

1 Like

That’s nice.

Would you mind sharing the script here, in case someone else need it ?
Maybe it could even go to the cookbook.

1 Like

I went through this process with ~1000 MD files…

Used this script to create folders with appropriately dated names from the file:

then did a global rename of all the .MD files to item.MD

as for checking the YAML it was an entire manual process and p.i.t.a.

HTH -Andreas

1 Like

AmauryH - the link is in my reply :slight_smile:

I did a lot of search/replace using find and sed - but I often caused more problems along the way. Stripped the dashes that delineate the header before I discovered that they were fairly essential. When trying to fix my markdown image links I managed to add square brackets behind every exclamation point in every post. I use way too many exclamation points, btw…