diff --git a/src/parser.js b/src/parser.js index 47b44e7..11c7db0 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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) { diff --git a/src/settings.js b/src/settings.js index 9425ce9..78e90e1 100644 --- a/src/settings.js +++ b/src/settings.js @@ -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; diff --git a/src/writer.js b/src/writer.js index 3f23955..9d4362e 100644 --- a/src/writer.js +++ b/src/writer.js @@ -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')); }