diff --git a/lib/routes/591/list.ts b/lib/routes/591/list.ts index 5b3502ba9..375e846c2 100644 --- a/lib/routes/591/list.ts +++ b/lib/routes/591/list.ts @@ -157,14 +157,14 @@ async function handler(ctx) { }; }); + ctx.set('json', { + houses, + }); + return { title: '591 租屋 - 自訂查詢', link: queryUrl, description: `591 租屋 - 自訂查詢, query: ${query}`, item: items, }; - - ctx.set('json', { - houses, - }); } diff --git a/lib/routes/apple/apps.ts b/lib/routes/apple/apps.ts index 425c50e68..303cb7d95 100644 --- a/lib/routes/apple/apps.ts +++ b/lib/routes/apple/apps.ts @@ -117,6 +117,10 @@ async function handler(ctx) { const icon = new URL('favicon.ico', rootUrl).href; + ctx.set('json', { + appData, + }); + return { item: items, title: `${title} - Apple App Stroe`, @@ -130,8 +134,4 @@ async function handler(ctx) { author: artistName, allowEmpty: true, }; - - ctx.set('json', { - appData, - }); } diff --git a/lib/routes/bsky/posts.ts b/lib/routes/bsky/posts.ts index f6ada0707..a5a9540c2 100644 --- a/lib/routes/bsky/posts.ts +++ b/lib/routes/bsky/posts.ts @@ -52,6 +52,12 @@ async function handler(ctx) { comments: post.replyCount, })); + ctx.set('json', { + DID, + profile, + authorFeed, + }); + return { title: `${profile.displayName} (@${profile.handle}) — Bluesky`, description: profile.description?.replaceAll('\n', ' '), @@ -61,10 +67,4 @@ async function handler(ctx) { logo: profile.avatar, item: items, }; - - ctx.set('json', { - DID, - profile, - authorFeed, - }); } diff --git a/lib/routes/cebbank/all.ts b/lib/routes/cebbank/all.ts index d18477697..0f1fe3d1f 100644 --- a/lib/routes/cebbank/all.ts +++ b/lib/routes/cebbank/all.ts @@ -63,7 +63,7 @@ async function handler(ctx) { }) .get(); - return { + const ret = { title: '中国光大银行', description: '中国光大银行 外汇牌价', link, @@ -71,9 +71,8 @@ async function handler(ctx) { }; ctx.set('json', { - title: '中国光大银行', - description: '中国光大银行 外汇牌价', + ...ret, pubDate: timezone(parseDate($('#t_id span').text().substring(5), 'YYYY-MM-DD HH:mm', true), 0), - item: items, }); + return ret; } diff --git a/lib/routes/cebbank/history.ts b/lib/routes/cebbank/history.ts index 7b1d8404d..352814f9a 100644 --- a/lib/routes/cebbank/history.ts +++ b/lib/routes/cebbank/history.ts @@ -65,16 +65,13 @@ async function handler(ctx) { }) .get(); items.pop(); - return { + + const ret = { title: '中国光大银行', description: `中国光大银行 外汇牌价 ${TYPE[type].name}`, link: `https://www.cebbank.com/site/ygzx/whpj/rmbwhpjlspj/index.html?currcode=${TYPE[type].id}`, item: items, }; - - ctx.set('json', { - title: '中国光大银行', - description: `中国光大银行 外汇牌价 ${TYPE[type].name}`, - item: items, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/cngal/entry.ts b/lib/routes/cngal/entry.ts index 71f7d1d1f..6e3181a77 100644 --- a/lib/routes/cngal/entry.ts +++ b/lib/routes/cngal/entry.ts @@ -38,6 +38,7 @@ async function handler(ctx) { const data = response.data; + ctx.set('json', response.data); return { title: `CnGal - ${data.name} 的动态`, link: `https://www.cngal.org/entries/index/${entryId}`, @@ -48,5 +49,4 @@ async function handler(ctx) { link: item.link, })), }; - ctx.set('json', response.data); } diff --git a/lib/routes/dahecube/index.ts b/lib/routes/dahecube/index.ts index b7e502c1a..1f3c7794e 100644 --- a/lib/routes/dahecube/index.ts +++ b/lib/routes/dahecube/index.ts @@ -72,7 +72,7 @@ async function handler(ctx) { ) ); - return { + const ret = { title: '大河财立方', link: parseUrl(type), description: `大河财立方 ${TYPE[type].name}`, @@ -80,10 +80,6 @@ async function handler(ctx) { item: items, }; - ctx.set('json', { - title: '大河财立方', - link: parseUrl(type), - description: `大河财立方 ${TYPE[type].name}`, - items, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/eprice/rss.ts b/lib/routes/eprice/rss.ts index 510eb66ca..8a540cb3a 100644 --- a/lib/routes/eprice/rss.ts +++ b/lib/routes/eprice/rss.ts @@ -108,7 +108,7 @@ async function handler(ctx) { ) ); - return { + const ret = { title: feed.title, link: feed.link, description: feed.description, @@ -117,12 +117,6 @@ async function handler(ctx) { language: feed.language, }; - ctx.set('json', { - title: feed.title, - link: feed.link, - description: feed.description, - item: items, - image: feed.image.url, - language: feed.language, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/gamer/hot.ts b/lib/routes/gamer/hot.ts index b01d5ca41..c129f2b3b 100644 --- a/lib/routes/gamer/hot.ts +++ b/lib/routes/gamer/hot.ts @@ -65,15 +65,12 @@ async function handler(ctx) { ) ); - return { + const ret = { title: $('title').text(), link: rootUrl, item: items, }; - ctx.set('json', { - title: $('title').text(), - link: rootUrl, - item: items, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/github/comments.ts b/lib/routes/github/comments.ts index 7abec77cc..28fc83c1e 100644 --- a/lib/routes/github/comments.ts +++ b/lib/routes/github/comments.ts @@ -95,18 +95,17 @@ async function allIssues(ctx, user, repo, limit, headers) { // used: Number.parseInt(response.headers['x-ratelimit-used']), // }; - ctx.set('json', { - title: `${user}/${repo}: Issue & Pull request comments`, - link: `${rootUrl}/${user}/${repo}`, - item: items, - // rateLimit, - }); - - return { + const ret = { title: `${user}/${repo}: Issue & Pull request comments`, link: `${rootUrl}/${user}/${repo}`, item: items, }; + + ctx.set('json', { + ...ret, + // rateLimit, + }); + return ret; } async function singleIssue(ctx, user, repo, number, limit, headers) { @@ -187,10 +186,14 @@ async function singleIssue(ctx, user, repo, number, limit, headers) { } } - ctx.set('json', { + const ret = { title: `${user}/${repo}: ${typeDict[type].title} #${number} - ${issue.title}`, link: issue.html_url, item: items, + }; + + ctx.set('json', { + ...ret, // rateLimit: { // limit: Number.parseInt(response.headers['x-ratelimit-limit']), // remaining: Number.parseInt(response.headers['x-ratelimit-remaining']), @@ -199,10 +202,5 @@ async function singleIssue(ctx, user, repo, number, limit, headers) { // used: Number.parseInt(response.headers['x-ratelimit-used']), // }, }); - - return { - title: `${user}/${repo}: ${typeDict[type].title} #${number} - ${issue.title}`, - link: issue.html_url, - item: items, - }; + return ret; } diff --git a/lib/routes/github/notifications.ts b/lib/routes/github/notifications.ts index 9668c410e..6c17eed7e 100644 --- a/lib/routes/github/notifications.ts +++ b/lib/routes/github/notifications.ts @@ -64,12 +64,6 @@ async function handler(ctx) { }; }); - return { - title: 'Github Notifications', - link: 'https://github.com/notifications', - item: items, - }; - ctx.set('json', { title: 'Github Notifications', item: notifications, @@ -81,4 +75,10 @@ async function handler(ctx) { used: Number.parseInt(response.headers['X-RateLimit-Used']), }, }); + + return { + title: 'Github Notifications', + link: 'https://github.com/notifications', + item: items, + }; } diff --git a/lib/routes/gitpod/blog.ts b/lib/routes/gitpod/blog.ts index 7f6984277..2adc7618b 100644 --- a/lib/routes/gitpod/blog.ts +++ b/lib/routes/gitpod/blog.ts @@ -71,7 +71,7 @@ async function handler(ctx) { ) ); - return { + const ret = { title: $('title').text(), link: rootUrl + '/blog', description: $('meta[name="description"]').attr('content'), @@ -79,11 +79,6 @@ async function handler(ctx) { item: items, }; - ctx.set('json', { - title: $('title').text(), - link: rootUrl + '/blog', - description: $('meta[name="description"]').attr('content'), - language: 'en-US', - item: items, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/hkej/index.ts b/lib/routes/hkej/index.ts index e4b23fccc..619b00172 100644 --- a/lib/routes/hkej/index.ts +++ b/lib/routes/hkej/index.ts @@ -167,7 +167,7 @@ async function handler(ctx) { ) ); - return { + const ret = { title: `信報網站 - ${cat.title} - 信報網站 hkej.com`, link: baseUrl + cat.link, description: `信報網站(www.hkej.com)即時新聞${cat.name},提供${cat.description}。`, @@ -176,11 +176,8 @@ async function handler(ctx) { }; ctx.set('json', { - title: `信報網站 - ${cat.title} - 信報網站 hkej.com`, - link: baseUrl + cat.link, - description: `信報網站(www.hkej.com)即時新聞${cat.name},提供${cat.description}。`, - item: items, - language: 'zh-hk', + ...ret, cookieJar, }); + return ret; } diff --git a/lib/routes/hket/index.ts b/lib/routes/hket/index.ts index d6b1724f9..42612bc52 100644 --- a/lib/routes/hket/index.ts +++ b/lib/routes/hket/index.ts @@ -208,7 +208,7 @@ async function handler(ctx) { ) ); - return { + const ret = { title: $('head meta[name=title]').attr('content').trim(), link: baseUrl + '/' + category, description: $('head meta[name=description]').attr('content').trim(), @@ -216,11 +216,6 @@ async function handler(ctx) { language: 'zh-hk', }; - ctx.set('json', { - title: $('head meta[name=title]').attr('content').trim(), - link: baseUrl + '/' + category, - description: $('head meta[name=description]').attr('content').trim(), - item: items, - language: 'zh-hk', - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/macupdate/app.ts b/lib/routes/macupdate/app.ts index 4e2e76060..7aa22dd6b 100644 --- a/lib/routes/macupdate/app.ts +++ b/lib/routes/macupdate/app.ts @@ -51,6 +51,10 @@ async function handler(ctx) { author: appData.developer.name, }; + ctx.set('json', { + pageProps: nextData.props.initialProps.pageProps, + }); + return { title: appData.title, description: appData.description, @@ -60,8 +64,4 @@ async function handler(ctx) { item: [item], language: 'en', }; - - ctx.set('json', { - pageProps: nextData.props.initialProps.pageProps, - }); } diff --git a/lib/routes/nature/siteindex.ts b/lib/routes/nature/siteindex.ts index 795ecd298..99ec1d809 100644 --- a/lib/routes/nature/siteindex.ts +++ b/lib/routes/nature/siteindex.ts @@ -57,12 +57,12 @@ async function handler(ctx) { ) ); + ctx.set('json', { + items, + }); return { title: 'Nature siteindex', link: response.url, item: items, }; - ctx.set('json', { - items, - }); } diff --git a/lib/routes/nintendo/eshop-us.ts b/lib/routes/nintendo/eshop-us.ts index 828fc4c4e..94fc1683d 100644 --- a/lib/routes/nintendo/eshop-us.ts +++ b/lib/routes/nintendo/eshop-us.ts @@ -35,6 +35,7 @@ async function handler(ctx) { }); const data = response.data.hits; + ctx.set('json', response.data); return { title: `Nintendo eShop(美服)新游戏`, link: `https://www.nintendo.com/store/games/`, @@ -45,5 +46,4 @@ async function handler(ctx) { link: `https://www.nintendo.com${item.url}`, })), }; - ctx.set('json', response.data); } diff --git a/lib/routes/otobanana/cast.ts b/lib/routes/otobanana/cast.ts index 85b3039e3..cd2b0c438 100644 --- a/lib/routes/otobanana/cast.ts +++ b/lib/routes/otobanana/cast.ts @@ -34,6 +34,11 @@ async function handler(ctx) { const casts = castData.results.map((item) => renderCast(item)); + ctx.set('json', { + userInfo, + castData, + }); + return { title: `${userInfo.name} (@${userInfo.username}) - 音声投稿 | OTOBANANA`, description: userInfo.bio.replaceAll('\n', ' '), @@ -46,9 +51,4 @@ async function handler(ctx) { itunes_author: userInfo.name, item: casts, }; - - ctx.set('json', { - userInfo, - castData, - }); } diff --git a/lib/routes/otobanana/livestream.ts b/lib/routes/otobanana/livestream.ts index 765eecf8a..f4c9c20c9 100644 --- a/lib/routes/otobanana/livestream.ts +++ b/lib/routes/otobanana/livestream.ts @@ -34,6 +34,11 @@ async function handler(ctx) { const casts = liveData.results.map((item) => renderLive(item)); + ctx.set('json', { + userInfo, + liveData, + }); + return { title: `${userInfo.name} (@${userInfo.username}) - ライブ配信 | OTOBANANA`, description: userInfo.bio.replaceAll('\n', ' '), @@ -46,9 +51,4 @@ async function handler(ctx) { itunes_author: userInfo.name, item: casts, }; - - ctx.set('json', { - userInfo, - liveData, - }); } diff --git a/lib/routes/otobanana/timeline.ts b/lib/routes/otobanana/timeline.ts index 6d711f355..59652ad7d 100644 --- a/lib/routes/otobanana/timeline.ts +++ b/lib/routes/otobanana/timeline.ts @@ -34,6 +34,11 @@ async function handler(ctx) { const posts = postData.results.map((item) => renderPost(item)); + ctx.set('json', { + userInfo, + postData, + }); + return { title: `${userInfo.name} (@${userInfo.username}) - タイムライン | OTOBANANA`, description: userInfo.bio.replaceAll('\n', ' '), @@ -46,9 +51,4 @@ async function handler(ctx) { itunes_author: userInfo.name, item: posts, }; - - ctx.set('json', { - userInfo, - postData, - }); } diff --git a/lib/routes/qbittorrent/news.ts b/lib/routes/qbittorrent/news.ts index 2e2b50f63..0659ccfc7 100644 --- a/lib/routes/qbittorrent/news.ts +++ b/lib/routes/qbittorrent/news.ts @@ -71,15 +71,12 @@ async function handler(ctx) { }; }); - return { + const ret = { title: 'qBittorrent News', link: `${baseUrl}/news.php`, item, }; - ctx.set('json', { - title: 'qBittorrent News', - link: `${baseUrl}/news.php`, - item, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/taptap/review.ts b/lib/routes/taptap/review.ts index e274c994b..f2caa46ec 100644 --- a/lib/routes/taptap/review.ts +++ b/lib/routes/taptap/review.ts @@ -154,17 +154,13 @@ async function handler(ctx) { const items = is_intl ? await fetchIntlItems(ctx.params) : await fetchMainlandItems(ctx.params); - return { + const ret = { title: `TapTap 评价 ${app_name} - ${(is_intl ? intlSortMap : sortMap)[order][lang]}排序`, link: `${getRootUrl(is_intl)}/app/${id}/review?${makeSortParam(is_intl, order)}`, image: app_img, item: items, }; - ctx.set('json', { - title: `TapTap 评价 ${app_name} - ${(is_intl ? intlSortMap : sortMap)[order][lang]}排序`, - link: `${getRootUrl(is_intl)}/app/${id}/review?${makeSortParam(is_intl, order)}`, - image: app_img, - item: items, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/taptap/topic.ts b/lib/routes/taptap/topic.ts index 5e9ca8e18..5df3417e7 100644 --- a/lib/routes/taptap/topic.ts +++ b/lib/routes/taptap/topic.ts @@ -99,7 +99,7 @@ async function handler(ctx) { }) ); - return { + const ret = { title: `${app_name} - ${typeMap[type][lang]} - TapTap 论坛`, link: `${getRootUrl(false)}/app/${appId}/topic?type=${type}&sort=${sort}`, image: app_img, @@ -107,12 +107,10 @@ async function handler(ctx) { }; ctx.set('json', { - title: `${app_name} - ${typeMap[type][lang]} - TapTap 论坛`, - link: `${getRootUrl(false)}/app/${appId}/topic?type=${type}&sort=${sort}`, - image: app_img, - item: out.filter((item) => item !== ''), + ...ret, appId, groupId, topics_list, }); + return ret; } diff --git a/lib/routes/threads/utils.ts b/lib/routes/threads/utils.ts index 5ef44395d..10dbcb911 100644 --- a/lib/routes/threads/utils.ts +++ b/lib/routes/threads/utils.ts @@ -27,8 +27,9 @@ const extractTokens = async (user, ctx) => { const userId = data.match(/{"user_id":"(\d+)"},/)?.[1]; - ctx.set('json', { lsd, userId }); - return { lsd, userId }; + const ret = { lsd, userId }; + ctx.set('json', ret); + return ret; }; const makeHeader = (user, lsd) => ({ diff --git a/lib/routes/timednews/news.ts b/lib/routes/timednews/news.ts index 405fa26d2..2ad750eb7 100644 --- a/lib/routes/timednews/news.ts +++ b/lib/routes/timednews/news.ts @@ -115,17 +115,13 @@ async function handler(ctx) { ) ); - return { + const ret = { title: '时刻新闻', link: url, description: `时刻新闻 ${PATH_LIST[type].name}`, item: items, }; - ctx.set('json', { - title: '时刻新闻', - link: url, - description: `时刻新闻 ${PATH_LIST[type].name}`, - item: items, - }); + ctx.set('json', ret); + return ret; } diff --git a/lib/routes/wechat/feeddd.ts b/lib/routes/wechat/feeddd.ts index 21b1b6e16..0f2692767 100644 --- a/lib/routes/wechat/feeddd.ts +++ b/lib/routes/wechat/feeddd.ts @@ -30,20 +30,14 @@ const handler = async (ctx) => { items = await Promise.all(items.map((item) => finishArticleItem(item))); - ctx.set('json', { - title: response.data.title, - link: response.data.feed_url, - image: 'https://mp.weixin.qq.com/favicon.ico', - description: response.data.title, - item: items, - }); - - return { + const ret = { title: response.data.title, link: response.data.feed_url, description: response.data.title, item: items, allowEmpty: true, }; + ctx.set('json', ret); + return ret; }; export default handler; diff --git a/lib/routes/youtube/subscriptions.ts b/lib/routes/youtube/subscriptions.ts index 0fec4e223..8932efe20 100644 --- a/lib/routes/youtube/subscriptions.ts +++ b/lib/routes/youtube/subscriptions.ts @@ -80,17 +80,16 @@ async function handler(ctx) { }; }); - return { + const ret = { title: 'Subscriptions - YouTube', description: 'YouTube Subscriptions', item: items, }; ctx.set('json', { - title: 'Subscriptions - YouTube', - description: 'YouTube Subscriptions', + ...ret, channelIds, playlistIds, - item: items, }); + return ret; }