Skip to content

Commit

Permalink
Merge pull request #42 from curbengh/object-shorthand
Browse files Browse the repository at this point in the history
refactor: object-shorthand & destructure
  • Loading branch information
curbengh committed Feb 17, 2020
2 parents 5109153 + 4759015 commit 0240913
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/feed.js
Expand Up @@ -14,22 +14,22 @@ const template = {
items: ['//item', {
title: 'title',
link: 'link',
description: 'description',
excerpt: 'description',
content: 'content:encoded',
date: 'pubDate',
id: 'guid',
categories: ['category', '.']
tags: ['category', '.']
}]
},
atom: {
items: ['//entry', {
id: 'id',
title: 'title',
date: 'published',
description: 'summary',
excerpt: 'summary',
content: 'content',
link: 'link',
categories: ['category', '@term']
tags: ['category', '@term']
}]
}
};
Expand Down
25 changes: 15 additions & 10 deletions lib/migrator.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0240913

Please sign in to comment.