feat(route): 优化少数派系列路由每篇文章的封面图片,增加了每日必应路由两个控制参数 (#15859)
* Update index.ts * Update index.ts * sspai index image * update * update2 * update3 * update4 * --屎山代码😢 * Update lib/routes/bing/daily-wallpaper.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * 😉done😢 * 添加参数来控制输出中文或英文 * 😭添加参数来控制输出中文或英文😭 * remove some Unnecessary codes ---------
This commit is contained in:
@@ -4,38 +4,77 @@ import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/',
|
||||
path: '/:routeParams?',
|
||||
parameters: {
|
||||
routeParams: '额外参数type,story和lang:请参阅以下说明和表格',
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['cn.bing.com/'],
|
||||
source: ['www.bing.com/', 'cn.bing.com/'],
|
||||
target: '',
|
||||
},
|
||||
],
|
||||
name: '每日壁纸',
|
||||
maintainers: ['FHYunCai'],
|
||||
maintainers: ['FHYunCai', 'LLLLLFish'],
|
||||
handler,
|
||||
url: 'cn.bing.com/',
|
||||
url: 'www.bing.com/',
|
||||
example: '/bing/type=UHD&story=1&lang=zh-CN',
|
||||
description: `| 参数 | 含义 | 接受的值 | 默认值 | 备注 |
|
||||
|-------|--------------------|-----------------------------------------------------------|-----------|--------------------------------------------------------|
|
||||
| type | 输出壁纸的像素类型 | UHD/1920x1080/1920x1200/768x1366/1080x1920/1080x1920_logo | 1920x1080 | 1920x1200与1080x1920_logo带有水印,输入的值不在接受范围内都会输出成1920x1080 |
|
||||
| story | 是否输出壁纸的故事 | 1/0 | 0 | 输入的值不为1都不会输出故事 |
|
||||
| lang | 输出壁纸图文的地区(中文或者是英文) | zh/en | zh | zh/en输出的壁纸图文不一定是一样的;如果en不生效,试着部署到其他地方 |
|
||||
`,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const response = await ofetch('HPImageArchive.aspx', {
|
||||
baseURL: 'https://cn.bing.com',
|
||||
const routeParams = new URLSearchParams(ctx.req.param('routeParams'));
|
||||
let type = routeParams.get('type') || '1920x1080';
|
||||
let lang = routeParams.get('lang');
|
||||
let apiUrl = '';
|
||||
const allowedTypes = ['UHD', '1920x1080', '1920x1200', '768x1366', '1080x1920', '1080x1920_logo'];
|
||||
if (lang !== 'zh' && lang !== 'en') {
|
||||
lang = 'zh';
|
||||
}
|
||||
if (lang === 'zh') {
|
||||
lang = 'zh-CN';
|
||||
apiUrl = 'https://cn.bing.com';
|
||||
} else {
|
||||
lang = 'en-US';
|
||||
apiUrl = 'https://www.bing.com';
|
||||
}
|
||||
if (!allowedTypes.includes(type)) {
|
||||
type = '1920x1080';
|
||||
}
|
||||
const story = routeParams.get('story') === '1';
|
||||
const resp = await ofetch('/hp/api/model', {
|
||||
baseURL: apiUrl,
|
||||
method: 'GET',
|
||||
query: {
|
||||
format: 'js',
|
||||
idx: 0,
|
||||
n: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 7,
|
||||
mkt: 'zh-CN',
|
||||
mtk: lang,
|
||||
},
|
||||
});
|
||||
const data = response;
|
||||
const items = resp.MediaContents.map((item) => {
|
||||
const ssd = item.Ssd;
|
||||
const link = `${apiUrl}${item.ImageContent.Image.Url.match(/\/th\?id=[^_]+_[^_]+/)[0].replace(/(_\d+x\d+\.webp)$/i, '')}_${type}.jpg`;
|
||||
let description = `<img src="${link}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`;
|
||||
if (story) {
|
||||
description += `<b>${item.ImageContent.Headline}</b>`;
|
||||
description += `<i>${item.ImageContent.QuickFact.MainText}</i><br>`;
|
||||
description += `<p>${item.ImageContent.Description}<p>`;
|
||||
}
|
||||
return {
|
||||
title: item.ImageContent.Title,
|
||||
description,
|
||||
link: `${apiUrl}${item.ImageContent.BackstageUrl}`,
|
||||
author: item.ImageContent.Copyright,
|
||||
pubDate: timezone(parseDate(ssd, 'YYYYMMDD_HHmm'), 0),
|
||||
};
|
||||
});
|
||||
return {
|
||||
title: 'Bing每日壁纸',
|
||||
link: 'https://cn.bing.com/',
|
||||
item: data.images.map((item) => ({
|
||||
title: item.copyright,
|
||||
description: `<img src="https://cn.bing.com${item.url}">`,
|
||||
link: item.copyrightlink,
|
||||
pubDate: timezone(parseDate(item.fullstartdate), 0),
|
||||
})),
|
||||
link: apiUrl,
|
||||
description: 'Bing每日壁纸',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -61,7 +61,13 @@ async function handler(ctx) {
|
||||
const key = `sspai: ${item.id}`;
|
||||
return cache.tryGet(key, async () => {
|
||||
const response = await got(link);
|
||||
description = response.data.data.body;
|
||||
// description = response.data.data.body;
|
||||
const articleData = response.data.data;
|
||||
const banner = articleData.promote_image;
|
||||
if (banner) {
|
||||
description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`;
|
||||
}
|
||||
description += articleData.body;
|
||||
|
||||
return {
|
||||
title: item.title.trim(),
|
||||
|
||||
@@ -42,10 +42,7 @@ async function handler() {
|
||||
return cache.tryGet(key, async () => {
|
||||
const response = await got({ method: 'get', url: link });
|
||||
const articleData = response.data.data;
|
||||
let banner = articleData.banner;
|
||||
if (articleData.keywords.includes('派早报')) {
|
||||
banner = `https://cdnfile.sspai.com/${banner}`;
|
||||
}
|
||||
const banner = articleData.promote_image;
|
||||
if (banner) {
|
||||
description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,13 @@ async function handler() {
|
||||
const key = `sspai: ${item.id}`;
|
||||
return cache.tryGet(key, async () => {
|
||||
const response = await got(link);
|
||||
description = response.data.data.body;
|
||||
// description = response.data.data.body;
|
||||
const articleData = response.data.data;
|
||||
const banner = articleData.promote_image;
|
||||
if (banner) {
|
||||
description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`;
|
||||
}
|
||||
description += articleData.body;
|
||||
|
||||
return {
|
||||
title: item.title.trim(),
|
||||
|
||||
@@ -46,7 +46,13 @@ async function handler(ctx) {
|
||||
const key = `sspai: ${item.id}`;
|
||||
return cache.tryGet(key, async () => {
|
||||
const response = await got({ method: 'get', url: link, headers: { Referer: host } });
|
||||
description = response.data.data.body;
|
||||
// description = response.data.data.body;
|
||||
const articleData = response.data.data;
|
||||
const banner = articleData.promote_image;
|
||||
if (banner) {
|
||||
description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`;
|
||||
}
|
||||
description += articleData.body;
|
||||
|
||||
return {
|
||||
title: item.title.trim(),
|
||||
|
||||
@@ -52,7 +52,13 @@ async function handler(ctx) {
|
||||
}
|
||||
return cache.tryGet(`sspai: ${item.id}`, async () => {
|
||||
const response = await got(link);
|
||||
const description = response.data.data.body;
|
||||
let description = '';
|
||||
const articleData = response.data.data;
|
||||
const banner = articleData.promote_image;
|
||||
if (banner) {
|
||||
description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`;
|
||||
}
|
||||
description += articleData.body;
|
||||
|
||||
const single = {
|
||||
title,
|
||||
|
||||
@@ -42,7 +42,7 @@ async function handler() {
|
||||
|
||||
const key = `sspai:topics:${item.id}`;
|
||||
return cache.tryGet(key, () => {
|
||||
description = `${item.intro}<br><img src="https://cdn.sspai.com/${item.banner}" /><br>如有兴趣,请复制链接订阅 <br> <h3>https://rsshub.app/sspai/topic/${item.id}</h3>`;
|
||||
description = `<br><img src="https://cdnfile.sspai.com/${item.banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"/>${item.intro}<br>如有兴趣,请复制链接订阅 <br> <h3>https://rsshub.app/sspai/topic/${item.id}</h3>`;
|
||||
|
||||
return {
|
||||
title: item.title.trim(),
|
||||
|
||||
Reference in New Issue
Block a user