diff --git a/src/parser.js b/src/parser.js index e9225f6..b2d2028 100644 --- a/src/parser.js +++ b/src/parser.js @@ -224,15 +224,17 @@ function populateFrontmatter(posts) { }); // inject custom taxonomy slugs into frontmatter, each taxonomy as its own field - Object.entries(post.customTaxonomies).forEach(([domain, slugs]) => { - if (slugs.length > 0) { - if (Object.hasOwn(post.frontmatter, domain)) { - console.warn(`⚠️ Skipping custom taxonomy '${domain}' on post '${post.slug}' because it conflicts with an existing frontmatter field.`); - return; + if (shared.config.includeCustomTaxonomies) { + Object.entries(post.customTaxonomies).forEach(([domain, slugs]) => { + if (slugs.length > 0) { + if (Object.hasOwn(post.frontmatter, domain)) { + console.warn(`⚠️ Skipping custom taxonomy '${domain}' on post '${post.slug}' because it conflicts with an existing frontmatter field.`); + return; + } + post.frontmatter[domain] = slugs; } - post.frontmatter[domain] = slugs; - } - }); + }); + } }); } diff --git a/src/questions.js b/src/questions.js index e9bec84..1ea6c1c 100644 --- a/src/questions.js +++ b/src/questions.js @@ -112,6 +112,40 @@ export function load() { description: 'Frontmatter fields', default: 'title,date,categories,tags,coverImage,draft' }, + { + name: 'include-custom-taxonomies', + type: 'boolean', + description: 'Include custom taxonomies in post frontmatter', + default: true, + choices: [ + { + name: 'Yes', + value: true + }, + { + name: 'No', + value: false + } + ], + prompt: inquirer.select + }, + { + name: 'save-taxonomy-data', + type: 'boolean', + description: 'Save taxonomy data to JSON files (categories, tags, and custom taxonomies if enabled)', + default: true, + choices: [ + { + name: 'Yes', + value: true + }, + { + name: 'No', + value: false + } + ], + prompt: inquirer.select + }, { name: 'request-delay', type: 'integer', diff --git a/src/writer.js b/src/writer.js index c0fe6ed..3fcd997 100644 --- a/src/writer.js +++ b/src/writer.js @@ -10,7 +10,9 @@ import * as shared from './shared.js'; export async function writeFilesPromise(posts, taxonomies) { await writeMarkdownFilesPromise(posts); await writeImageFilesPromise(posts); - await writeTaxonomyFilesPromise(taxonomies); + if (shared.config.saveTaxonomyData) { + await writeTaxonomyFilesPromise(taxonomies); + } } async function processPayloadsPromise(payloads, loadFunc) { @@ -193,7 +195,14 @@ function logSavingMessage(things, existingCount, remainingCount) { async function writeTaxonomyFilesPromise(taxonomies) { shared.logHeading('Saving taxonomy data'); - const entries = Object.entries(taxonomies); + const builtInTaxonomies = ['category', 'post_tag']; + const filteredTaxonomies = Object.fromEntries( + Object.entries(taxonomies).filter(([name]) => + builtInTaxonomies.includes(name) || shared.config.includeCustomTaxonomies + ) + ); + + const entries = Object.entries(filteredTaxonomies); if (entries.length === 0) { console.log('No taxonomy data to save.'); return;