Skip to content

Instantly share code, notes, and snippets.

@kloh-fr
Created December 21, 2020 18:59
Show Gist options
  • Save kloh-fr/4b2d9c4fdcc5c5012ba55cd518f441c5 to your computer and use it in GitHub Desktop.
Save kloh-fr/4b2d9c4fdcc5c5012ba55cd518f441c5 to your computer and use it in GitHub Desktop.
Convert WordPress posts to 11ty (from json export)
/**
* Convert WordPress posts to 11ty from json export
* https://heydonworks.com/article/wordpress-to-eleventy/
*/
const transformAndWriteToFile = require("json-to-frontmatter-markdown").default;
const wordpressData = require(__dirname + "/wordpress.json");
const posts = wordpressData.posts;
Object.keys(posts).forEach((p, i) => {
let post = posts[p];
transformAndWriteToFile({
frontmatterMarkdown: {
frontmatter: [
{
layout: "layouts/article.njk",
},
{
title: post.title.rendered.replace(/’/g, "’"),
},
{
date: post.date,
},
{
permalink: `articles/${post.slug}/index.html`,
},
],
body: post.content.rendered
.replace(/https:\/\/www.kloh.ch\/wp-content\/uploads/g, "/images")
.replace(/\/wp-content\/uploads/g, "/images")
.replace(/ class="h3-like"/g, ""),
},
path: "./src/articles",
fileName: `${post.slug}.md`,
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment