New setting for post types

This commit is contained in:
Will Boyd
2020-12-26 13:18:49 -05:00
parent 0f69e8cf46
commit 2e9550f14a
3 changed files with 41 additions and 20 deletions
+32 -20
View File
@@ -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) {
+4
View File
@@ -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;
+5
View File
@@ -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'));
}