Files
RSSHub/lib/v2/google/sitesRecentChanges.js
Ethan Shen 0a53418b93 feat: add google sites recent changes (#7246)
* feat: add google sites recent changes

* fix pubDate

* fix: wrong date format
2022-03-10 19:46:56 +08:00

53 lines
1.4 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id;
const rootUrl = 'https://sites.google.com';
const currentUrl = `${rootUrl}/site/${id}/activity.xml`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let items = $('entry')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('summary').text(),
link: item.find('summary a').attr('href'),
pubDate: parseDate(item.find('updated').text()),
author: item.find('author name').text(),
};
});
items = await Promise.all(
items.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('#sites-canvas').html();
return item;
})
)
);
ctx.state.data = {
title: $('feed title').first().text(),
link: currentUrl,
item: items,
};
};