fix(route): Mirror (#9933)
This commit is contained in:
parent
a5c9691de3
commit
196a951fe2
|
|
@ -459,7 +459,7 @@ Edition
|
|||
|
||||
### User
|
||||
|
||||
<RouteEn author="fifteen42 rde9" example="/mirror/tingfei.eth" path="/mirror/:id" :paramsDesc="['user id']" />
|
||||
<RouteEn author="fifteen42 rde9 nczitzk" example="/mirror/tingfei.eth" path="/mirror/:id" :paramsDesc="['user id']" />
|
||||
|
||||
## National Association of Colleges and Employers
|
||||
|
||||
|
|
|
|||
|
|
@ -848,7 +848,7 @@ IPFS 网关有可能失效,那时候换成其他网关。
|
|||
|
||||
### User
|
||||
|
||||
<Route author="fifteen42 rde9" example="/mirror/tingfei.eth" path="/mirror/:id" :paramsDesc="['user id']" />
|
||||
<Route author="fifteen42 rde9 nczitzk" example="/mirror/tingfei.eth" path="/mirror/:id" :paramsDesc="['user id']" />
|
||||
|
||||
## MIT 科技评论
|
||||
|
||||
|
|
|
|||
|
|
@ -4065,7 +4065,7 @@ router.get('/secrss/author/:author?', lazyloadRouteHandler('./routes/secrss/auth
|
|||
router.get('/fashionnetwork/headline/:country?', lazyloadRouteHandler('./routes/fashionnetwork/headline.js'));
|
||||
|
||||
// mirror.xyz
|
||||
router.get('/mirror/:id', lazyloadRouteHandler('./routes/mirror/entries'));
|
||||
// router.get('/mirror/:id', lazyloadRouteHandler('./routes/mirror/entries'));
|
||||
|
||||
// KBS migrated to v2
|
||||
// router.get('/kbs/today/:language?', lazyloadRouteHandler('./routes/kbs/today'));
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
let link;
|
||||
let subDomain = 0;
|
||||
if (id.endsWith('.eth') || id.length === 42 || id.length === 40) {
|
||||
link = 'https://mirror.xyz/' + id;
|
||||
} else {
|
||||
link = 'https://' + id + '.mirror.xyz';
|
||||
subDomain = 1;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
const data = response.body;
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const author = $('div#__next > div.GlobalNavigation > div.GlobalNavigationContainer > div > div > div > div > div > a').text();
|
||||
|
||||
// 标题
|
||||
const article = $('h1')
|
||||
.map(function () {
|
||||
return $(this).text();
|
||||
})
|
||||
.get();
|
||||
|
||||
// 地址
|
||||
const addr = $('h1')
|
||||
.parent()
|
||||
.parent()
|
||||
.parent()
|
||||
.map(function () {
|
||||
return $(this).attr('href');
|
||||
})
|
||||
.get();
|
||||
|
||||
// 发布日期
|
||||
const date = $('div#__next > div > div > div > div > div > div > div > div > div')
|
||||
.map(function () {
|
||||
return $(this).text();
|
||||
})
|
||||
.get();
|
||||
|
||||
// 摘要
|
||||
const des = $('h1')
|
||||
.parent()
|
||||
.parent()
|
||||
.parent()
|
||||
.parent()
|
||||
.next()
|
||||
.next()
|
||||
.map(function () {
|
||||
return $(this).text();
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = [];
|
||||
article.forEach((item, index) => {
|
||||
items.push({
|
||||
title: item,
|
||||
author,
|
||||
description: des[index],
|
||||
pubDate: date[index],
|
||||
link: subDomain ? link + addr[index] : 'https://mirror.xyz' + addr[index],
|
||||
});
|
||||
});
|
||||
|
||||
const title = author + ' - Mirror';
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link,
|
||||
allowEmpty: true,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const md = require('markdown-it')({
|
||||
html: true,
|
||||
linkify: true,
|
||||
});
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const rootUrl = 'https://mirror.xyz';
|
||||
const currentUrl = id.endsWith('.eth') ? `${rootUrl}/${id}` : `https://${id}.mirror.xyz`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const data = JSON.parse(response.data.match(/"__NEXT_DATA__" type="application\/json">({"props":.*})<\/script>/)[1]);
|
||||
|
||||
const items = data.props.pageProps.project.posts.map((item) => ({
|
||||
title: item.title,
|
||||
description: md.render(item.body),
|
||||
link: `${currentUrl}/${item._id}`,
|
||||
pubDate: parseDate(item.timestamp * 1000),
|
||||
author: item.publisher.project.displayName,
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data.props.pageProps.project.displayName} - Mirror`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/:id': ['fifteen42', 'rde9', 'nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
'mirror.xyz': {
|
||||
_name: 'Mirror',
|
||||
'.': [
|
||||
{
|
||||
title: 'User',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#mirror-user',
|
||||
source: ['/:id', '/'],
|
||||
target: (params, url) => {
|
||||
const matches = new URL(url).toString().match(/https:\/\/(.*?)\.mirror\.xyz/);
|
||||
const id = matches ? matches[1] : params.id;
|
||||
return `/mirror/${id}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:id', require('./index'));
|
||||
};
|
||||
Loading…
Reference in New Issue