mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-19 14:43:58 +09:00
refactor: simplify taxonomy entry creation in collectTaxonomyMetadata
This commit is contained in:
+16
-12
@@ -236,29 +236,34 @@ function populateFrontmatter(posts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildTaxonomyEntry({ slug, name, parent, description }) {
|
||||||
|
const entry = { slug, name };
|
||||||
|
if (parent) entry.parent = parent;
|
||||||
|
if (description) entry.description = description;
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
function collectTaxonomyMetadata(channel) {
|
function collectTaxonomyMetadata(channel) {
|
||||||
const taxonomies = {};
|
const taxonomies = {};
|
||||||
|
|
||||||
// channel-level <wp:category> elements (stripped to 'category')
|
// channel-level <wp:category> elements (stripped to 'category')
|
||||||
const wpCategories = channel.children('category');
|
const wpCategories = channel.children('category');
|
||||||
if (wpCategories.length > 0) {
|
if (wpCategories.length > 0) {
|
||||||
taxonomies.category = wpCategories.map((cat) => ({
|
taxonomies.category = wpCategories.map((cat) => buildTaxonomyEntry({
|
||||||
termId: parseInt(cat.optionalChildValue('term_id')),
|
|
||||||
slug: cat.optionalChildValue('category_nicename'),
|
slug: cat.optionalChildValue('category_nicename'),
|
||||||
name: cat.optionalChildValue('cat_name'),
|
name: cat.optionalChildValue('cat_name'),
|
||||||
parent: cat.optionalChildValue('category_parent') || null,
|
parent: cat.optionalChildValue('category_parent'),
|
||||||
description: cat.optionalChildValue('category_description') || null
|
description: cat.optionalChildValue('category_description')
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// channel-level <wp:tag> elements (stripped to 'tag')
|
// channel-level <wp:tag> elements (stripped to 'tag')
|
||||||
const wpTags = channel.children('tag');
|
const wpTags = channel.children('tag');
|
||||||
if (wpTags.length > 0) {
|
if (wpTags.length > 0) {
|
||||||
taxonomies.post_tag = wpTags.map((tag) => ({
|
taxonomies.post_tag = wpTags.map((tag) => buildTaxonomyEntry({
|
||||||
termId: parseInt(tag.optionalChildValue('term_id')),
|
|
||||||
slug: tag.optionalChildValue('tag_slug'),
|
slug: tag.optionalChildValue('tag_slug'),
|
||||||
name: tag.optionalChildValue('tag_name'),
|
name: tag.optionalChildValue('tag_name'),
|
||||||
description: tag.optionalChildValue('tag_description') || null
|
description: tag.optionalChildValue('tag_description')
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,13 +277,12 @@ function collectTaxonomyMetadata(channel) {
|
|||||||
if (!taxonomies[taxonomy]) {
|
if (!taxonomies[taxonomy]) {
|
||||||
taxonomies[taxonomy] = [];
|
taxonomies[taxonomy] = [];
|
||||||
}
|
}
|
||||||
taxonomies[taxonomy].push({
|
taxonomies[taxonomy].push(buildTaxonomyEntry({
|
||||||
termId: parseInt(term.optionalChildValue('term_id')),
|
|
||||||
slug: term.optionalChildValue('term_slug'),
|
slug: term.optionalChildValue('term_slug'),
|
||||||
name: term.optionalChildValue('term_name'),
|
name: term.optionalChildValue('term_name'),
|
||||||
parent: term.optionalChildValue('term_parent') || null,
|
parent: term.optionalChildValue('term_parent'),
|
||||||
description: term.optionalChildValue('term_description') || null
|
description: term.optionalChildValue('term_description')
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
return taxonomies;
|
return taxonomies;
|
||||||
|
|||||||
Reference in New Issue
Block a user