diff --git a/docs/social-media.md b/docs/social-media.md index 5e5382719..aa2f05b20 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -270,6 +270,22 @@ pageClass: routes +## Lofter + +::: tip 提示 + +官方提供了用户主页 RSS: http://**:username**.lofter.com/rss + +::: + +### 话题(标签) + + + +| new | date | week | month | total | +| ---- | ---- | ---- | ----- | ----- | +| 最新 | 日榜 | 周榜 | 月榜 | 总榜 | + ## pixiv ### 用户收藏 diff --git a/lib/router.js b/lib/router.js index 0bd4e13e3..febf926a7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1754,4 +1754,7 @@ router.get('/taptap/topic/:id/:label?', require('./routes/taptap/topic')); router.get('/taptap/changelog/:id', require('./routes/taptap/changelog')); router.get('/taptap/review/:id/:order?', require('./routes/taptap/review')); +// lofter +router.get('/lofter/tag/:name/:type?', require('./routes/lofter/tag')); + module.exports = router; diff --git a/lib/routes/lofter/tag.js b/lib/routes/lofter/tag.js new file mode 100644 index 000000000..04866a1d5 --- /dev/null +++ b/lib/routes/lofter/tag.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const titles = { + date: '日榜', + week: '周榜', + month: '月榜', + total: '总榜', + new: '最新', +}; + +module.exports = async (ctx) => { + const name = ctx.params.name; + const type = ctx.params.type ? ctx.params.type : 'new'; + + const url = `http://www.lofter.com/tag/${encodeURIComponent(name)}/${type}/`; + + const response = await got.get(url); + const $ = cheerio.load(response.data); + + const list = $('.m-mlist > .mlistcnt') + .slice(1) + .toArray(); + + ctx.state.data = { + title: `lofter话题 - ${name} - ${titles[type]}`, + link: url, + item: list.map((item) => { + item = $(item); + + const author = item + .find('.w-who > .ptag') + .first() + .text() + .trim(); + + const images = item.find('img[data-origin]'); + for (let k = 0; k < images.length; k++) { + $(images[k]).replaceWith(``); + } + + item.find('.imgc[style]').removeAttr('style'); + + item.find('.js-digest').remove(); + + item.find('a:not([href])').each(function() { + $(this).replaceWith($(this).html()); + }); + + const title = item.find('.tit'); + + return { + title: title.length === 0 ? `${author}的图片` : title.text().trim(), + author: author, + description: item.find('.m-icnt.ctag > .cnt').html(), + link: item.find('a.isayc').attr('href'), + pubDate: new Date(item.find('a.isayc').attr('data-time') * 1), + }; + }), + }; +};