Migrate content from Bolt to Grav CMS

By Jogai on Tuesday 6 July 2021 21:32 - Comments (0)
Category: Quick tips, Views: 3.375

A few steps to migrate the pages from bolt to grav. This probably could be improved, but this is the 80% that is enough for my use case. The following commands are working for me in bash (despite saying perl, thats just for highlighting). I'm not a bash/linux guru, so beware!

Export the pages from the bolt database
This will export the page body but prepends a minimal header we need for Grav. The newlines here are important!
sqlite3 bolt.db "select '@@@@@ 
                          slug: ' || slug || '
                          title: ' || title || '
                          ' || body from bolt_pages" > data.dump
Split the dump into a file per page
csplit -z --suppress-matched data.dump '/@@@@@/' {*}

The -z is to skip empty files. The result is a file without extension and with the minimal frontmatter config along with the content.
Move the pages into a Grav structure
Move the created files to your grav cms in user/pages or somewhere where you feel safe to execute a strangers script on the whole folder.
C=1; for file in *; do D="$C.$(sed -n '2p' $file | cut -b 7-)"; mkdir "$D"; mv "$file" "default.md"; mv "default.md" "$D/"; C=$[$C +1]; done
  • Loops over all the files
  • Read the first 2 lines
  • Cuts it short from the end (this should give you the value of slug
  • Makes a folder using the counter and the slug, because that's what grav expects in the folder structure
  • Renames the file to default.md
  • Moves that file into the the folder that it just created
The last loop could certainly be improved. Let me know in the comments. Kudos for just using pipes (tried that, but failed). Extra points if someone can point out how to improve the sqlite bit, so the splitting becomes unnecessary.

Edit: I just heard about the conimex plugin. That might be a better route to do this.

Since this blog is part of a dutch community you can comment in dutch below. But you're welcome to comment in english on reddit ;)