feat: add mathpix blog (#6236)
This commit is contained in:
parent
7c388e6aa2
commit
f02a8515f3
|
|
@ -160,6 +160,10 @@ pageClass: routes
|
|||
|
||||
<Route author="nczitzk" example="/manictime/releases" path="/manictime/releases"/>
|
||||
|
||||
## Mathpix
|
||||
|
||||
<Route author="nczitzk" example="/mathpix/blog" path="/mathpix/blog"/>
|
||||
|
||||
## Microsoft Edge
|
||||
|
||||
### 外接程序更新
|
||||
|
|
|
|||
|
|
@ -3512,6 +3512,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
|
|||
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
|
||||
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
|
||||
|
||||
// Mathpix
|
||||
router.get('/mathpix/blog', require('./routes/mathpix/blog'));
|
||||
|
||||
// OneNote Gem Add-Ins
|
||||
router.get('/onenotegem/release', require('./routes/onenotegem/release'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://mathpix.com';
|
||||
const currentUrl = `${rootUrl}/blog`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.articles__text-content a')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
pubDate: new Date(item.parent().find('.articles__date').text()).toUTCString(),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
const titleImage = content('.article__image-area img');
|
||||
titleImage.attr('src', `${rootUrl}${titleImage.attr('srcset')}`);
|
||||
titleImage.removeAttr('srcset');
|
||||
|
||||
item.author = content('.article__titles-wrapper summary').text().replace('By ', '');
|
||||
item.description = content('.article__image-area').html() + content('.article__content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Mathpix Blog',
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue