feat(route): add 产品沉思录 (#9927)

This commit is contained in:
Ethan Shen 2022-06-09 18:29:38 +08:00 committed by GitHub
parent 8fef1e2190
commit 57e2a2401b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 0 deletions

View File

@ -1520,6 +1520,12 @@ Supported sub-sites:
<Route author="Fatpandac" example="/chaping/newsflash" path="/chaping/newsflash"/>
## 产品沉思录
### 首页
<Route author="nczitzk" example="/pmthinking" path="/pmthinking" />
## 城农 Growin' City
### 城农资讯观点

View File

@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const rootUrl = 'https://pmthinking.com';
const currentUrl = `${rootUrl}/wp-json/b2/v1/getModulePostList`;
const response = await got({
method: 'post',
url: currentUrl,
json: {
index: 2,
post_paged: 1,
},
});
const $ = cheerio.load(response.data.data);
let items = $('h2 a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
});
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);
item.author = content('.post-user-name').text();
item.pubDate = timezone(parseDate(content('time[itemprop="datePublished"]').attr('datetime')), +8);
item.description = art(path.join(__dirname, 'templates/description.art'), {
image: content('.post-style-4-top img').attr('src'),
description: content('.entry-content').html(),
});
return item;
})
)
);
ctx.state.data = {
title: '产品沉思录 · Product Thinking',
link: rootUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/': ['nczitzk'],
};

View File

@ -0,0 +1,13 @@
module.exports = {
'pmthinking.com': {
_name: '产品沉思录',
'.': [
{
title: '首页',
docs: 'https://docs.rsshub.app/new-media.html#chan-pin-chen-si-lu-shou-ye',
source: ['/'],
target: '/pmthinking',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/', require('./index'));
};

View File

@ -0,0 +1,4 @@
{{ if image }}
<img src="{{ image }}">
{{ /if }}
{{@ description }}