fix(route): behance v2 & fix (#9767)
* behance v2 & fix * behance v2 & fix * Try get & remove old radar * fetch limits * fix: maintainer
This commit is contained in:
parent
134372c826
commit
a60663ee91
|
|
@ -817,20 +817,6 @@
|
|||
{ title: '用户投稿', docs: 'https://docs.rsshub.app/anime.html#acfun-yong-hu-tou-gao', source: '/u/:id', target: '/acfun/user/video/:id' },
|
||||
],
|
||||
},
|
||||
'behance.net': {
|
||||
_name: 'Behance',
|
||||
www: [
|
||||
{
|
||||
title: 'User',
|
||||
docs: 'https://docs.rsshub.app/design.html#behance-user-works',
|
||||
source: ['/:user'],
|
||||
target: (params, url, document) => {
|
||||
const uid1 = document && document.querySelector('html').innerHTML.match(/([^/]+)\/insights/)[1];
|
||||
return `/behance/${uid1}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
'jjmhw.cc': { _name: '漫小肆', www: [{ title: '漫画更新', docs: 'https://docs.rsshub.app/anime.html#man-xiao-si', source: '/book/:id', target: '/manxiaosi/book/:id' }] },
|
||||
'wenxuecity.com': {
|
||||
_name: '文学城',
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ pageClass: routes
|
|||
|
||||
## Behance
|
||||
|
||||
### User Works
|
||||
### 用户作品
|
||||
|
||||
<Route author="MisteryMonster" example="/behance/mishapetrick" path="/behance/:user/:type?" :paramsDesc="['用户名', '类型,可选 `projects` 或 `appreciated`']" radar="1">
|
||||
<Route author="MisteryMonster" example="/behance/mishapetrick" path="/behance/:user/:type?" :paramsDesc="['用户名', '类型,可选 `projects` 或 `appreciated`,默认为 `projects`']" radar="1">
|
||||
|
||||
Behance 用户主页 URL 获取用户名,如 <https://www.behance.net/mishapetrick> 的用户名为 `mishapetrick`。
|
||||
|
||||
|
|
|
|||
|
|
@ -1673,20 +1673,6 @@ module.exports = {
|
|||
},
|
||||
],
|
||||
},
|
||||
'behance.net': {
|
||||
_name: 'Behance',
|
||||
www: [
|
||||
{
|
||||
title: 'User',
|
||||
docs: 'https://docs.rsshub.app/design.html#behance-user-works',
|
||||
source: ['/:user'],
|
||||
target: (params, url, document) => {
|
||||
const uid1 = document && document.querySelector('html').innerHTML.match(/([^/]+)\/insights/)[1];
|
||||
return `/behance/${uid1}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
'jjmhw.cc': {
|
||||
_name: '漫小肆',
|
||||
www: [
|
||||
|
|
|
|||
|
|
@ -3022,9 +3022,6 @@ router.get('/touhougarakuta/:language/:type', lazyloadRouteHandler('./routes/tou
|
|||
// 猎趣TV
|
||||
router.get('/liequtv/room/:id', lazyloadRouteHandler('./routes/liequtv/room'));
|
||||
|
||||
// Behance
|
||||
router.get('/behance/:user/:type?', lazyloadRouteHandler('./routes/behance/index'));
|
||||
|
||||
// 北京物资学院
|
||||
router.get('/bwu/news', lazyloadRouteHandler('./routes/universities/bwu/news'));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const dayjs = require('dayjs');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const user = ctx.params.user || '';
|
||||
const type = ctx.params.type || 'projects';
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.behance.net/${user}/${type}`, // 接口只获取12个项目
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
});
|
||||
const data = response.data;
|
||||
const list = data.profile.activeSection.work.projects;
|
||||
const articledata = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
if (type !== 'projects') {
|
||||
item = item.project;
|
||||
}
|
||||
const url = `${item.url}?ilo0=1`;
|
||||
const cache = await ctx.cache.get(url);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const response2 = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const articleHtml = response2.data;
|
||||
const $2 = cheerio.load(articleHtml);
|
||||
|
||||
const content = $2('div.project-styles').html();
|
||||
const single = {
|
||||
content,
|
||||
};
|
||||
ctx.cache.set(url, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `${data.profile.owner.first_name} ${data.profile.owner.last_name}'s Work`,
|
||||
link: data.profile.owner.url,
|
||||
item: list.map((item, index) => {
|
||||
if (type !== 'projects') {
|
||||
item = item.project;
|
||||
}
|
||||
return {
|
||||
title: item.name,
|
||||
description: articledata[index].content,
|
||||
link: item.url,
|
||||
pubDate: dayjs.unix(item.published_on).format(),
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:user/:type?': ['MisteryMonster'],
|
||||
};
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
module.exports = {
|
||||
'behance.net': {
|
||||
_name: 'Behance',
|
||||
www: [
|
||||
{
|
||||
title: 'User',
|
||||
docs: 'https://docs.rsshub.app/design.html#behance-yong-hu-zuo-pin',
|
||||
source: ['/:user', '/:user/:types', '/gallery/:galleryid/:galleryname'],
|
||||
target: (params, url, document) => {
|
||||
let uid;
|
||||
let type = '';
|
||||
if (params.types && params.types.match('appreciated')) {
|
||||
type = '/appreciated';
|
||||
}
|
||||
if (url.match(/gallery\/\d+/)) {
|
||||
uid = document && document.querySelector('.e2e-project-avatar').childNodes[0].attributes[1].value.match(/behance.net\/(.*)/)[1];
|
||||
} else {
|
||||
uid = document && document.querySelector('html').innerHTML.match(/([^/]+)\/insights/)[1];
|
||||
}
|
||||
|
||||
return `/behance/${uid}${type}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/:user/:type?', require('./user'));
|
||||
};
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const user = ctx.params.user ?? '';
|
||||
const type = ctx.params.type ?? 'projects';
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.behance.net/${user}/${type}`, // 接口只获取12个项目
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
});
|
||||
const data = response.data;
|
||||
let list;
|
||||
if (type === 'projects') {
|
||||
list = data.profile.activeSection.work.projects.slice(0, 12);
|
||||
}
|
||||
if (type === 'appreciated') {
|
||||
list = data.profile.activeSection.appreciations.appreciations.slice(0, 12);
|
||||
}
|
||||
const articledata = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
if (type === 'appreciated') {
|
||||
item = item.project;
|
||||
}
|
||||
const url = `${item.url}?ilo0=1`;
|
||||
const description = await ctx.cache.tryGet(url, async () => {
|
||||
const response2 = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const articleHtml = response2.data;
|
||||
const $2 = cheerio.load(articleHtml);
|
||||
$2('.ImageElement-root-kir').remove();
|
||||
$2('.embed-dimensions').remove();
|
||||
$2('script.js-lightbox-slide-content').each((_, elem) => {
|
||||
elem = $2(elem);
|
||||
elem.replaceWith(elem.html());
|
||||
});
|
||||
const content = $2('div.project-styles').html();
|
||||
const single = {
|
||||
content,
|
||||
};
|
||||
return single;
|
||||
});
|
||||
return description;
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `${data.profile.owner.first_name} ${data.profile.owner.last_name}'s ${type}`,
|
||||
link: data.profile.owner.url,
|
||||
item: list.map((item, index) => {
|
||||
if (type === 'appreciated') {
|
||||
item = item.project;
|
||||
}
|
||||
return {
|
||||
title: item.name,
|
||||
description: articledata[index].content,
|
||||
link: item.url,
|
||||
pubDate: parseDate(item.published_on * 1000),
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue