mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
feat: add options to include custom taxonomies and save taxonomy data in frontmatter
This commit is contained in:
+10
-8
@@ -224,15 +224,17 @@ function populateFrontmatter(posts) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// inject custom taxonomy slugs into frontmatter, each taxonomy as its own field
|
// inject custom taxonomy slugs into frontmatter, each taxonomy as its own field
|
||||||
Object.entries(post.customTaxonomies).forEach(([domain, slugs]) => {
|
if (shared.config.includeCustomTaxonomies) {
|
||||||
if (slugs.length > 0) {
|
Object.entries(post.customTaxonomies).forEach(([domain, slugs]) => {
|
||||||
if (Object.hasOwn(post.frontmatter, domain)) {
|
if (slugs.length > 0) {
|
||||||
console.warn(`⚠️ Skipping custom taxonomy '${domain}' on post '${post.slug}' because it conflicts with an existing frontmatter field.`);
|
if (Object.hasOwn(post.frontmatter, domain)) {
|
||||||
return;
|
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;
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,40 @@ export function load() {
|
|||||||
description: 'Frontmatter fields',
|
description: 'Frontmatter fields',
|
||||||
default: 'title,date,categories,tags,coverImage,draft'
|
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',
|
name: 'request-delay',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
|
|||||||
+11
-2
@@ -10,7 +10,9 @@ import * as shared from './shared.js';
|
|||||||
export async function writeFilesPromise(posts, taxonomies) {
|
export async function writeFilesPromise(posts, taxonomies) {
|
||||||
await writeMarkdownFilesPromise(posts);
|
await writeMarkdownFilesPromise(posts);
|
||||||
await writeImageFilesPromise(posts);
|
await writeImageFilesPromise(posts);
|
||||||
await writeTaxonomyFilesPromise(taxonomies);
|
if (shared.config.saveTaxonomyData) {
|
||||||
|
await writeTaxonomyFilesPromise(taxonomies);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processPayloadsPromise(payloads, loadFunc) {
|
async function processPayloadsPromise(payloads, loadFunc) {
|
||||||
@@ -193,7 +195,14 @@ function logSavingMessage(things, existingCount, remainingCount) {
|
|||||||
async function writeTaxonomyFilesPromise(taxonomies) {
|
async function writeTaxonomyFilesPromise(taxonomies) {
|
||||||
shared.logHeading('Saving taxonomy data');
|
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) {
|
if (entries.length === 0) {
|
||||||
console.log('No taxonomy data to save.');
|
console.log('No taxonomy data to save.');
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user