diff --git a/docs/bbs.md b/docs/bbs.md index 129170152..46cae0b35 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -4,6 +4,30 @@ pageClass: routes # 论坛 +## 19 楼 + +### 头条 + + + +| 杭州 | 台州 | 嘉兴 | 宁波 | 湖州 | +| --- | ------- | ------- | ------ | ------ | +| www | taizhou | jiaxing | ningbo | huzhou | + +| 绍兴 | 湖州 | 温州 | 金华 | 舟山 | +| -------- | ------ | ------- | ------ | -------- | +| shaoxing | huzhou | wenzhou | jinhua | zhoushan | + +| 衢州 | 丽水 | 义乌 | 萧山 | 余杭 | +| ------ | ------ | ---- | -------- | ------ | +| quzhou | lishui | yiwu | xiaoshan | yuhang | + +| 临安 | 富阳 | 桐庐 | 建德 | 淳安 | +| ----- | ------ | ------ | ------ | ------ | +| linan | fuyang | tonglu | jiande | chunan | + + + ## 2047 ### 分类 diff --git a/lib/v2/19lou/index.js b/lib/v2/19lou/index.js new file mode 100644 index 000000000..d8e89c6a5 --- /dev/null +++ b/lib/v2/19lou/index.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 iconv = require('iconv-lite'); + +const setCookie = function (cookieName, cookieValue, seconds, path, domain, secure) { + let expires = null; + if (seconds !== -1) { + expires = new Date(); + expires.setTime(expires.getTime() + seconds); + } + return [encodeURI(cookieName), '=', encodeURI(cookieValue), expires ? '; expires=' + expires.toGMTString() : '', path ? '; path=' + path : '/', domain ? '; domain=' + domain : '', secure ? '; secure' : ''].join(''); +}; + +module.exports = async (ctx) => { + const city = ctx.params.city ?? 'www'; + + const rootUrl = `https://${city}.19lou.com`; + + const response = await got({ + method: 'get', + url: rootUrl, + responseType: 'buffer', + }); + + const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + + $('.title-more').remove(); + + let items = $('.center-center-jiazi') + .find('a[title]') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.attr('title'), + link: `https:${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, + responseType: 'buffer', + headers: { + cookie: setCookie('_Z3nY0d4C_', '37XgPK9h', 365, '/', '19lou.com'), + referer: rootUrl, + }, + }); + + const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + + content('.name-lz, .postView-pk-mod').remove(); + + item.author = content('.uname, .user-name').first().text(); + item.description = content('.post-cont').first().html() || content('.thread-cont').html(); + item.pubDate = timezone(parseDate(content('.cont-top-left meta').first().attr('content')), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text().split('-')[0], + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/19lou/maintainer.js b/lib/v2/19lou/maintainer.js new file mode 100644 index 000000000..3e64e483c --- /dev/null +++ b/lib/v2/19lou/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:city?': ['nczitzk'], +}; diff --git a/lib/v2/19lou/radar.js b/lib/v2/19lou/radar.js new file mode 100644 index 000000000..fa9363a66 --- /dev/null +++ b/lib/v2/19lou/radar.js @@ -0,0 +1,29 @@ +module.exports = { + '19lou.com': { + _name: '19 楼', + '.': [ + { + title: '头条', + docs: 'https://docs.rsshub.app/bbs.html#19-lou-tou-tiao', + source: ['/'], + target: (params, url) => `/19lou/${new URL(url).toString().match(/\/\/(.*?)\.19lou/)[1]}`, + }, + ], + www: [ + { + title: '头条', + docs: 'https://docs.rsshub.app/bbs.html#19-lou-tou-tiao', + source: ['/'], + target: '/19lou/www', + }, + ], + jiaxing: [ + { + title: '头条', + docs: 'https://docs.rsshub.app/bbs.html#19-lou-tou-tiao', + source: ['/'], + target: '/19lou/jiaxing', + }, + ], + }, +}; diff --git a/lib/v2/19lou/router.js b/lib/v2/19lou/router.js new file mode 100644 index 000000000..3b023b188 --- /dev/null +++ b/lib/v2/19lou/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:city?', require('./index')); +};