mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix date and cache
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const cheerio = require('cheerio');
|
||||
const axios = require('../../utils/axios');
|
||||
const date = require('../../utils/date');
|
||||
const url = require('url');
|
||||
|
||||
const host = 'https://user.guancha.cn';
|
||||
@@ -21,9 +22,15 @@ module.exports = async (ctx) => {
|
||||
list.map(async (itemUrl) => {
|
||||
// 将相对链接替换为绝对链接
|
||||
const absoluteUrl = url.resolve(host, itemUrl);
|
||||
const cache = await ctx.cache.get(absoluteUrl);
|
||||
// 判断缓存
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await axios.get(absoluteUrl);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const dateStr = $('.user-main .time1').text();
|
||||
const item = {
|
||||
title: $('.article-content h1').text(),
|
||||
author: $('.user-main h4')
|
||||
@@ -32,12 +39,9 @@ module.exports = async (ctx) => {
|
||||
.text(),
|
||||
link: absoluteUrl,
|
||||
description: $('.article-txt-content').html(),
|
||||
pubDate: $('.user-main .time1').text(),
|
||||
// 格式化日期
|
||||
pubDate: date(dateStr),
|
||||
};
|
||||
const cache = await ctx.cache.get(absoluteUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
ctx.cache.set(absoluteUrl, JSON.stringify(item), 24 * 60 * 60);
|
||||
|
||||
return Promise.resolve(item);
|
||||
|
||||
Reference in New Issue
Block a user