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:
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user