feat(route): add Sensor Tower Blog (#10519)
* feat(route): add Sensor Tower Blog * fix typo * fix: language property
This commit is contained in:
parent
1a9fc89ff7
commit
1c114759a9
|
|
@ -641,6 +641,18 @@ Compared to the official one, this feed:
|
|||
|
||||
<RouteEn author="nczitzk" example="/semiconductors/latest-news" path="/semiconductors/latest-news"/>
|
||||
|
||||
## Sensor Tower
|
||||
|
||||
### Blog
|
||||
|
||||
<RouteEn author="nczitzk" example="/sensortower/blog" path="/sensortower/blog/:language?" :paramsDesc="['Language, see below, English by default']">
|
||||
|
||||
| English | Chinese | Japanese | Korean |
|
||||
| ------- | ------- | -------- | ------ |
|
||||
| | zh-CN | ja | ko |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Simons Foundation
|
||||
|
||||
### Articles
|
||||
|
|
|
|||
|
|
@ -1170,6 +1170,18 @@ IPFS 网关有可能失效,那时候换成其他网关。
|
|||
|
||||
<Route author="nczitzk" example="/samsung/research/blog" path="/samsung/research/blog"/>
|
||||
|
||||
## Sensor Tower
|
||||
|
||||
### Blog
|
||||
|
||||
<Route author="nczitzk" example="/sensortower/blog" path="/sensortower/blog/:language?" :paramsDesc="['语言,见下表,默认为 English']">
|
||||
|
||||
| English | Chinese | Japanese | Korean |
|
||||
| ------- | ------- | -------- | ------ |
|
||||
| | zh-CN | ja | ko |
|
||||
|
||||
</Route>
|
||||
|
||||
## Simons Foundation
|
||||
|
||||
### 文章
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const language = ctx.params.language ?? '';
|
||||
|
||||
const rootUrl = 'https://sensortower.com';
|
||||
const currentUrl = `${rootUrl}${language ? `/${language}` : ''}/blog`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const data = response.data.match(/"uri":"(\/blog\/.*?)"/g);
|
||||
|
||||
let items = data.map((item) => ({
|
||||
link: `${rootUrl}${language ? `/${language}` : ''}${item.match(/"(\/blog\/.*?)"/)[1]}`,
|
||||
}));
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
const detail = JSON.parse(`{${detailResponse.data.match(/("title":.*?),"body":/)[1]}}`);
|
||||
|
||||
content('h1').remove();
|
||||
content('h5').parent().remove();
|
||||
content('div[data-testid="Text-embedded-entry-block"]').remove();
|
||||
|
||||
content('img').each(function () {
|
||||
const image = (content(this).attr('srcset') ?? content(this).attr('src')).split('?w=')[0];
|
||||
|
||||
content(this).replaceWith(
|
||||
art(path.join(__dirname, 'templates/description.art'), {
|
||||
image,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
item.title = detail.title;
|
||||
item.author = detail.author.name;
|
||||
item.pubDate = parseDate(detail.pubDate, 'MMMM YYYY');
|
||||
item.category = (detail.tags?.map((t) => t.title) ?? []).concat(detail.category?.map((c) => c.title) ?? []);
|
||||
item.description = art(path.join(__dirname, 'templates/description.art'), {
|
||||
header: content('header[data-csk-entry-type="blog"]').html(),
|
||||
description: content('div[data-csk-entry-type="blog"] div[data-testid="Text-root"]').html(),
|
||||
});
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Sensor Tower - Blog',
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
language: language ? language : 'en-US',
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/blog/:language?': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'sensortower.com': {
|
||||
_name: 'Sensor Tower',
|
||||
'.': [
|
||||
{
|
||||
title: 'Blog',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#sensor-tower-blog',
|
||||
source: ['/blog', '/zh-CN/blog', '/ja/blog', '/ko/blog', '/'],
|
||||
target: '/sensortower/blog',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/blog/:language?', require('./blog'));
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{{ if image }}
|
||||
<img src="{{ image }}">
|
||||
{{ /if }}
|
||||
{{ if header }}
|
||||
{{@ header }}
|
||||
{{ /if }}
|
||||
{{ if description }}
|
||||
{{@ description }}
|
||||
{{ /if }}
|
||||
Loading…
Reference in New Issue