Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Installation & Hosting

Importing Markdown Files

solved

Solved by Glenn View solution

Started by Glenn 8 years ago · 11 replies · 1899 views
8 years ago

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?

8 years ago

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.

8 years ago

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
8 years ago

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...

8 years ago

Hello,

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"
8 years ago

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 'post.md'

Preferably all in one command. Easy peasy...

8 years ago

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:
https://stackoverflow.com/questions/22668866/linux-bash-script-to-create-folder-and-move-files
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. ;)

👍 1
8 years ago

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
8 years ago

AmauryH - the link is in my reply 🙂

8 years ago

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...

Suggested topics

Topic Participants Replies Views Activity
Installation & Hosting · by antoinep, 13 hours ago
5 60 8 hours ago
Installation & Hosting · by Jürgen Dietrich, 7 months ago
0 62 7 months ago
Installation & Hosting · by rappluk, 8 months ago
0 62 8 months ago
Installation & Hosting · by N, 12 months ago
3 72 12 months ago
Installation & Hosting · by Youle, 1 year ago
1 61 1 year ago