fix: 为今日哈工大正文添加格式,提高阅读体验 (#3745)

This commit is contained in:
Honglin Mu
2020-01-16 14:10:19 +08:00
committed by DIYgod
parent dcec15de04
commit 40501a7dfd
+9 -1
View File
@@ -1,5 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
module.exports = async (ctx) => {
const host = 'http://today.hit.edu.cn';
@@ -62,12 +63,19 @@ module.exports = async (ctx) => {
}
const $ = cheerio.load(response.data);
const description =
$('.article-content').html() &&
$('.article-content')
.html()
.replace(/src="\//g, `src="${url.resolve(host, '.')}`)
.replace(/href="\//g, `href="${url.resolve(host, '.')}`)
.trim();
const single = {
pubDate: new Date($('.left-attr.first').text()).toUTCString(),
author: author,
link: link,
title: title,
description: $('.article-content').text(),
description: description,
};
ctx.cache.set(link, JSON.stringify(single));