mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 07:40:26 +08:00
feat: add google sites (#4119)
This commit is contained in:
@@ -1124,6 +1124,14 @@
|
||||
script: "({id: document.querySelector('html').innerHTML.match(/photos.app.goo.gl\\/(.*?)\"/)[1]})",
|
||||
},
|
||||
],
|
||||
sites: [
|
||||
{
|
||||
title: 'Sites',
|
||||
docs: 'https://docs.rsshub.app/blog.html#google-sites',
|
||||
source: ['/site/:id/*', '/site/:id'],
|
||||
target: '/google/sites/:id',
|
||||
},
|
||||
],
|
||||
},
|
||||
'javlibrary.com': {
|
||||
_name: 'javlibrary',
|
||||
|
||||
@@ -10,6 +10,12 @@ pageClass: routes
|
||||
|
||||
<Route author="kt286" example="/archdaily" path="/archdaily"/>
|
||||
|
||||
## Google Sites
|
||||
|
||||
### 文章更新
|
||||
|
||||
<Route author="hoilc" example="/google/sites/outlierseconomics" path="/google/sites/:id" :paramsDesc="['Site ID, 可在 URL 中找到']" radar="1" />
|
||||
|
||||
## Hexo
|
||||
|
||||
### Next 主题博客
|
||||
|
||||
@@ -10,6 +10,12 @@ pageClass: routes
|
||||
|
||||
<RouteEn author="kt286" example="/archdaily" path="/archdaily"/>
|
||||
|
||||
## Google Sites
|
||||
|
||||
### Articles
|
||||
|
||||
<RouteEn author="hoilc" example="/google/sites/outlierseconomics" path="/google/sites/:id" :paramsDesc="['Site ID, can be found in URL']" />
|
||||
|
||||
## Hexo Blog
|
||||
|
||||
### Blog using Next theme
|
||||
|
||||
@@ -476,6 +476,7 @@ router.get('/google/citations/:id', require('./routes/google/citations'));
|
||||
router.get('/google/scholar/:query', require('./routes/google/scholar'));
|
||||
router.get('/google/doodles/:language?', require('./routes/google/doodles'));
|
||||
router.get('/google/album/:id', require('./routes/google/album'));
|
||||
router.get('/google/sites/:id', require('./routes/google/sites'));
|
||||
|
||||
// Awesome Pigtals
|
||||
router.get('/pigtails', require('./routes/pigtails'));
|
||||
|
||||
75
lib/routes/google/sites.js
Normal file
75
lib/routes/google/sites.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const base = 'https://sites.google.com/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const init_url = `https://sites.google.com/site/${id}/system/app/pages/sitemap/list?offset=0`;
|
||||
const init_response = await got.get(init_url);
|
||||
|
||||
const test_pages_count = init_response.data.match(/'sites-pagination-next-link-top', (\d+),/);
|
||||
if (!test_pages_count) {
|
||||
throw 'Site Not Found';
|
||||
}
|
||||
const pages_count = parseInt(test_pages_count[1]);
|
||||
|
||||
const url = pages_count > 20 ? `https://sites.google.com/site/${id}/system/app/pages/sitemap/list?offset=${pages_count - 20}` : init_url;
|
||||
const response = url === init_url ? init_response : await got.get(url);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const site_name = $('a#sites-chrome-userheader-title').text();
|
||||
const list = $('.sites-table > tbody > tr').get();
|
||||
|
||||
const parseContent = async (htmlString) => {
|
||||
const $ = cheerio.load(htmlString);
|
||||
|
||||
const content = $('#sites-canvas-main-content');
|
||||
|
||||
return {
|
||||
description: content.html(),
|
||||
};
|
||||
};
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item, index) => {
|
||||
const $ = cheerio.load(item);
|
||||
|
||||
const title = $('a');
|
||||
const path = title.attr('href');
|
||||
const link = base + path;
|
||||
const time = new Date();
|
||||
time.setMinutes(time.getMinutes() - pages_count + index);
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const rssitem = {
|
||||
title: title.text().trim(),
|
||||
link: link,
|
||||
pubDate: time,
|
||||
author: site_name,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await got.get(link);
|
||||
const result = await parseContent(response.data);
|
||||
rssitem.description = result.description;
|
||||
} catch (err) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
ctx.cache.set(link, JSON.stringify(rssitem));
|
||||
return Promise.resolve(rssitem);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${site_name} - Google Sites`,
|
||||
link: url,
|
||||
item: out.filter((item) => item !== ''),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user