Skip to content

Instantly share code, notes, and snippets.

@yossale
Last active December 28, 2016 15:34
Show Gist options
  • Save yossale/4c9b380ddd37dd976e65 to your computer and use it in GitHub Desktop.
Save yossale/4c9b380ddd37dd976e65 to your computer and use it in GitHub Desktop.
Fix "error: Value in [posts.slug] exceeds maximum length of 150 characters." error when importing from Wordpress to Ghost
var fs = require('fs');
var filePath = process.argv[2];
var content = null;
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
//Sometimes the shortning causes duplicte sluglines, which are forbidden. So the map is here to handle it.
var slugsMap = {};
content = JSON.parse(data);
var posts = content.data.posts;
posts.forEach(function (post) {
if (post.slug.length > 150) {
post.slug = post.slug.substring(0, 149);
if (slugsMap[post.slug]) {
console.log("Found duplicate: " + post.slug);
slugsMap[post.slug]++
post.slug = (slugsMap[post.slug] + post.slug).substring(0, 149);
console.log("Changed to: " + post.slug);
} else {
slugsMap[post.slug] = 1;
}
}
});
var outputFile = "./parsed_slugline.json";
fs.writeFile(outputFile, JSON.stringify(content), function (err) {
if (err) {
console.log(err);
} else {
console.log("File was saved to " + __dirname + "/" + outputFile);
}
})
});
@yossale
Copy link
Author

yossale commented Jul 19, 2014

Run the script on the json file you exported from wordpress, and use the new output when importing to Ghost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment