diff --git a/lib/feed.js b/lib/feed.js index f469080..8f28b38 100644 --- a/lib/feed.js +++ b/lib/feed.js @@ -14,11 +14,11 @@ const template = { items: ['//item', { title: 'title', link: 'link', - description: 'description', + excerpt: 'description', content: 'content:encoded', date: 'pubDate', id: 'guid', - categories: ['category', '.'] + tags: ['category', '.'] }] }, atom: { @@ -26,10 +26,10 @@ const template = { id: 'id', title: 'title', date: 'published', - description: 'summary', + excerpt: 'summary', content: 'content', link: 'link', - categories: ['category', '@term'] + tags: ['category', '@term'] }] } }; diff --git a/lib/migrator.js b/lib/migrator.js index 4237367..2aaf9fb 100644 --- a/lib/migrator.js +++ b/lib/migrator.js @@ -8,6 +8,7 @@ const parseFeed = require('./feed'); module.exports = async function(args) { const source = args._.shift(); + const { alias } = args; let { limit } = args; const tomd = new TurndownService(); const { log } = this; @@ -46,26 +47,30 @@ module.exports = async function(args) { for (let i = 0; i < limit; i++) { const item = feed.items[i]; + const { date, tags, link } = item; + let { title } = item; + const content = tomd.turndown(item.content || item.excerpt); + const excerpt = tomd.turndown(item.excerpt); - if (!item.title) { + if (!title) { untitledPostCounter += 1; const untitledPostTitle = 'Untitled Post - ' + untitledPostCounter; - item.title = untitledPostTitle; + title = untitledPostTitle; log.w('Post found but without any titles. Using %s', untitledPostTitle); } else { - log.i('Post found: %s', item.title); + log.i('Post found: %s', title); } const newPost = { - title: item.title, - date: item.date, - tags: item.categories, - excerpt: tomd.turndown(item.description || ''), - content: tomd.turndown(item.content || item.description || '') + title, + date, + tags, + excerpt, + content }; - if (args.alias && item.link) { - newPost.alias = parse(item.link).pathname; + if (alias && link) { + newPost.alias = parse(link).pathname; } posts.push(newPost);