Nicer post type logging

This commit is contained in:
Will Boyd
2025-03-08 17:46:44 -05:00
parent dc0b15c3d1
commit 39c2bf864a
+24 -4
View File
@@ -31,7 +31,7 @@ export async function parseFilePromise() {
function getPostTypes(allPostData) { function getPostTypes(allPostData) {
// search export file for all post types minus some specific types we don't want // search export file for all post types minus some specific types we don't want
const postTypes = allPostData const postTypes = [...new Set(allPostData // new Set() is used to dedupe array
.map((postData) => postData.childValue('post_type')) .map((postData) => postData.childValue('post_type'))
.filter((postType) => ![ .filter((postType) => ![
'attachment', 'attachment',
@@ -46,8 +46,14 @@ function getPostTypes(allPostData) {
'wp_navigation', 'wp_navigation',
'wp_template', 'wp_template',
'wp_template_part' 'wp_template_part'
].includes(postType)); ].includes(postType))
return [...new Set(postTypes)]; // remove duplicates )];
// change order to "post", "page", then all custom post types (alphabetically)
prioritizePostType(postTypes, 'page');
prioritizePostType(postTypes, 'post');
return postTypes;
} }
function getItemsOfType(allPostData, type) { function getItemsOfType(allPostData, type) {
@@ -63,7 +69,13 @@ function collectPosts(allPostData, postTypes) {
.map(postData => buildPost(postData)); .map(postData => buildPost(postData));
if (postsForType.length > 0) { if (postsForType.length > 0) {
console.log(`${postsForType.length} posts of type "${postType}" found.`); if (postType === 'post') {
console.log(`${postsForType.length} normal posts found.`);
} else if (postType === 'page') {
console.log(`${postsForType.length} pages found.`);
} else {
console.log(`${postsForType.length} custom "${postType}" posts found.`);
}
} }
allPosts.push(...postsForType); allPosts.push(...postsForType);
@@ -195,6 +207,14 @@ function populateFrontmatter(posts) {
}); });
} }
function prioritizePostType(postTypes, postType) {
const index = postTypes.indexOf(postType);
if (index !== -1) {
postTypes.splice(index, 1);
postTypes.unshift(postType);
}
}
function isAbsoluteUrl(url) { function isAbsoluteUrl(url) {
return (/^https?:\/\//i).test(url); return (/^https?:\/\//i).test(url);
} }