mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-11 18:56:14 +09:00
New setting for post types
This commit is contained in:
+32
-20
@@ -37,27 +37,39 @@ function collectPosts(data, config) {
|
||||
// this is passed into getPostContent() for the markdown conversion
|
||||
const turndownService = translator.initTurndownService();
|
||||
|
||||
const posts = getItemsOfType(data, 'post')
|
||||
.filter(post => post.status[0] !== 'trash' && post.status[0] !== 'draft')
|
||||
.map(post => ({
|
||||
// meta data isn't written to file, but is used to help with other things
|
||||
meta: {
|
||||
id: getPostId(post),
|
||||
slug: getPostSlug(post),
|
||||
coverImageId: getPostCoverImageId(post),
|
||||
imageUrls: []
|
||||
},
|
||||
frontmatter: {
|
||||
title: getPostTitle(post),
|
||||
date: getPostDate(post),
|
||||
categories: getCategories(post),
|
||||
tags: getTags(post)
|
||||
},
|
||||
content: translator.getPostContent(post, turndownService, config)
|
||||
}));
|
||||
let allPosts = [];
|
||||
settings.post_types.forEach(postType => {
|
||||
const postsForType = getItemsOfType(data, postType)
|
||||
.filter(post => post.status[0] !== 'trash' && post.status[0] !== 'draft')
|
||||
.map(post => ({
|
||||
// meta data isn't written to file, but is used to help with other things
|
||||
meta: {
|
||||
id: getPostId(post),
|
||||
slug: getPostSlug(post),
|
||||
coverImageId: getPostCoverImageId(post),
|
||||
type: postType,
|
||||
imageUrls: []
|
||||
},
|
||||
frontmatter: {
|
||||
title: getPostTitle(post),
|
||||
date: getPostDate(post),
|
||||
categories: getCategories(post),
|
||||
tags: getTags(post)
|
||||
},
|
||||
content: translator.getPostContent(post, turndownService, config)
|
||||
}));
|
||||
|
||||
console.log(posts.length + ' posts found.');
|
||||
return posts;
|
||||
if (settings.post_types.length > 1) {
|
||||
console.log(`${postsForType.length} "${postType}" posts found.`);
|
||||
}
|
||||
|
||||
allPosts.push(...postsForType);
|
||||
});
|
||||
|
||||
if (settings.post_types.length === 1) {
|
||||
console.log(allPosts.length + ' posts found.');
|
||||
}
|
||||
return allPosts;
|
||||
}
|
||||
|
||||
function getPostId(post) {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// the post types you want to export (the default is plain old vanilla "post")
|
||||
// if you specify multiple post types, then a folder will be created for each within the output folder
|
||||
exports.post_types = ['post'];
|
||||
|
||||
// time in ms to wait between requesting image files
|
||||
// increase this if you see timeouts or server errors
|
||||
exports.image_file_request_delay = 500;
|
||||
|
||||
@@ -132,6 +132,11 @@ function getPostPath(post, config) {
|
||||
// start with base output dir
|
||||
const pathSegments = [config.output];
|
||||
|
||||
// create fragment for post type, if there's more than one
|
||||
if (settings.post_types.length > 1) {
|
||||
pathSegments.push(post.meta.type);
|
||||
}
|
||||
|
||||
if (config.yearFolders) {
|
||||
pathSegments.push(dt.toFormat('yyyy'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user