mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
feat: add digic picture (#4567)
This commit is contained in:
@@ -4,6 +4,12 @@ pageClass: routes
|
||||
|
||||
# 设计
|
||||
|
||||
## Digic Picture
|
||||
|
||||
### 作品和新闻
|
||||
|
||||
<Route author="MisteryMonster" example="/digic-pictures/works/real-time-engine" path="/digic-pictures/:menu/:tag?" :paramsDesc="['`news`, `works`', 'WORK 下项目类型: `/game-cinematics`, `/feature`, `/making-of`, `/commercials-vfx`, `/real-time-engine`']"/>
|
||||
|
||||
## Blur Studio
|
||||
|
||||
### Works
|
||||
|
||||
@@ -4,6 +4,12 @@ pageClass: routes
|
||||
|
||||
# Design
|
||||
|
||||
## Digic Picture
|
||||
|
||||
### Works & News
|
||||
|
||||
<RouteEn author="MisteryMonster" example="/digic-pictures/works/real-time-engine" path="/digic-pictures/:menu/:tag?" :paramsDesc="['`news`, `works`', 'Under WORK types: `/game-cinematics`, `/feature`, `/making-of`, `/commercials-vfx`, `/real-time-engine`']" />
|
||||
|
||||
## Blur Studio
|
||||
|
||||
### Works
|
||||
|
||||
@@ -2598,4 +2598,7 @@ router.get('/bendibao/news/:city', require('./routes/bendibao/news'));
|
||||
// unit-image
|
||||
router.get('/unit-image/films/:type?', require('./routes/unit-image/films'));
|
||||
|
||||
// digic-picture
|
||||
router.get('/digic-pictures/:menu/:tags?', require('./routes/digic-pictures/index'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
72
lib/routes/digic-pictures/index.js
Executable file
72
lib/routes/digic-pictures/index.js
Executable file
@@ -0,0 +1,72 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { menu, tags } = ctx.params;
|
||||
const url = `https://digicpictures.com/${menu}/${tags}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('ul#articles-slider li').get().slice(0, 5);
|
||||
const articledata = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
item = $(item);
|
||||
const link = item.find('a').attr('href');
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const response2 = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
const articledata = response2.data;
|
||||
const $2 = cheerio.load(articledata);
|
||||
const title = $2('div#main-content>div>div>div').find('h1').text();
|
||||
const time = $2('div#main-content>div>div>div:nth-child(1) p').text();
|
||||
const images = $2('#main-slider img')
|
||||
.get()
|
||||
.map((item) => $2(item).attr('src'));
|
||||
const content = $2('div#main-content>div>div>div:nth-child(2)')
|
||||
.html()
|
||||
.replace(/<span style="(.*?)">/g, '')
|
||||
.replace('<span>', '<br>')
|
||||
.replace(/<.?p>/g, '');
|
||||
const single = {
|
||||
title,
|
||||
link,
|
||||
time,
|
||||
content,
|
||||
images,
|
||||
};
|
||||
ctx.cache.set(link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Digic Picture',
|
||||
link: 'https://www.digicpictures.com/',
|
||||
item: list.map((item, index) => {
|
||||
let content = '';
|
||||
const imgstyle = `style="max-width: 650px; height: auto; object-fit: contain; flex: 0 0 auto;"`;
|
||||
|
||||
content += `${articledata[index].time}<br>${articledata[index].content}<br>`;
|
||||
if (articledata[index].images) {
|
||||
for (let p = 0; p < articledata[index].images.length; p++) {
|
||||
content += `<img ${imgstyle} src="${articledata[index].images[p]}"><br>`;
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: `${articledata[index].title}`,
|
||||
description: content,
|
||||
link: `${articledata[index].link}`,
|
||||
pubDate: `${articledata[index].time}`,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user