feat(route): add DevolverDigital Blog (#12548)
* feat(route): add DevolverDigital Blog * use embedded json #__NEXT_DATA__ * index value using .map() * minor improvements
This commit is contained in:
@@ -38,6 +38,12 @@ pageClass: routes
|
||||
|
||||
<Route author="Jkker" example="/csdn/blog/csdngeeknews" path="/csdn/blog/:user" radar="1" :paramsDesc="['`user` 为 CSDN 用户名,可以在主页 url 中找到']" />
|
||||
|
||||
## DevolverDigital
|
||||
|
||||
### 官方博客
|
||||
|
||||
<Route author="XXY233" example="/devolverdigital/blog" path="/devolverdigital/blog" radar="1" />
|
||||
|
||||
## FreeBuf
|
||||
|
||||
### 文章
|
||||
|
||||
@@ -28,6 +28,12 @@ pageClass: routes
|
||||
|
||||
<RouteEn author="Jkker" example="/csdn/blog/csdngeeknews" path="/csdn/blog/:user" radar="1" :paramsDesc="['`user` is the username of a CSDN blog which can be found in the url of the home page']" />
|
||||
|
||||
## DevolverDigital
|
||||
|
||||
### Official Blogs
|
||||
|
||||
<RouteEn author="XXY233" example="/devolverdigital/blog" path="/devolverdigital/blog" radar="1" />
|
||||
|
||||
## Geocaching
|
||||
|
||||
### Official Blogs
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.devolverdigital.com/blog';
|
||||
|
||||
const { data: response } = await got(baseUrl);
|
||||
const $ = cheerio.load(response);
|
||||
$('noscript').remove();
|
||||
|
||||
const nextData = JSON.parse($('#__NEXT_DATA__').text());
|
||||
const allBlogContents = $('div.flex > div > div > div > div:not([class])');
|
||||
|
||||
const items = nextData.props.pageProps.posts.map((post, postIndex) => {
|
||||
// img resource redirection and
|
||||
// clean up absolute layouts for img and span
|
||||
|
||||
const imageUrls = post.body.filter((item) => item.type === 'upload' && item.value.cloudinary.resource_type === 'image').map((item) => item.value.cloudinary.secure_url);
|
||||
|
||||
const allImageSpans = $(allBlogContents[postIndex]).find('span > img').parent();
|
||||
|
||||
allImageSpans.each((spanIndex, span) => {
|
||||
$(span).attr('style', $(span).attr('style').replace('position:absolute', ''));
|
||||
const img = $(span).find('img');
|
||||
img.attr('src', imageUrls[spanIndex]);
|
||||
img.attr('style', img.attr('style').replace('position:absolute', '').replace('width:0', '').replace('height:0', ''));
|
||||
});
|
||||
|
||||
return {
|
||||
title: post.title,
|
||||
author: post.author,
|
||||
pubDate: Date.parse(post.createdAt),
|
||||
description: $(allBlogContents[postIndex]).html(),
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'DevolverDigital Blog',
|
||||
link: 'https://www.devolverdigital.com/blog',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/blog': ['XXY233'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'devolverdigital.com': {
|
||||
_name: 'DevolverDigital',
|
||||
'.': [
|
||||
{
|
||||
title: '官方博客',
|
||||
docs: 'https://docs.rsshub.app/blog.html#devolverdigital',
|
||||
source: '/blog',
|
||||
target: '/devolverdigital/blog',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/blog', require('./blog'));
|
||||
};
|
||||
Reference in New Issue
Block a user