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
+2
View File
@@ -224,6 +224,7 @@ function populateFrontmatter(posts) {
});
// inject custom taxonomy slugs into frontmatter, each taxonomy as its own field
if (shared.config.includeCustomTaxonomies) {
Object.entries(post.customTaxonomies).forEach(([domain, slugs]) => {
if (slugs.length > 0) {
if (Object.hasOwn(post.frontmatter, domain)) {
@@ -233,6 +234,7 @@ function populateFrontmatter(posts) {
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',
+10 -1
View File
@@ -10,8 +10,10 @@ import * as shared from './shared.js';
export async function writeFilesPromise(posts, taxonomies) {
await writeMarkdownFilesPromise(posts);
await writeImageFilesPromise(posts);
if (shared.config.saveTaxonomyData) {
await writeTaxonomyFilesPromise(taxonomies);
}
}
async function processPayloadsPromise(payloads, loadFunc) {
const promises = payloads.map((payload) => new Promise((resolve, reject) => {
@@ -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;