{{ ranking_value }}
+{{ /if }} + +
{{ title }}
+ +{{ if original_title }} +{{ original_title }}
+{{ /if }} + +{{ if rate }} +{{ rate }}
+{{ /if }} + +{{ if card_subtitle }} +{{ card_subtitle }}
+{{ /if }} + +{{ if description }} +{{ description }}
+{{ /if }} + +{{ if cover }} + +{{ /if }} diff --git a/lib/v2/gamebase/maintainer.js b/lib/v2/gamebase/maintainer.js new file mode 100644 index 00000000000000..aa6c6618a92d09 --- /dev/null +++ b/lib/v2/gamebase/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:type?/:category?': ['nczitzk'], +}; diff --git a/lib/v2/gamebase/news.js b/lib/v2/gamebase/news.js new file mode 100644 index 00000000000000..629d5e4c94acdf --- /dev/null +++ b/lib/v2/gamebase/news.js @@ -0,0 +1,74 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +const types = { + newslist: 'newsList', + r18list: 'newsPornList', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type ?? 'newslist'; + const category = ctx.params.category ?? 'all'; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20; + + const rootUrl = 'https://news.gamebase.com.tw'; + const currentUrl = `${rootUrl}/news/${type}?type=${category}`; + + const apiRootUrl = 'https://api.gamebase.com.tw'; + const apiUrl = `${apiRootUrl}/api/news/getNewsList`; + + const response = await got({ + method: 'post', + url: apiUrl, + json: { + GB_type: types[type], + category, + page: 1, + }, + }); + + const titleResponse = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(titleResponse.data); + + const items = await Promise.all( + response.data.return_msg.list.slice(0, limit).map((item) => + ctx.cache.tryGet(`gamebase:news:${type}:${category}:${item.news_no}`, async () => { + const i = {}; + + i.author = item.nickname; + i.title = item.news_title; + i.link = `${rootUrl}/news/detail/${item.news_no}`; + i.description = item.news_meta?.meta_des ?? ''; + i.pubDate = timezone(parseDate(item.post_time), +8); + i.category = [item.system]; + + if (i.description) { + return i; + } + + const detailResponse = await got({ + method: 'get', + url: i.link, + }); + + const description = detailResponse.data.match(/(\\u003C.*?)","/)[1].replace(/\\"/g, '"'); + + i.description = description.replace(/\\u[\dA-F]{4}/gi, (match) => String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16))); + + return i; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/gamebase/radar.js b/lib/v2/gamebase/radar.js new file mode 100644 index 00000000000000..17a8eff10614fa --- /dev/null +++ b/lib/v2/gamebase/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'gamebase.com.tw': { + _name: '遊戲基地 Gamebase', + news: [ + { + title: '新聞', + docs: 'https://docs.rsshub.app/game.html#gamebase-xin-wen', + source: ['/news/:type'], + target: (params, url) => `/gamebase/news/${params.type}/${new URL(url).searchParams.get('type')}`, + }, + ], + }, +}; diff --git a/lib/v2/gamebase/router.js b/lib/v2/gamebase/router.js new file mode 100644 index 00000000000000..8b0471905f12e5 --- /dev/null +++ b/lib/v2/gamebase/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news/:type?/:category?', require('./news')); +}; diff --git a/lib/v2/oshwhub/explore.js b/lib/v2/oshwhub/explore.js new file mode 100644 index 00000000000000..d82ec6b8f19328 --- /dev/null +++ b/lib/v2/oshwhub/explore.js @@ -0,0 +1,116 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const path = require('path'); +const { art } = require('@/utils/render'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const md = require('markdown-it')({ + html: true, + linkify: true, +}); + +const requestImages = (url, tryGet) => + tryGet(url, async () => { + const response = await got({ + method: 'get', + url, + }); + + const images = {}; + const boms = []; + + const imgData = response.data; + imgData?.result?.boards?.forEach((board) => { + const name = board.name; + if (images[name] === undefined) { + images[name] = []; + } + + board.schematic?.documents?.forEach((val) => { + if (val.thumb) { + images[name].push(val.thumb); + } + }); + + if (board.pcb_info?.thumb) { + images[name].push(board.pcb_info.thumb); + } + if (board.pcb_info?.boms?.boms) { + boms.push(...JSON.parse(board.pcb_info.boms.boms)); + } + }); + return { images, boms }; + }); + +module.exports = async (ctx) => { + const baseUrl = 'https://oshwhub.com'; + const sortType = ctx.params.sortType ?? 'updatedTime'; + + const url = `${baseUrl}/explore?projectSort=${sortType}`; + const response = await got({ + method: 'get', + url, + }); + + const html = response.data; + const $ = cheerio.load(html); + const title = $('title').text(); + const projects = $('a[class="project-link"]'); + + const items = await Promise.all( + projects.map((id, item) => { + const detailUrl = `${baseUrl}${item.attribs.href}`; + return ctx.cache.tryGet(detailUrl, async () => { + const response = await got({ + method: 'get', + url: detailUrl, + }); + + const html = response.data; + const $$ = cheerio.load(html); + const projectDetail = $$('div[class="projects-left-top"]'); + + const title = $$(projectDetail).find('span[class="title"]').text(); + const author = $$(projectDetail).find('div[class="member-items"] > ul > li > a > span').first().text().trim(); + const publishTime = $$(projectDetail).find('div[class="issue-time"] > span').text(); + const pubDate = timezone(parseDate(publishTime.trim().split('\n')[1].trim(), 'YYYY/MM/DD HH:mm:ss'), 0); + + const coverImg = $$(projectDetail).find('div[class="img-cover"] > img').attr('src').trim(); + const introduction = $$(projectDetail).find('p[class="introduction"]').text().trim(); + const content = $$(projectDetail).find('div[class*="html-content"]').attr('data-markdown'); + + // request images + const dataUuid = $$('div[class="projects-detail"]').attr()['data-uuid']; + const { images, boms } = await requestImages(`${baseUrl}/api/project/${dataUuid}/pro_images`, ctx.cache.tryGet); + + const description = art(path.join(__dirname, 'templates/description.art'), { + title, + author, + publishTime, + coverImg, + introduction, + content: md.render(content) || 'No Content', + images, + boms, + }); + + const single = { + title, + description, + pubDate, + link: detailUrl, + author, + }; + + return single; + }); + }) + ); + + ctx.state.data = { + title, + link: url, + description: title, + item: items, + }; +}; diff --git a/lib/v2/oshwhub/maintainer.js b/lib/v2/oshwhub/maintainer.js new file mode 100644 index 00000000000000..ff8668b06de44e --- /dev/null +++ b/lib/v2/oshwhub/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:sortType?': ['tylinux'], +}; diff --git a/lib/v2/oshwhub/radar.js b/lib/v2/oshwhub/radar.js new file mode 100644 index 00000000000000..5176c22e2fb67a --- /dev/null +++ b/lib/v2/oshwhub/radar.js @@ -0,0 +1,16 @@ +module.exports = { + 'oshwhub.com': { + _name: '立创开源硬件平台', + '.': [ + { + title: '开源广场', + docs: 'https://docs.rsshub.app/other.html#li-chuang-kai-yuan-ying-jian-ping-tai', + source: ['/explore'], + target: (_, url) => { + const sortType = new URL(url).searchParams.get('projectSort'); + return sortType ? `/oshwhub/${sortType}` : ''; + }, + }, + ], + }, +}; diff --git a/lib/v2/oshwhub/router.js b/lib/v2/oshwhub/router.js new file mode 100644 index 00000000000000..b112bc945e7f29 --- /dev/null +++ b/lib/v2/oshwhub/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:sortType?', require('./explore')); +}; diff --git a/lib/v2/oshwhub/templates/description.art b/lib/v2/oshwhub/templates/description.art new file mode 100644 index 00000000000000..cb6027fcaaa005 --- /dev/null +++ b/lib/v2/oshwhub/templates/description.art @@ -0,0 +1,58 @@ +No | +Quantity | +Device | +Designator | +Footprint | +Value | +Manufacturer Part | +Manufacturer | +Supplier Part | +Supplier | +
---|---|---|---|---|---|---|---|---|---|
{{$value.No}} | +{{$value.Quantity}} | +{{$value.Device}} | +{{$value.Designator}} | +{{$value.Footprint}} | +{{$value.Value}} | +{{$value['Manufacturer Part']}} | +{{$value.Manufacturer}} | +{{$value['Supplier Part']}} | +{{$value.Supplier}} | +