diff --git a/docs/new-media.md b/docs/new-media.md index ccb3173e2..7d4a8169e 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1520,6 +1520,12 @@ Supported sub-sites: +## 产品沉思录 + +### 首页 + + + ## 城农 Growin' City ### 城农资讯观点 diff --git a/lib/v2/pmthinking/index.js b/lib/v2/pmthinking/index.js new file mode 100644 index 000000000..1334aedf6 --- /dev/null +++ b/lib/v2/pmthinking/index.js @@ -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, + }; +}; diff --git a/lib/v2/pmthinking/maintainer.js b/lib/v2/pmthinking/maintainer.js new file mode 100644 index 000000000..ca7cf1eb1 --- /dev/null +++ b/lib/v2/pmthinking/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/': ['nczitzk'], +}; diff --git a/lib/v2/pmthinking/radar.js b/lib/v2/pmthinking/radar.js new file mode 100644 index 000000000..c3f78733c --- /dev/null +++ b/lib/v2/pmthinking/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/pmthinking/router.js b/lib/v2/pmthinking/router.js new file mode 100644 index 000000000..20c52b09d --- /dev/null +++ b/lib/v2/pmthinking/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/', require('./index')); +}; diff --git a/lib/v2/pmthinking/templates/description.art b/lib/v2/pmthinking/templates/description.art new file mode 100644 index 000000000..c823516c9 --- /dev/null +++ b/lib/v2/pmthinking/templates/description.art @@ -0,0 +1,4 @@ +{{ if image }} + +{{ /if }} +{{@ description }} \ No newline at end of file