fix: filter out paid articles (#1659)

fix #1658
This commit is contained in:
Henry Wang
2019-03-04 11:04:33 +00:00
committed by DIYgod
parent fac1541ae6
commit db474c726f

View File

@@ -11,15 +11,21 @@ module.exports = async (ctx) => {
const list = $('a.list-group-item')
.slice(0, 10)
.filter((i, e) => $(e).find('h4.media-heading i').length === 0)
.map(function() {
const info = {
title: $(this)
.find('h4.media-heading')
.text()
.trim(),
author: $(this)
.find('.text-500')
.text(),
link: $(this).attr('href'),
date: $(this)
.find('p.pull-right.media-date strong')
.text(),
.text()
.trim(),
};
return info;
})
@@ -27,8 +33,6 @@ module.exports = async (ctx) => {
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = url.resolve(host, info.link);
const cache = await ctx.cache.get(itemUrl);
@@ -47,19 +51,22 @@ module.exports = async (ctx) => {
.trim();
const single = {
title: title,
title: info.title,
author: info.author,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
description,
pubDate: new Date(info.date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: 'leetcode文章',
link: link,
title: 'LeetCode Articles',
description: 'LeetCode Articles, the only official solutions you will find.',
link,
item: out,
};
};