diff --git a/src/parser.js b/src/parser.js index cff6ae9..5c87fee 100644 --- a/src/parser.js +++ b/src/parser.js @@ -48,7 +48,9 @@ function collectPosts(data, config) { }, frontmatter: { title: getPostTitle(post), - date: getPostDate(post) + date: getPostDate(post), + categories: getCategories(post), + tags: getTags(post), }, content: translator.getPostContent(post, turndownService, config) })); @@ -80,7 +82,24 @@ function getPostTitle(post) { } function getPostDate(post) { - return luxon.DateTime.fromRFC2822(post.pubDate[0], { zone: 'utc' }).toISODate(); + return luxon.DateTime.fromRFC2822(post.pubDate[0], { zone: 'utc' }).toISO(); +} + +function getCategories(post) { + return processCategoryTags(post, "category"); +} + +function getTags(post) { + return processCategoryTags(post, "post_tag"); +} + +function processCategoryTags(post, domain) { + if (!post.category) { + return []; + } + return post.category + .filter(c => c["$"].domain === domain) + .map(({ $: c }) => c.nicename); } function collectAttachedImages(data) { diff --git a/src/writer.js b/src/writer.js index 27e9c43..33be01b 100644 --- a/src/writer.js +++ b/src/writer.js @@ -58,8 +58,10 @@ async function loadMarkdownFilePromise(post) { let output = '---\n'; Object.entries(post.frontmatter).forEach(pair => { const key = pair[0]; - const value = (pair[1] || '').replace(/"/g, '\\"'); - output += key + ': "' + value + '"\n'; + const value = Array.isArray(pair[1]) + ? (pair[1].length === 0 ? "" : "\n - \"" + pair[1].join("\"\n - \"") + "\"") + : '"' + (pair[1] || '').replace(/"/g, '\\"') +'"'; + output += key + ': ' + value + '\n'; }); output += '---\n\n' + post.content + '\n'; return output;