Created
December 21, 2020 18:59
-
-
Save kloh-fr/4b2d9c4fdcc5c5012ba55cd518f441c5 to your computer and use it in GitHub Desktop.
Convert WordPress posts to 11ty (from json export)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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