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