Fix d2 daily, fixed #1570 (#1576)

This commit is contained in:
周长安
2019-02-19 12:06:43 +08:00
committed by DIYgod
parent effce02a98
commit 7c0d60478f

View File

@@ -4,12 +4,12 @@ const url = require('url');
const sanitizeHtml = require('sanitize-html');
module.exports = async (ctx) => {
const indexLink = 'https://awesome.fairyever.com/daily/';
const indexLink = 'https://daily.fairyever.com/';
const { data } = await axios.get(indexLink);
const $ = cheerio.load(data);
// 修改 slice 可以获取更多天的内容,暂时最新的一天就够了
const days = $('ul.menu-list>li>a')
const days = $('.sidebar-link:contains(年)')
.slice(0, 1)
.toArray();
@@ -24,13 +24,17 @@ module.exports = async (ctx) => {
}
const { data } = await axios.get(link);
const $$ = cheerio.load(data);
let description = $$('article[title*=日报]>section')
// 去掉文章头部的 logo 和文章尾部的二维码
.slice(1, -1)
// 去除锚点
$$('a')
.filter(function() {
return $(this).text() === '#';
})
.remove();
let description = $$('.content')
.toArray()
.reduce((pre, cur) => pre + $$.html(cur), '');
description = sanitizeHtml(description, {
allowedTags: ['section', 'h2', 'ul', 'li', 'p', 'span', 'a'],
allowedTags: ['div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'li', 'p', 'span', 'a', 'blockquote'],
});
const item = {
title: $('head>title').text(),