diff --git a/lib/v2/imiker/jinghua.js b/lib/v2/imiker/jinghua.js new file mode 100644 index 00000000000000..5f431e920626a9 --- /dev/null +++ b/lib/v2/imiker/jinghua.js @@ -0,0 +1,87 @@ +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 limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 50; + + const rootUrl = 'https://ask.imiker.com'; + const apiUrl = new URL('explore/main/list/', rootUrl).href; + const currentUrl = new URL(``, rootUrl).href; + + const { data: response } = await got(apiUrl, { + searchParams: { + page: 1, + page_size: limit, + type: 'jinghua', + types: 'json', + }, + }); + + let items = response.slice(0, limit).map((item) => ({ + title: item.question_content, + link: new URL(`question/${item.id}`, rootUrl).href, + description: art(path.join(__dirname, 'templates/description.art'), { + headImage: item.headimage, + author: item.nick_name, + question: item.question_detail, + }), + author: item.nick_name, + guid: `imiker-${item.id}`, + pubDate: parseDate(item.add_time_timestamp * 1000), + upvotes: item.count?.vote_count ?? 0, + comments: item.count?.answer_count ?? 0, + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + content('h5.img-for-lazyload').each((_, e) => { + const image = content(e).find('img'); + + content(e).replaceWith( + art(path.join(__dirname, 'templates/description.art'), { + image: { + src: image.prop('data-original'), + alt: image.prop('alt'), + width: image.prop('data-width'), + height: image.prop('data-height'), + }, + }) + ); + }); + + item.title = content('div.title h1').text(); + item.description += art(path.join(__dirname, 'templates/description.art'), { + description: content('div#warp').html(), + }); + item.author = content('div.name').text(); + + return item; + }) + ) + ); + + const author = '米课圈'; + const description = '精华'; + const icon = new URL('favicon.ico', rootUrl).href; + + ctx.state.data = { + item: items, + title: `${author} - ${description}`, + link: currentUrl, + description, + language: 'zh', + icon, + logo: icon, + subtitle: description, + author, + allowEmpty: true, + }; +}; diff --git a/lib/v2/imiker/maintainer.js b/lib/v2/imiker/maintainer.js new file mode 100644 index 00000000000000..a6d26a348d136a --- /dev/null +++ b/lib/v2/imiker/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/ask/jinghua': ['nczitzk'], +}; diff --git a/lib/v2/imiker/radar.js b/lib/v2/imiker/radar.js new file mode 100644 index 00000000000000..d817a01d96975a --- /dev/null +++ b/lib/v2/imiker/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'imiker.com': { + _name: '米课', + '.': [ + { + title: '米课圈精华', + docs: 'https://docs.rsshub.app/routes/new-media#mi-ke-mi-ke-quan-jing-hua', + source: ['/explore/find'], + target: '/imiker/ask/jinghua', + }, + ], + }, +}; diff --git a/lib/v2/imiker/router.js b/lib/v2/imiker/router.js new file mode 100644 index 00000000000000..c938cd7756a87c --- /dev/null +++ b/lib/v2/imiker/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/ask/jinghua', require('./jinghua')); +}; diff --git a/lib/v2/imiker/templates/description.art b/lib/v2/imiker/templates/description.art new file mode 100644 index 00000000000000..97303d008510ac --- /dev/null +++ b/lib/v2/imiker/templates/description.art @@ -0,0 +1,32 @@ +{{ if image?.src }} + <figure> + <img + {{ if image.alt }} + alt="{{ image.alt }}" + {{ /if }} + {{ if image.width }} + alt="{{ image.width }}" + {{ /if }} + {{ if image.height }} + alt="{{ image.height }}" + {{ /if }} + src="{{ image.src }}"> + </figure> +{{ /if }} + +{{ if headImage }} + <figure> + <img src="{{ headImage }}"> + {{ if author }} + <figcaption>{{ author }}</figcaption> + {{ /if }} + </figure> +{{ /if }} + +{{ if question }} + <blockquote>{{ question }}</blockquote> +{{ /if }} + +{{ if description }} + {{@ description }} +{{ /if }} \ No newline at end of file diff --git a/website/docs/routes/new-media.mdx b/website/docs/routes/new-media.mdx index 1e6265b656f4a9..ea4d517fc4f699 100644 --- a/website/docs/routes/new-media.mdx +++ b/website/docs/routes/new-media.mdx @@ -4815,6 +4815,12 @@ column 为 third 时可选的 category: </Route> +## 米课 {#mi-ke} + +### 米课圈精华 {#mi-ke-mi-ke-quan-jing-hua} + +<Route author="nczitzk" example="/imiker/ask/jinghua" path="/imiker/ask/jinghua" radar="1"/> + ## 摩点 {#mo-dian} ### 众筹 {#mo-dian-zhong-chou}