diff --git a/docs/en/social-media.md b/docs/en/social-media.md index bb3a950049..6e5de9c1b1 100644 --- a/docs/en/social-media.md +++ b/docs/en/social-media.md @@ -136,7 +136,13 @@ If you don't want to setup credentials, use Picuki. ### Tag - + + +| new | date | week | month | total | +| ---- | ---- | ---- | ----- | ----- | +| 最新 | 日榜 | 周榜 | 月榜 | 总榜 | + + ## Mastodon diff --git a/docs/social-media.md b/docs/social-media.md index 51df866d87..c1dd5159cf 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -458,12 +458,14 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 ### 话题 (标签) - + | new | date | week | month | total | | ---- | ---- | ---- | ----- | ----- | | 最新 | 日榜 | 周榜 | 月榜 | 总榜 | + + ## Mastodon ::: tip 提示 diff --git a/lib/router.js b/lib/router.js index 92f696a65d..a71c11b7ef 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2246,7 +2246,7 @@ router.get('/taptap/changelog/:id', lazyloadRouteHandler('./routes/taptap/change router.get('/taptap/review/:id/:order?', lazyloadRouteHandler('./routes/taptap/review')); // lofter -router.get('/lofter/tag/:name/:type?', lazyloadRouteHandler('./routes/lofter/tag')); +router.get('/lofter/tag/:name?/:type?', lazyloadRouteHandler('./routes/lofter/tag')); router.get('/lofter/user/:username', lazyloadRouteHandler('./routes/lofter/posts')); // 米坛社区表盘 diff --git a/lib/routes/lofter/tag.js b/lib/routes/lofter/tag.js index 0f8080f30a..88f2e7182c 100644 --- a/lib/routes/lofter/tag.js +++ b/lib/routes/lofter/tag.js @@ -1,55 +1,59 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); - -const titles = { - date: '日榜', - week: '周榜', - month: '月榜', - total: '总榜', - new: '最新', -}; +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { - const name = ctx.params.name; - const type = ctx.params.type ? ctx.params.type : 'new'; + const name = ctx.params.name || '摄影'; + const type = ctx.params.type || 'new'; - const url = `http://www.lofter.com/tag/${encodeURIComponent(name)}/${type}/`; + const rootUrl = 'http://www.lofter.com'; + const currentUrl = `${rootUrl}/tag/${name}/${type}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); - const response = await got.get(url); const $ = cheerio.load(response.data); - const list = $('.m-mlist > .mlistcnt').slice(1).toArray(); + $('.js-digest').remove(); - ctx.state.data = { - title: `lofter话题 - ${name} - ${titles[type]}`, - link: url, - item: list.map((item) => { + let title = $('a.j-crt').text(); + title = title === '最热' ? $('.select-recomm-type').text() : title; + + const items = $('div[data-blogid]') + .map((_, item) => { item = $(item); - const author = item.find('.w-who > .ptag').first().text().trim(); + const videos = item + .find('.js-video') + .toArray() + .reduce((accumulator, currentValue) => accumulator + ``, ''); - const images = item.find('img[data-origin]'); - for (let k = 0; k < images.length; k++) { - $(images[k]).replaceWith(``); - } + const images = item + .find('.imgc img') + .toArray() + .reduce((accumulator, currentValue) => accumulator + ``, ''); - 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'); + const description = item.find('.js-content.ptag'); return { - title: title.length === 0 ? `${author}的图片` : title.text().trim(), - 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), + author: item.attr('data-blognickname'), + link: item.find('.isayc').attr('href'), + title: item.find('.tit').text() || `${item.find('.w-who .ptag').text()}${description.text() ? `:${description.text()}` : ''}`, + pubDate: parseDate(item.find('.isayc').attr('data-time') * 1), + description: videos + images + description.html(), + category: item + .find('.opta .opti') + .toArray() + .map((item) => $(item).text()), }; - }), + }) + .get(); + + ctx.state.data = { + title: `${name} - ${title}|LOFTER`, + link: currentUrl, + item: items, }; };