feat: add options to include custom taxonomies and save taxonomy data in frontmatter

This commit is contained in:
2026-03-12 15:31:57 +09:00
parent 287af36d7d
commit e475523979
3 changed files with 55 additions and 10 deletions
+10 -8
View File
@@ -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;
}
});
});
}
});
}
+34
View File
@@ -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',
+11 -2
View File
@@ -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;