From Wordpress to Zola

Prerequisites

  • nodejs
  • npm

Converting a Wordpress site to Zola

npx wordpress-export-to-markdown

# exported tree may vary based on options
posts/
├── 2009
│   ├── 01
│   │   ├── bon-matin.md
│   │   ├── et-cest-reparti.md
│   │   ├── rip-araya.md
│   │   ├── squat-express.md
│   │   └── ya-toujours-de-quoi-qui-se-passe.md
pages/
...

The wp2zola script

Now we need to convert hugo headers to zola

---
title: "Sortie hivernale 2"
date: 2008-01-09
categories:
  - "sortie-de-soir-en-fixe"
---

===>

+++
title = "Sortie hivernale 2"
date = "2008-01-09"
taxonomies = { tags = ["sortie-de-soir-en-fixe"] }
+++

This bash script will handle simple cases:

#!/usr/bin/env bash
# Convert hugo markups to zola

main() {
  local wpfile=$1 categories

  [[ -f "${wpfile}" ]] || exit 1

  categories="$(grep -oP '  - \K(\".*\")' "${wpfile}" | tr '\n' ',')"

  sed -i \
  -e 's/+++/+++/g' \
  -e 's/title: /title = /g' \
  -e 's/draft: /draft = /g' \
  -e 's/date: \([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)/date = "\1"/g' \
  -e '/  - \".*\"/d' \
  -e "s/taxonomies = { tags = [] }/taxonomies = { tags = [${categories%?}] }/g" "${wpfile}"
}

main "$@"
  • save this script to wp2zola and set the execute flag: chmod +x wp2zola
  • cd into your converted site and run the following command:
find -name *.md -exec wp2zola {} \;

Références

wordpress-export-to-markdown

tags: [ #wordpress, #zola ]

$HOME