refactor: fix all get to toArray (#19000)

* refactor: fix all get

* fix(utils/common-config): charset case compare

* Revert "fix(utils/common-config): charset case compare"

This reverts commit 3c1880f2fa.

* fix: nga

* fix: notateslaapp

* fix: ps

* fix: xjtu

* fix: enforce error on restricted syntax for get calls

* fix: eslint

* fix: more eslint
This commit is contained in:
Tony
2025-05-04 05:24:53 +08:00
committed by GitHub
parent 6bbf2f0289
commit a5e2e295dc
363 changed files with 2598 additions and 2870 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ unicorn.configs.recommended,
'no-new-func': 'error',
'no-restricted-imports': 'error',
'no-restricted-syntax': ['warn', {
'no-restricted-syntax': ['error', {
selector: "CallExpression[callee.property.name='get'][arguments.length=0]",
message: "Please use .toArray() instead.",
}, {
+3 -3
View File
@@ -29,7 +29,8 @@ async function handler(ctx) {
const $ = load(iconv.decode(response.data, 'gbk'));
const list = $('tbody[id^="normalthread_"]')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const xst = item.find('a.s.xst');
const author = item.find('td.by cite a').eq(0).text();
@@ -38,8 +39,7 @@ async function handler(ctx) {
link: xst.attr('href'),
author,
};
})
.get();
});
// console.log(list);
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -54,15 +54,15 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('post-title a')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+1 -1
View File
@@ -36,7 +36,7 @@ async function handler(ctx) {
const $ = load(data);
const title = $('title').text();
const description = $('.signature .complete').text();
const list = $('#ac-space-video-list a').get();
const list = $('#ac-space-video-list a').toArray();
const image = $('head style')
.text()
.match(/.user-photo{\n\s*background:url\((.*)\) 0% 0% \/ 100% no-repeat;/)[1];
+3 -3
View File
@@ -42,7 +42,8 @@ async function handler() {
const list = $('#wp_news_w9')
.find('li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const date = item.find('.column-news-date').text();
@@ -54,8 +55,7 @@ async function handler() {
link,
pubDate: timezone(parseDate(date), +8),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+26 -30
View File
@@ -44,36 +44,32 @@ async function handler(ctx) {
.match(/(?:[^=]*=)?\s*([^>]+)\s*/)[1];
const publication = $('.al-article-item-wrap.al-normal');
const list = publication
.map((_, item) => {
const title = $(item).find('.item-title a:first').text();
const link = $(item).find('.item-title a:first').attr('href');
const doilink = $(item).find('.citation-label a').attr('href');
const doi = doilink && doilink.match(/10\.\d+\/\S+/)[0];
const id = $(item).find('h5[data-resource-id-access]').data('resource-id-access');
const authors = $(item)
.find('.al-authors-list')
.find('a')
.map(function () {
return $(this).text();
})
.get()
.join('; ');
const imgUrl = $(item).find('.issue-featured-image a img').attr('src');
const img = imgUrl ? imgUrl.replace(/\?.+$/, '') : '';
const description = renderDesc(title, authors, doi, img);
return {
title,
link,
doilink,
id,
authors,
img,
doi,
description,
};
})
.get();
const list = publication.toArray().map((item) => {
const title = $(item).find('.item-title a:first').text();
const link = $(item).find('.item-title a:first').attr('href');
const doilink = $(item).find('.citation-label a').attr('href');
const doi = doilink && doilink.match(/10\.\d+\/\S+/)[0];
const id = $(item).find('h5[data-resource-id-access]').data('resource-id-access');
const authors = $(item)
.find('.al-authors-list')
.find('a')
.toArray()
.map((element) => $(element).text())
.join('; ');
const imgUrl = $(item).find('.issue-featured-image a img').attr('src');
const img = imgUrl ? imgUrl.replace(/\?.+$/, '') : '';
const description = renderDesc(title, authors, doi, img);
return {
title,
link,
doilink,
id,
authors,
img,
doi,
description,
};
});
return {
title: jrnlName,
+3 -3
View File
@@ -33,7 +33,8 @@ async function handler() {
const $ = load(response.data);
const list = $("ul[class='posts'] > li")
.map((i, e) => {
.toArray()
.map((e) => {
const element = $(e);
const title = element.find('a').text().trim();
const link = `http://mysql.taobao.org${element.find('a').attr('href').trim()}/`;
@@ -42,8 +43,7 @@ async function handler() {
description: '',
link,
};
})
.get();
});
const result = await Promise.all(
list.map((item) => {
+12 -18
View File
@@ -42,9 +42,7 @@ async function handler(ctx) {
const $ = load(data);
const title = $('div[class="header-information-title"]')
.contents()
.filter(function () {
return this.nodeType === 3;
})
.filter((element) => element.nodeType === 3)
.text()
.trim();
const desc = $('div[class="header-information"]').find('span').last().text().trim();
@@ -54,20 +52,16 @@ async function handler(ctx) {
title: `阿里云开发者社区-${title}`,
link,
description: desc,
item:
list &&
list
.map((index, item) => {
item = $(item);
const desc = item.find('.question-desc');
const description = item.find('.browse').text() + ' ' + desc.find('.answer').text();
return {
title: item.find('.question-title').text().trim() || item.find('a p').text().trim(),
link: item.find('a').attr('href'),
pubDate: parseDate(item.find('.time').text()),
description,
};
})
.get(),
item: list.toArray().map((item) => {
item = $(item);
const desc = item.find('.question-desc');
const description = item.find('.browse').text() + ' ' + desc.find('.answer').text();
return {
title: item.find('.question-title').text().trim() || item.find('a p').text().trim(),
link: item.find('a').attr('href'),
pubDate: parseDate(item.find('.time').text()),
description,
};
}),
};
}
+3 -3
View File
@@ -48,7 +48,8 @@ async function handler(ctx) {
const response = await got({ method: 'get', url });
const $ = load(response.data);
const list = $('ul > li.notice-li')
.map((i, e) => {
.toArray()
.map((e) => {
const element = $(e);
const title = element.find('a').text().trim();
const link = 'https://help.aliyun.com' + element.find('a').attr('href').trim();
@@ -60,8 +61,7 @@ async function handler(ctx) {
link,
pubDate,
};
})
.get();
});
const result = await Promise.all(
list.map((item) =>
+7 -7
View File
@@ -37,19 +37,19 @@ async function handler() {
const $ = load(data);
const list = $('.a-row.cs-help-landing-section.help-display-cond')
.map(function () {
.toArray()
.map((item) => {
const data = {};
data.title = $(this).find('.sectiontitle').text();
data.link = $(this).find('a').eq(0).attr('href');
data.version = $(this).find('li').first().text();
data.title = $(item).find('.sectiontitle').text();
data.link = $(item).find('a').eq(0).attr('href');
data.version = $(item).find('li').first().text();
data.website = `${url}?nodeId=${nodeIdValue}`;
data.description = $(this)
data.description = $(item)
.find('.a-column.a-span8')
.html()
.replaceAll(/[\t\n]/g, '');
return data;
})
.get();
});
return {
title: 'Kindle E-Reader Software Updates',
link: `${url}?nodeId=${nodeIdValue}`,
+1 -1
View File
@@ -7,7 +7,7 @@ const handler = async () => {
const response = await got(`${url}/vul`);
const $ = load(response.data);
const list = $('table>tbody>tr').get();
const list = $('table>tbody>tr').toArray();
const items = list.map((i) => {
const item = $(i);
+31 -35
View File
@@ -66,40 +66,36 @@ async function handler(ctx) {
title: lz ? `【只看楼主】${title}` : title,
link: `https://tieba.baidu.com/p/${id}?see_lz=${lz}`,
description: `${title}的最新回复`,
item:
list &&
list
.map((_, element) => {
const item = $(element);
const { author, content } = item.data('field');
const tempList = item
.find('.post-tail-wrap > .tail-info')
.toArray()
.map((element) => $(element).text());
let [pubContent, from, num, time] = ['', '', '', ''];
if (0 === tempList.length && 'date' in content) {
num = `${content.post_no}`;
time = content.date;
pubContent = item.find('.j_d_post_content').html();
} else if (2 === tempList.length) {
[num, time] = tempList;
pubContent = content.content;
} else if (3 === tempList.length) {
[from, num, time] = tempList;
pubContent = content.content;
}
return {
title: `${author.user_name}回复了帖子《${title}`,
description: art(path.join(__dirname, '../templates/post.art'), {
pubContent,
author: author.user_name,
num,
from,
}),
pubDate: timezone(parseDate(time, 'YYYY-MM-DD hh:mm'), +8),
link: `https://tieba.baidu.com/p/${id}?pid=${content.post_id}#${content.post_id}`,
};
})
.get(),
item: list.toArray().map((element) => {
const item = $(element);
const { author, content } = item.data('field');
const tempList = item
.find('.post-tail-wrap > .tail-info')
.toArray()
.map((element) => $(element).text());
let [pubContent, from, num, time] = ['', '', '', ''];
if (0 === tempList.length && 'date' in content) {
num = `${content.post_no}`;
time = content.date;
pubContent = item.find('.j_d_post_content').html();
} else if (2 === tempList.length) {
[num, time] = tempList;
pubContent = content.content;
} else if (3 === tempList.length) {
[from, num, time] = tempList;
pubContent = content.content;
}
return {
title: `${author.user_name}回复了帖子《${title}`,
description: art(path.join(__dirname, '../templates/post.art'), {
pubContent,
author: author.user_name,
num,
from,
}),
pubDate: timezone(parseDate(time, 'YYYY-MM-DD hh:mm'), +8),
link: `https://tieba.baidu.com/p/${id}?pid=${content.post_id}#${content.post_id}`,
};
}),
};
}
+4 -4
View File
@@ -36,8 +36,9 @@ async function handler() {
const $ = load(response.data);
const items = [...$('a[href^="/news/20"]')]
.map((_, item) => {
const items = $('a[href^="/news/20"]')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('h3[class^="thumbnail-module--thumbnailTitle--"]').text(),
@@ -45,8 +46,7 @@ async function handler() {
pubDate: parseDate(item.find('span[class^="thumbnail-module--thumbnailType--"]').text()),
link: rootUrl + item.attr('href'),
};
})
.get();
});
return {
title: 'News - BBC News Labs',
+3 -3
View File
@@ -38,15 +38,15 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('div#newsquery > ul > li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('div.title > a').text(),
link: new URL(item.find('div.title > a').attr('href'), baseUrl).href,
// pubDate: parseDate(item.find('div.time').text(), 'YYYY-MM-DD'),
};
})
.get();
});
await Promise.all(
list.map((item) =>
+9 -13
View File
@@ -40,18 +40,14 @@ async function handler(ctx) {
title: `北极星太阳能光大网${typeName}`,
description: $('meta[name="Description"]').attr('content'),
link: `https://guangfu.bjx.com.cn/${type}/`,
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
description: item.html(),
link: item.find('a').attr('href'),
pubDate: parseDate(item.find('span').text()),
};
})
.get(),
item: list.toArray().map((item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
description: item.html(),
link: item.find('a').attr('href'),
pubDate: parseDate(item.find('span').text()),
};
}),
};
}
+3 -4
View File
@@ -24,7 +24,8 @@ async function handler() {
});
const $ = cheerio.load(response.data);
const resultItem = $('.media')
.map((index, elem) => {
.toArray()
.map((elem) => {
elem = $(elem);
const $link = elem.find('dt a');
return {
@@ -34,9 +35,7 @@ async function handler() {
author: elem.find('.small a').eq(0).text(),
pubDate: elem.find('dd').eq(1).text().split('\n')[2],
};
})
.get();
});
return {
title: '技术头条',
link: url,
+10 -12
View File
@@ -15,18 +15,16 @@ const parseAuthorNewsList = async (slug) => {
}
const $ = load(resp.html);
const articles = $('article.story-list-story');
return articles
.map((index, item) => {
item = $(item);
const headline = item.find('a.story-list-story__info__headline-link');
return {
title: headline.text(),
pubDate: item.attr('data-updated-at'),
guid: `bloomberg:${item.attr('data-id')}`,
link: new URL(headline.attr('href'), baseURL).href,
};
})
.get();
return articles.toArray().map((item) => {
item = $(item);
const headline = item.find('a.story-list-story__info__headline-link');
return {
title: headline.text(),
pubDate: item.attr('data-updated-at'),
guid: `bloomberg:${item.attr('data-id')}`,
link: new URL(headline.attr('href'), baseURL).href,
};
});
};
export const route: Route = {
+3 -3
View File
@@ -45,7 +45,8 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('a[title]')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
@@ -53,8 +54,7 @@ async function handler(ctx) {
pubDate: parseDate(item.prev().text()),
link: `${rootUrl}/${category}/${item.attr('href')}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -48,7 +48,8 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('ul.container.list > li')
.map((_, item) => {
.toArray()
.map((item) => {
const link = $(item).find('a').attr('href');
const absoluteLink = new URL(link, currentUrl).href;
return {
@@ -56,8 +57,7 @@ async function handler(ctx) {
pubDate: parseDate($(item).find('span').text()),
link: absoluteLink,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+11 -15
View File
@@ -51,20 +51,16 @@ async function handler(ctx) {
return {
title: $('head title').text(),
link: url,
item:
list &&
list
.map((index, item) => {
item = $(item);
const date = item.find('time').attr('datetime');
const pubDate = parseDate(date);
return {
title: item.find('h2 a').text(),
link: item.find('h2 a').attr('href'),
pubDate,
description: item.find('p').text(),
};
})
.get(),
item: list.toArray().map((item) => {
item = $(item);
const date = item.find('time').attr('datetime');
const pubDate = parseDate(date);
return {
title: item.find('h2 a').text(),
link: item.find('h2 a').attr('href'),
pubDate,
description: item.find('p').text(),
};
}),
};
}
+3 -3
View File
@@ -24,7 +24,8 @@ async function handler() {
const $ = load(response.data);
const list = $('div.single-post')
.map((i, e) => {
.toArray()
.map((e) => {
const element = $(e);
const title = element.find('h2 > a').text();
const link = element.find('h2 > a').attr('href');
@@ -37,8 +38,7 @@ async function handler() {
link,
pubDate: parseDate(dateraw, 'YYYY 年 MM 月 DD 日'),
};
})
.get();
});
return {
title: '不良林',
+2 -2
View File
@@ -68,7 +68,8 @@ async function handler(ctx: Context) {
const $ = load(response.data);
const list = $('.txt-elise')
.map((_, item) => {
.toArray()
.map((item) => {
const $item = $(item);
const $link = $item.find('a');
// Skip elements without links or with empty href
@@ -80,7 +81,6 @@ async function handler(ctx: Context) {
link: rootUrl + '/' + $link.attr('href'),
};
})
.get()
.filter(Boolean);
const items = await Promise.all(
+3 -3
View File
@@ -41,15 +41,15 @@ async function handler() {
const $ = load(response.data);
const list = $('.date-block')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.next().text(),
link: `${rootUrl}/${item.next().attr('href')}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -11,12 +11,12 @@ const getList = async (url) => {
const response = await got(url);
const $ = load(response.data);
const list = $('#infinite-content > div')
.map((_index, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('div.title').text().trim(),
link: new URL($(item).find('div.title > em > a').attr('href'), rootUrl).href,
author: $(item).find('div.contributors').text().trim(),
}))
.get();
}));
return list;
};
+3 -3
View File
@@ -45,15 +45,15 @@ async function handler(ctx) {
const list = $('#content li')
.not('.gl_line')
.slice(0, 15)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: `${rootUrl}/cg/${caty}${a.attr('href').replace('.', '')}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -36,15 +36,15 @@ async function handler() {
const $ = load(listData.data);
const list = $('div.index-four-content > div.article-box')
.find('div.new-child')
.map((_, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('p.new-title').text(),
link: new URL($(item).find('a').attr('href'), rootUrl).href,
author: $(item)
.find('p.new-desc')
.text()
.match(/作者:(.*?)\s/)[1],
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -40,14 +40,14 @@ async function handler(ctx) {
const list = $('.textr a')
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 10)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+1 -1
View File
@@ -9,7 +9,7 @@ import { parseDate } from '@/utils/parse-date';
async function loadContent(link) {
const res = await got({ method: 'get', url: link });
const $ = load(res.data);
// console.log($('div.image').get().text())
// console.log($('div.image').toArray().text())
// console.log('********')
const js_txt = '' + $('script');
+3 -3
View File
@@ -42,7 +42,8 @@ async function handler(ctx) {
const $ = load(content.data);
const items = $('.lczj_box tbody tr')
.map((i, e) => {
.toArray()
.map((e, i) => {
if (i < 2) {
return null;
}
@@ -58,8 +59,7 @@ async function handler(ctx) {
pubDate: timezone(parseDate($('#t_id span').text().slice(5), 'YYYY-MM-DD HH:mm', true), 8),
guid: md5(c('td:nth-child(1)').text() + $('#t_id span').text().slice(5)),
};
})
.get();
});
const ret = {
title: '中国光大银行',
+3 -3
View File
@@ -45,7 +45,8 @@ async function handler(ctx) {
const $ = load(res.data);
const items = $('.lczj_box tbody tr')
.map((i, e) => {
.toArray()
.map((e, i) => {
if (i < 2) {
return null;
}
@@ -60,8 +61,7 @@ async function handler(ctx) {
time: c('td:nth-child(6)').text(),
}),
};
})
.get();
});
items.pop();
const ret = {
+40 -44
View File
@@ -41,59 +41,55 @@ async function handler(ctx) {
});
const data = response.data;
const $ = load(data);
const list = $('.user-work .work-info').get();
const list = $('.user-work .work-info').toArray();
const author = $('div.user-main-info > span.txt-info > a.uname').text();
const authorimg = $('div.user-main-info > .poster > img').attr('data-src');
let items = await Promise.all(
list.map(async (item) => {
list.map((item) => {
const $ = load(item);
const link = $('a').attr('href');
const songid = await cache.tryGet(
link,
async () => {
const result = await got({
method: 'get',
url: link,
headers,
});
return cache.tryGet(link, async () => {
const result = await got({
method: 'get',
url: link,
headers,
});
const re = /workid: '\d+'/;
let workid;
try {
workid = result.data.match(re)[0];
} catch {
// 没有找到该作品
// 这可能是由下列原因造成的:
// 该作品已经被原作者删除了
// 该作品包含了视频,目前正在审核中,在审核没有通过前无法被播放
// 目前服务器压力太大,刚刚上传成功的作品可能需要半个小时后才能被播放
return null;
}
const re = /workid: '\d+'/;
let workid;
try {
workid = result.data.match(re)[0];
} catch {
// 没有找到该作品
// 这可能是由下列原因造成的:
// 该作品已经被原作者删除了
// 该作品包含了视频,目前正在审核中,在审核没有通过前无法被播放
// 目前服务器压力太大,刚刚上传成功的作品可能需要半个小时后才能被播放
return null;
}
workid = workid.split("'")[1];
return workid;
},
60 * 60 * 24
);
if (!songid) {
return null;
}
const mp3 = `https://upscuw.changba.com/${songid}.mp3`;
const description = art(path.join(__dirname, 'templates/work_description.art'), {
desc: $('div.des').text(),
mp3url: mp3,
workid = workid.split("'")[1];
if (!workid) {
return null;
}
const mp3 = `https://upscuw.changba.com/${workid}.mp3`;
const description = art(path.join(__dirname, 'templates/work_description.art'), {
desc: $('div.des').text(),
mp3url: mp3,
});
const itunes_item_image = $('div.work-cover').attr('style').replace(')', '').split('url(')[1];
return {
title: $('.work-title').text(),
description,
link,
author,
itunes_item_image,
enclosure_url: mp3,
enclosure_type: 'audio/mpeg',
};
});
const itunes_item_image = $('div.work-cover').attr('style').replace(')', '').split('url(')[1];
return {
title: $('.work-title').text(),
description,
link,
author,
itunes_item_image,
enclosure_url: mp3,
enclosure_type: 'audio/mpeg',
};
})
);
+2 -2
View File
@@ -57,13 +57,13 @@ async function handler(ctx) {
const listCategory = `中华网-财经-${categoryTitle}新闻`;
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 30;
const detailsUrls = $('.item-con-inner')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
link: item.find('.tit>a').attr('href'),
};
})
.get()
.filter((item) => item.link !== void 0)
.slice(0, limit);
+11 -15
View File
@@ -50,20 +50,16 @@ async function handler(ctx) {
return {
title: `中华网-${categoryTitle}新闻`,
link: websiteUrl,
item:
news &&
news
.map((_, item) => {
item = $(item);
return {
title: item.find('.item_title a').text(),
author: item.find('.item_source').text(),
category: `${categoryTitle}新闻`,
pubDate: parseDate(item.find('.item_time').text()),
description: item.find('.item_title a').text(),
link: item.find('li a').attr('href'),
};
})
.get(),
item: news.toArray().map((item) => {
item = $(item);
return {
title: item.find('.item_title a').text(),
author: item.find('.item_source').text(),
category: `${categoryTitle}新闻`,
pubDate: parseDate(item.find('.item_time').text()),
description: item.find('.item_title a').text(),
link: item.find('li a').attr('href'),
};
}),
};
}
+11 -15
View File
@@ -36,20 +36,16 @@ async function handler() {
return {
title: '中华网-军事新闻',
link: 'https://military.china.com/news/',
item:
commonList &&
commonList
.map((_, item) => {
item = $(item);
return {
title: item.find('h3.item_title').text(),
author: '中华网军事',
category: '中华网军事',
pubDate: parseDate(item.find('em.item_time').text()),
description: item.find('.item_source').text(),
link: item.find('h3.item_title a').attr('href'),
};
})
.get(),
item: commonList.toArray().map((item) => {
item = $(item);
return {
title: item.find('h3.item_title').text(),
author: '中华网军事',
category: '中华网军事',
pubDate: parseDate(item.find('em.item_time').text()),
description: item.find('.item_source').text(),
link: item.find('h3.item_title a').attr('href'),
};
}),
};
}
+2 -2
View File
@@ -29,11 +29,11 @@ async function handler(ctx) {
});
const $ = load(response.data);
const list = $('a', '.dd_bt')
.map((_, item) => ({
.toArray()
.map((item) => ({
link: rootUrl + $(item).attr('href'),
title: $(item).text(),
}))
.get()
.slice(0, ctx.req.query('limit') ? Math.min(Number.parseInt(ctx.req.query('limit')), 125) : 50);
const items = await Promise.all(
+3 -5
View File
@@ -57,13 +57,11 @@ async function handler(ctx) {
});
const $ = load(response.data);
const list = $('a', '.common_newslist_pc')
.filter(function () {
return $(this).attr('href');
})
.map((_, item) => ({
.filter((element) => $(element).attr('href'))
.toArray()
.map((item) => ({
link: rootUrl + $(item).attr('href'),
}))
.get()
.slice(0, ctx.req.query('limit') ? Math.min(Number.parseInt(ctx.req.query('limit')), 20) : 20);
const items = await Promise.all(
+3 -3
View File
@@ -41,14 +41,14 @@ async function handler(ctx) {
const list = $('#newsrightlist a')
.slice(0, 10)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href').replace('..', '')}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+1 -1
View File
@@ -67,7 +67,7 @@ async function handler(ctx) {
item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html();
item.category = [
...content("meta[property='article:tag']")
.get()
.toArray()
.map((e) => e.attribs.content),
content('.active > a').text(),
];
+1 -1
View File
@@ -58,7 +58,7 @@ async function handler(ctx) {
item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html();
item.category = [
...content("meta[property='article:tag']")
.get()
.toArray()
.map((e) => e.attribs.content),
content('.active > a').text(),
];
+3 -3
View File
@@ -35,12 +35,12 @@ async function handler(ctx) {
const $ = load(response.data);
const title = $('h1.is-style-page-title').text();
const list = $('div.post-archive__item')
.map((_index, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('span.post-archive__title').text().trim(),
link: $(item).find('span.post-archive__title > a').attr('href'),
pubDate: parseDate($(item).find('span.post-archive__item_date').text().split('|')[0]),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -25,11 +25,11 @@ async function handler() {
const response = await got(url);
const $ = load(response.data);
const list = $('div.report-item')
.map((_index, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('a.report-item__link').attr('title'),
link: $(item).find('a.report-item__link').attr('href'),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
+7 -7
View File
@@ -51,12 +51,12 @@ async function handler(ctx) {
});
const $ = load(response.data);
const list = $('dd')
.map((_, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('span.name > a').text().trim(),
link: `${rootUrl}/kcms/detail/${new URLSearchParams(new URL(`${rootUrl}/${$(item).find('span.name > a').attr('href')}`).search).get('url')}.html`,
pubDate: parseDate($(item).find('span.company').text(), 'YYYY-MM-DD HH:mm:ss'),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
@@ -65,12 +65,12 @@ async function handler(ctx) {
const $ = load(detailResponse.data);
item.description = art(path.join(__dirname, 'templates/desc.art'), {
author: $('h3.author > span')
.map((_, item) => $(item).text())
.get()
.toArray()
.map((item) => $(item).text())
.join(' '),
company: $('a.author')
.map((_, item) => $(item).text())
.get()
.toArray()
.map((item) => $(item).text())
.join(' '),
content: $('div.row > span.abstract-text').parent().text(),
});
+10 -12
View File
@@ -79,19 +79,17 @@ async function handler(ctx) {
const $ = load(response.data);
const publications = $('dd');
const list = publications
.map((_, publication) => {
const title = $(publication).find('a').first().text();
const filename = $(publication).find('b').attr('id');
const link = `https://cnki.net/kcms/detail/detail.aspx?filename=${filename}&dbcode=CJFD`;
const list = publications.toArray().map((publication) => {
const title = $(publication).find('a').first().text();
const filename = $(publication).find('b').attr('id');
const link = `https://cnki.net/kcms/detail/detail.aspx?filename=${filename}&dbcode=CJFD`;
return {
title,
link,
pubDate: date,
};
})
.get();
return {
title,
link,
pubDate: date,
};
});
const items = await Promise.all(list.map((item) => cache.tryGet(item.link, () => ProcessItem(item))));
+3 -3
View File
@@ -71,14 +71,14 @@ async function handler(ctx: Context) {
const author = $("span:contains('作者')").parent().contents().eq(1).text();
// const cover = $(".fed-deta-images a").attr('data-original');
const items = $('.all_data_list >ul>li>a')
.map((i, elem) => ({
.toArray()
.map((elem, i) => ({
title: `${book_name} ${$(elem).text()}`,
link: elem.attribs.href,
description: $('.fed-part-esan').text(),
author,
pubDate: shift_date(updateDate, -7 * i),
}))
.get();
}));
return {
title: book_name || 'Unknown Manga',
+3 -3
View File
@@ -45,7 +45,8 @@ async function handler(ctx) {
const response = await got.get(url);
const $ = load(response.data);
const list = $('div.words > ul > li')
.map((_, item) => {
.toArray()
.map((item) => {
const date = $(item).find('span').text();
const dateArr = date.split('-');
const dateStr = Number.parseInt(dateArr[0]) + 1911 + '/' + dateArr[1] + '/' + dateArr[2];
@@ -55,8 +56,7 @@ async function handler(ctx) {
title: $(item).find('a').attr('title'),
pubDate: parseDate(dateStr, 'YYYY/MM/DD'),
};
})
.get();
});
const items = await Promise.all(
list.map(async (item) => {
+3 -3
View File
@@ -37,14 +37,14 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('div.InCont_r_d_cont > li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
link: new URL(item.find('a').attr('href'), baseUrl).href,
pubDate: parseDate(item.find('span.cont_d').text(), 'YYYY-MM-DD'),
};
})
.get();
});
await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -29,7 +29,8 @@ async function handler(ctx) {
const $ = load(data);
const list = $('div.notice_right ul li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const url = `http://${domain}` + item.find('a').attr('href').slice(1);
const title = item.find('a div.title').text();
@@ -40,8 +41,7 @@ async function handler(ctx) {
author: '中国法学网',
pubtime: publish_time,
};
})
.get();
});
return {
title: '中国法学网',
+1 -1
View File
@@ -41,7 +41,7 @@ async function handler(ctx) {
const link = url + type + '.htm';
const response = await got.get(link);
const $ = load(response.data);
const list = $('.download li').get();
const list = $('.download li').toArray();
const out = await Promise.all(
list.map((item) => {
const $ = load(item);
+1 -1
View File
@@ -23,7 +23,7 @@ export default {
const data = iconv.decode(listRes.data, 'gb2312');
const $ = load(data);
// 只取最近的三个,取全文rss
const list = $('li', 'ul').slice(0, 3).get();
const list = $('li', 'ul').slice(0, 3).toArray();
const result_item = await Promise.all(
list.map((item) =>
+19 -21
View File
@@ -41,27 +41,25 @@ async function handler(ctx) {
const $ = load(response.data);
const lists = $('div.c-box > div > div.c-zx-list > ul > li');
const reg = /日期:(.*?(\s\(.*?\))?)\s/;
const list = lists
.map((index, item) => {
item = $(item).find('div');
let date = reg.exec(item.find('div.r > p.other').text())[1];
if (date.includes('周') || date.includes('月')) {
date = /\((.*?)\)/.exec(date)[1];
date = parseDate(date, 'MM-DD');
} else if (date.includes('年')) {
date = /\((.*?)\)/.exec(date)[1];
date = parseDate(date, 'YYYY-MM-DD');
} else {
date = parseRelativeDate(date);
}
return {
title: item.find('div.r > p.r-top > span > a').text(),
pubDate: timezone(date, +8),
description: item.find('div.r > p.desc').text(),
link: item.find('div.r > p.r-top > span > a').attr('href'),
};
})
.get();
const list = lists.toArray().map((item) => {
item = $(item).find('div');
let date = reg.exec(item.find('div.r > p.other').text())[1];
if (date.includes('周') || date.includes('月')) {
date = /\((.*?)\)/.exec(date)[1];
date = parseDate(date, 'MM-DD');
} else if (date.includes('年')) {
date = /\((.*?)\)/.exec(date)[1];
date = parseDate(date, 'YYYY-MM-DD');
} else {
date = parseRelativeDate(date);
}
return {
title: item.find('div.r > p.r-top > span > a').text(),
pubDate: timezone(date, +8),
description: item.find('div.r > p.desc').text(),
link: item.find('div.r > p.r-top > span > a').attr('href'),
};
});
const items =
fulltext === 'y'
? await Promise.all(
+3 -4
View File
@@ -24,7 +24,8 @@ async function handler() {
const $ = load(response.data);
const list = $('div.col-xs-12.col-md-8.pd30 > div.panel.panel-default.categeay > div.panel-body > ul.media-list.clearfix > li.media')
.map((i, e) => {
.toArray()
.map((e) => {
const element = $(e);
const title = element.find('h3 > a').text();
const link = element.find('h3 > a').attr('href');
@@ -37,9 +38,7 @@ async function handler() {
link,
pubDate: parseDate(dateraw, 'YYYY年MM月DD日'),
};
})
.get();
});
return {
title: 'dbaplus社群',
link: url,
+3 -3
View File
@@ -1,5 +1,5 @@
import { Route } from '@/types';
const envs = process.env;
import { config } from '@/config';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
@@ -31,7 +31,7 @@ export const route: Route = {
async function handler(ctx) {
const url = 'https://www.ddosi.org/category';
const userAgent = envs.UA || 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1';
const userAgent = config.ua || 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1';
const category = ctx.req.param('category');
const response = await got({
method: 'get',
@@ -42,7 +42,7 @@ async function handler(ctx) {
},
});
const $ = load(response.data);
const list = $('main>article').get();
const list = $('main>article').toArray();
const items = list.map((i) => {
const item = $(i);
+3 -3
View File
@@ -1,5 +1,5 @@
import { Route } from '@/types';
const envs = process.env;
import { config } from '@/config';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
@@ -20,7 +20,7 @@ export const route: Route = {
async function handler() {
const url = 'https://www.ddosi.org/';
const userAgent = envs.UA || 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1';
const userAgent = config.ua || 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1';
const response = await got({
method: 'get',
url: String(url),
@@ -30,7 +30,7 @@ async function handler() {
},
});
const $ = load(response.data);
const list = $('main>article').get();
const list = $('main>article').toArray();
const items = list.map((i) => {
const item = $(i);
+3 -3
View File
@@ -39,15 +39,15 @@ async function handler() {
const $ = load(response.data);
const list = $('.elementor-heading-title a')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+5 -5
View File
@@ -39,7 +39,8 @@ async function handler(ctx) {
title: $('title').text(),
link: url,
item: $('.briefnews_con_li .li_img_de')
.map((_, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('h3 a').text(),
link: $(item).find('h3 a').attr('href'),
author: $(item).find('.head_con_p_o span:nth-child(3)').text().split('')[1],
@@ -47,9 +48,8 @@ async function handler(ctx) {
description: $(item).find('p.com_about').text(),
category: $(item)
.find('.u_comfoot a .bqwarp')
.map((_, item) => $(item).text())
.get(),
}))
.get(),
.toArray()
.map((item) => $(item).text()),
})),
};
}
+3 -3
View File
@@ -54,7 +54,8 @@ async function handler() {
$ = load(newBookPage.data);
const resultItem = $('.doulist-item')
.map((_, item) => {
.toArray()
.map((item) => {
const $item = $(item);
return {
@@ -63,8 +64,7 @@ async function handler() {
description: `<img src="${$item.find('.post img').attr('src')}" /><br>${$item.find('.abstract').html()}`,
pubDate: new Date($item.find('.time > span').attr('title')).toUTCString(),
};
})
.get();
});
return {
title: `商务印书馆-${title}`,
+9 -13
View File
@@ -43,18 +43,14 @@ async function handler(ctx) {
return {
title: `豆瓣电影人 - ${person}`,
link: `https://movie.douban.com/celebrity/${id}/movies?sortby=${sort}`,
item:
list &&
list
.map((index, item) => {
item = $(item);
itemPicUrl = item.find('img').attr('src');
return {
title: '《' + item.find('h6 > a').text() + '》' + item.find('h6 > span').text().replace('(', '').replace(')', '').replace('[', '【').replace(']', '】'),
description: `<img src="${itemPicUrl}"/><br/>主演:${item.find('dl > dd').last().text()}<br/>评分:${item.find('.star > span:nth-child(2)').text()}`,
link: item.find('dt > a').attr('href'),
};
})
.get(),
item: list.toArray().map((item) => {
item = $(item);
itemPicUrl = item.find('img').attr('src');
return {
title: '《' + item.find('h6 > a').text() + '》' + item.find('h6 > span').text().replace('(', '').replace(')', '').replaceAll('[', '【').replaceAll(']', '】'),
description: `<img src="${itemPicUrl}"/><br/>主演:${item.find('dl > dd').last().text()}<br/>评分:${item.find('.star > span:nth-child(2)').text()}`,
link: item.find('dt > a').attr('href'),
};
}),
};
}
+16 -16
View File
@@ -36,34 +36,35 @@ async function handler(ctx) {
const title = $('#content h1').text().trim();
const description = $('div.doulist-about').text().trim();
const out = $('div.doulist-item')
.map(function () {
const type = $(this).find('div.source').text().trim();
.toArray()
.map((item) => {
const type = $(item).find('div.source').text().trim();
let title = $(this).find('div.bd.doulist-note div.title a').text().trim();
let link = $(this).find('div.bd.doulist-note div.title a').attr('href');
let description = $(this).find('div.bd.doulist-note div.abstract').text().trim();
let title = $(item).find('div.bd.doulist-note div.title a').text().trim();
let link = $(item).find('div.bd.doulist-note div.title a').attr('href');
let description = $(item).find('div.bd.doulist-note div.abstract').text().trim();
if (type === '来自:豆瓣广播') {
title = $(this).find('p.status-content > a').text().trim();
link = $(this).find('p.status-content a').attr('href');
title = $(item).find('p.status-content > a').text().trim();
link = $(item).find('p.status-content a').attr('href');
description = $(this).find('span.status-recommend-text').text().trim();
description = $(item).find('span.status-recommend-text').text().trim();
}
if (type === '来自:豆瓣电影' || type === '来自:豆瓣' || type === '来自:豆瓣读书' || type === '来自:豆瓣音乐') {
title = $(this).find('div.bd.doulist-subject div.title a').text().trim();
link = $(this).find('div.bd.doulist-subject div.title a').attr('href');
title = $(item).find('div.bd.doulist-subject div.title a').text().trim();
link = $(item).find('div.bd.doulist-subject div.title a').attr('href');
description = $(this).find('div.bd.doulist-subject div.abstract').text().trim();
description = $(item).find('div.bd.doulist-subject div.abstract').text().trim();
const ft = $(this).find('div.ft div.comment-item.content').text().trim();
const ft = $(item).find('div.ft div.comment-item.content').text().trim();
const img = $(this).find('div.post a img').attr('src');
const img = $(item).find('div.post a img').attr('src');
description = '<div><img width="100" src="' + img + '"></div>' + description + '<blockquote>' + ft + '</blockquote>';
}
const date = $(this).find('div.ft div.actions time span').attr('title');
const date = $(item).find('div.ft div.actions time span').attr('title');
const single = {
title,
@@ -72,8 +73,7 @@ async function handler(ctx) {
pubDate: new Date(date).toUTCString(),
};
return single;
})
.get();
});
return {
title,
+6 -6
View File
@@ -20,15 +20,15 @@ async function handler(ctx) {
const list = $('div.item')
.slice(0, 10)
.map(function () {
.toArray()
.map((item) => {
const info = {
title: $(this).find('div.title a').text(),
link: $(this).find('div.title a').attr('href'),
author: $(this).find('div.usr-pic a').text(),
title: $(item).find('div.title a').text(),
link: $(item).find('div.title a').attr('href'),
author: $(item).find('div.usr-pic a').text(),
};
return info;
})
.get();
});
for (let i = list.length - 1; i >= 0; i--) {
if (list[i].author === '[已注销]') {
+23 -27
View File
@@ -37,34 +37,30 @@ async function handler() {
return {
title: '豆瓣-浏览发现',
link: 'https://www.douban.com/explore',
item:
list &&
list
.map((_, item) => {
item = $(item);
item: list.toArray().map((item) => {
item = $(item);
const title = item.find('.title a').first().text() ?? '#' + item.find('.icon-topic').text();
const desc = item.find('.content p').text();
const itemPic = item.find('a.cover').attr('style')
? item
.find('a.cover')
.attr('style')
.match(/\('(.*?)'\)/)[1]
: '';
const author = item.find('.usr-pic a').last().text();
const link = item.find('.title a').attr('href') ?? item.find('.icon-topic a').attr('href');
const title = item.find('.title a').first().text() ?? '#' + item.find('.icon-topic').text();
const desc = item.find('.content p').text();
const itemPic = item.find('a.cover').attr('style')
? item
.find('a.cover')
.attr('style')
.match(/\('(.*?)'\)/)[1]
: '';
const author = item.find('.usr-pic a').last().text();
const link = item.find('.title a').attr('href') ?? item.find('.icon-topic a').attr('href');
return {
title,
author,
description: art(path.join(__dirname, '../templates/explore.art'), {
author,
desc,
itemPic,
}),
link,
};
})
.get(),
return {
title,
author,
description: art(path.join(__dirname, '../templates/explore.art'), {
author,
desc,
itemPic,
}),
link,
};
}),
};
}
+1 -1
View File
@@ -59,7 +59,7 @@ async function handler(ctx) {
});
const $ = load(response.data);
const list = $('.olt tr:not(.th)').slice(0, 30).get();
const list = $('.olt tr:not(.th)').slice(0, 30).toArray();
const items = await Promise.all(
list.map((item) => {
+5 -7
View File
@@ -39,13 +39,11 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('div.mod.position');
const items = list
.map((_, item) => ({
title: $(item).find('h3').text(),
link: `${url}#${$(item).find('h3').attr('id')}`,
description: $(item).find('div.bd').html(),
}))
.get();
const items = list.toArray().map((item) => ({
title: $(item).find('h3').text(),
link: `${url}#${$(item).find('h3').attr('id')}`,
description: $(item).find('div.bd').html(),
}));
return {
title: `豆瓣${titleMap[type]}`,
+3 -3
View File
@@ -28,7 +28,8 @@ async function handler() {
const $ = load(response.data);
const item = $('#showing-soon .item')
.map((index, ele) => {
.toArray()
.map((ele) => {
const description = $(ele).html();
const name = $('h3', ele).text().trim();
const date = $('ul li', ele).eq(0).text().trim();
@@ -40,8 +41,7 @@ async function handler() {
link,
description,
};
})
.get();
});
return {
title: '即将上映的电影',
+1 -1
View File
@@ -32,7 +32,7 @@ async function handler(ctx) {
const url = 'https://music.douban.com/latest';
const res = await got.get(url);
const $ = load(res.data);
const list = $('.dlist').get();
const list = $('.dlist').toArray();
data = {
title,
+1 -1
View File
@@ -32,7 +32,7 @@ async function handler(ctx) {
title: `正在上映的${score ? `超过 ${score} 分的` : ''}电影`,
link: `https://movie.douban.com/cinema/nowplaying/`,
item: $('.list-item')
.get()
.toArray()
.map((i) => {
const item = $(i);
const itemScore = Number.parseFloat(item.attr('data-score')) || 0;
+3 -3
View File
@@ -30,7 +30,8 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('div.recent-replied-mod ul.comment-list li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const p = item.find('p');
const nid = p
@@ -44,8 +45,7 @@ async function handler(ctx) {
title: `${item.find('a.lnk-people').text()} - ${title}`,
link: `https://www.douban.com/note/${nid}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -30,7 +30,8 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('div.recent-replies-mod ul.comment-list li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const p = item.find('p');
const match = p
@@ -43,8 +44,7 @@ async function handler(ctx) {
return {
link: `https://www.douban.com/note/${nid}/#${cid}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+1 -1
View File
@@ -64,7 +64,7 @@ async function handler(ctx) {
if (list) {
return Promise.all(
list.get().map((item) => {
list.toArray().map((item) => {
item = $(item);
const itemPicUrl = item.find('.pic a img').attr('src');
const info = item.find('.info');
+3 -3
View File
@@ -47,15 +47,15 @@ async function handler(ctx) {
const list = $('.info-2_P1UM a')
.slice(0, 10)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -58,14 +58,14 @@ async function handler(ctx) {
const list = $('.entry-title a')
.slice(0, 10)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -61,12 +61,12 @@ async function handler(ctx) {
const $ = load(response.data);
const title = $('div.categories-list > div > div > div > ul > li.active').text();
const list = $('div.post-item')
.map((_index, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('div.title').text(),
link: new URL($(item).find('a').attr('href'), host).href,
pubDate: parseDate($(item).find('div.metas > a > span').text().replace('・', '')),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
+25 -29
View File
@@ -66,36 +66,32 @@ async function handler(ctx) {
description: `Eagle ${changelog}`,
// 遍历此前获取的数据
item:
list &&
list
.map((index, item) => {
item = $(item);
// 对获取的日期进行格式化处理
function getDate() {
const str = item.find('.date').text();
let date = '';
if (language === 'cn' || language === 'tw') {
const patt = /\d+/g;
let result;
while ((result = patt.exec(str)) !== null) {
date += result + '-';
}
date = date.replaceAll(/-$/g, '');
} else if (language === 'en') {
date = str.replaceAll('RELEASED', '');
}
return date;
item: list.toArray().map((item) => {
item = $(item);
// 对获取的日期进行格式化处理
function getDate() {
const str = item.find('.date').text();
let date = '';
if (language === 'cn' || language === 'tw') {
const patt = /\d+/g;
let result;
while ((result = patt.exec(str)) !== null) {
date += result + '-';
}
date = date.replaceAll(/-$/g, '');
} else if (language === 'en') {
date = str.replaceAll('RELEASED', '');
}
return date;
}
return {
title: item.find('.ver').text(),
description: item.find('.logs').html(),
link: `https://${language}.eagle.cool/changelog`,
pubDate: parseDate(getDate()),
guid: item.find('.ver').text(),
};
})
.get(),
return {
title: item.find('.ver').text(),
description: item.find('.logs').html(),
link: `https://${language}.eagle.cool/changelog`,
pubDate: parseDate(getDate()),
guid: item.find('.ver').text(),
};
}),
};
}
+3 -3
View File
@@ -29,12 +29,12 @@ export const route: Route = {
const response = await got(`${baseUrl}tzggwwxsgg/list.htm`);
const $ = load(response.data);
const links = $('.col_news_con ul.news_list > li')
.map((_, el) => ({
.toArray()
.map((el) => ({
pubDate: timezone(parseDate($(el).find('.news_date').text()), 8),
link: new URL($(el).find('a').attr('href'), baseUrl).toString(),
title: $(el).find('a').text(),
}))
.get();
}));
const items = await Promise.all(
links.map((item) =>
cache.tryGet(item.link, async () => {
+1 -1
View File
@@ -150,7 +150,7 @@ function getBittorrent(cache, bittorrent_page_url) {
try {
const response = await got({ method: 'get', url: bittorrent_page_url, headers });
const $ = load(response.data);
const el_forms = $('form').get();
const el_forms = $('form').toArray();
let bittorrent_url;
for (const el_form of el_forms) {
const el_a = $(el_form).find('a');
+3 -3
View File
@@ -34,7 +34,8 @@ async function handler(ctx) {
const $ = load(response.data);
const jrnlName = $('.anchor.js-title-link').text();
const list = $('.js-article')
.map((_, item) => {
.toArray()
.map((item) => {
const title = $(item).find('.js-article-title').text();
const authors = $(item).find('.js-article__item__authors').text();
const link = $(item).find('.article-content-title').attr('href');
@@ -46,8 +47,7 @@ async function handler(ctx) {
authors,
issue,
};
})
.get();
});
const renderDesc = (item) =>
art(path.join(__dirname, 'templates/description.art'), {
+3 -3
View File
@@ -45,7 +45,8 @@ async function handler(ctx) {
});
const $2 = load(response2.data);
const list = $2('.js-article')
.map((_, item) => {
.toArray()
.map((item) => {
const title = $2(item).find('.js-article-title').text();
const authors = $2(item).find('.js-article__item__authors').text();
const link = $2(item).find('.article-content-title').attr('href');
@@ -57,8 +58,7 @@ async function handler(ctx) {
authors,
issue,
};
})
.get();
});
const renderDesc = (item) =>
art(path.join(__dirname, 'templates/description.art'), {
+14 -16
View File
@@ -30,22 +30,20 @@ async function handler(ctx) {
let dateRow = '';
const item = await Promise.all(
data
.map((i, e) => {
let date = $(e).find('td').first().text().trim();
if (date.includes('-')) {
dateRow = date.split(' ')[0];
} else {
date = `${dateRow} ${date}`;
}
return {
title: $(e).find('a').text(),
pubDate: parseDate(date, 'MMM-DD-YY HH:mmA'),
author: $(e).find('span').text(),
link: $(e).find('a').attr('href'),
};
})
.get()
data.toArray().map((e) => {
let date = $(e).find('td').first().text().trim();
if (date.includes('-')) {
dateRow = date.split(' ')[0];
} else {
date = `${dateRow} ${date}`;
}
return {
title: $(e).find('a').text(),
pubDate: parseDate(date, 'MMM-DD-YY HH:mmA'),
author: $(e).find('span').text(),
link: $(e).find('a').attr('href'),
};
})
);
const name = $('.fullview-title b').text();
+3 -3
View File
@@ -56,15 +56,15 @@ async function handler() {
};
const items = $('.news-message')
.map((_, elem) => ({
.toArray()
.map((elem) => ({
pubDate: parseDate($('.news-message-date', elem).text().trim(), 'DD.MM.YYYY HH:mm'),
title: $('.news-message-location', elem).text().trim(),
description: descBuilder(elem).html(),
author: $('.news-message-user', elem).text().trim(),
guid: $(elem).attr('id'),
link: rootUrl + $('.news-message-comments-number > a', elem).attr('href'),
}))
.get();
}));
return {
title: $('head > title').text().trim(),
+3 -3
View File
@@ -28,7 +28,8 @@ async function handler() {
title: 'Release notes — fish-shell',
language: 'en',
item: $('#release-notes > section')
.map((_, item) => {
.toArray()
.map((item) => {
const title = $(item).find('h2').contents().first().text();
const date = title.match(/\(released (.+?)\)/)?.[1];
return {
@@ -37,7 +38,6 @@ async function handler() {
pubDate: date ? parseDate(date, 'MMMM D, YYYY') : undefined,
description: $(item).html(),
};
})
.get(),
}),
};
}
+1 -1
View File
@@ -123,7 +123,7 @@ async function handler(ctx) {
const $ = load(gbk2utf8(response.data));
const list = $("[id*='normalthread']").get();
const list = $("[id*='normalthread']").toArray();
const result = await util.ProcessFeed(list, cache);
+3 -3
View File
@@ -41,12 +41,12 @@ async function handler() {
const $ = load(gbk2utf8(response.data));
const list = $('.comiis_wzli')
.map((_index, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('.wzbt').text(),
link: `${host}/${$(item).find('.wzbt a').attr('href')}`,
description: $(item).find('.wznr > div:first-child').text(),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
+4 -4
View File
@@ -55,12 +55,12 @@ async function handler(ctx) {
item.category = [
$('.n-content-tag--with-follow').text(),
...$('.article__right-bottom a.concept-list__concept')
.map((i, e) => $(e).text().trim())
.get(),
.toArray()
.map((e) => $(e).text().trim()),
];
item.author = $('a.n-content-tag--author')
.map((i, e) => ({ name: $(e).text() }))
.get();
.toArray()
.map((e) => ({ name: $(e).text() }));
return item;
})
+2 -2
View File
@@ -38,8 +38,8 @@ async function handler(ctx) {
});
const $ = load(res.data);
const artists = $('.filter-item')
.map((i, e) => utils.authorDetail(e))
.get();
.toArray()
.map((e) => utils.authorDetail(e));
artists.shift(); // the first one is "show all"
return {
+13 -15
View File
@@ -50,12 +50,12 @@ const detailPage = (link, cache) =>
const title = $('.row .panel-heading h2').text().trim(); // Get first title
const desc = $('.character-description p').text().trim();
const pics = $('.img-gallery .prettyPhoto')
.map((i, e) => {
.toArray()
.map((e) => {
const p = load(e);
const link = p('a').attr('href').trim();
return `${base}/${link.slice(2)}`;
})
.get();
});
return {
title,
@@ -69,18 +69,16 @@ const fetchAllCharacters = (data, base) => {
// All character page
const $ = load(data);
const characters = $('.character-article');
const info = characters
.map((i, e) => {
const c = load(e);
const r = {
title: c('.character-headline').text().trim(),
headImage: c('.character-images img').attr('src').trim(),
detailPage: `${base}/${c('.character-images a').attr('href').trim()}`,
author: authorDetail(c('.character-description').html()),
};
return r;
})
.get();
const info = characters.toArray().map((e) => {
const c = load(e);
const r = {
title: c('.character-headline').text().trim(),
headImage: c('.character-images img').attr('src').trim(),
detailPage: `${base}/${c('.character-images a').attr('href').trim()}`,
author: authorDetail(c('.character-description').html()),
};
return r;
});
return info;
};
+12 -14
View File
@@ -34,19 +34,17 @@ async function handler(ctx) {
const title = `FX-Markets ${pageTitle}`;
const items = $('div#listings').children();
const articles = items
.map((i, el) => {
const $el = $(el);
const $titleEl = $el.find('h5 > a');
const articleURL = `https://www.fx-markets.com${$titleEl.attr('href')}`;
const articleTitle = $titleEl.attr('title');
return {
title: articleTitle,
link: articleURL,
pubDate: parseDate($el.find('time').text()),
};
})
.get();
const articles = items.toArray().map((el) => {
const $el = $(el);
const $titleEl = $el.find('h5 > a');
const articleURL = `https://www.fx-markets.com${$titleEl.attr('href')}`;
const articleTitle = $titleEl.attr('title');
return {
title: articleTitle,
link: articleURL,
pubDate: parseDate($el.find('time').text()),
};
});
const result = await Promise.all(
articles.map((item) =>
@@ -54,7 +52,7 @@ async function handler(ctx) {
const res = await got(item.link);
const doc = load(res.data);
// This script holds publish datetime info {"datePublished": "2022-05-12T08:45:04+01:00"}
const dateScript = doc('script[type="application/ld+json"]').get()[0].children[0].data;
const dateScript = doc('script[type="application/ld+json"]').toArray()[0].children[0].data;
const re = /"datePublished": "(?<dateTimePub>.*)"/;
const dateStr = re.exec(dateScript).groups.dateTimePub;
const pubDateTime = parseDate(dateStr, 'YYYY-MM-DDTHH:mm:ssZ');
+2 -2
View File
@@ -37,9 +37,9 @@ async function handler() {
// 页面新闻消息列表
const list = $('.body_zb ul .body_zb_li .zb_word')
.find('.list_font_pic > a:first-child')
.map((i, e) => $(e).attr('href'))
.toArray()
.slice(0, 30)
.get();
.map((e) => $(e).attr('href'));
const out = await Promise.all(
list.map((itemUrl) =>
+3 -3
View File
@@ -29,7 +29,8 @@ async function handler() {
const $ = load(data);
const list = $('span#resources li')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const url = `http://${domain}` + item.find('a').attr('href');
const title = item.find('a').text();
@@ -40,8 +41,7 @@ async function handler() {
author: '福州地铁',
pubtime: publishTime,
};
})
.get();
});
return {
title: '福州地铁通知公告',
+3 -3
View File
@@ -95,7 +95,8 @@ async function handler(ctx) {
.children()
.not('p,a,img,span')
.slice(0, limit)
.map((index, item) => {
.toArray()
.map((item) => {
item = $(item);
let aLabelNode;
let tag;
@@ -113,8 +114,7 @@ async function handler(ctx) {
title: '[' + tag + ']' + aLabelNode.text(),
link: aLabelNode.attr('href').replace('//', 'https://'),
};
})
.get();
});
const items = await Promise.all(
list.map(async (item) => {
+3 -3
View File
@@ -35,13 +35,13 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('div.FM-abox2A a.FM-abox2B')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
link: `https:${item.attr('href')}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+17 -19
View File
@@ -42,25 +42,23 @@ async function handler(ctx) {
const description = $('head meta[name=description]').attr('content');
const language = 'ja';
const item = articles
.map((_, article) => {
const _subtitle = $('p.m-listitem__title span.subtitle', article).text();
const _title = $('p.m-listitem__title', article)
.contents()
.filter((_, el) => el.nodeType === 3)
.text();
const title = `${_subtitle} ${_title}`;
const author = $('p.m-listitem__author', article).text();
const pubDate = timezone(parseDate($('span.date', article).text(), 'YYYY-MM-DD'), +9);
const link = `${baseUrl}${$('a', article).attr('href')}`.replace(/\?summary$/, '');
return {
title,
author,
pubDate,
link,
};
})
.get();
const item = articles.toArray().map((article) => {
const _subtitle = $('p.m-listitem__title span.subtitle', article).text();
const _title = $('p.m-listitem__title', article)
.contents()
.filter((_, el) => el.nodeType === 3)
.text();
const title = `${_subtitle} ${_title}`;
const author = $('p.m-listitem__author', article).text();
const pubDate = timezone(parseDate($('span.date', article).text(), 'YYYY-MM-DD'), +9);
const link = `${baseUrl}${$('a', article).attr('href')}`.replace(/\?summary$/, '');
return {
title,
author,
pubDate,
link,
};
});
return {
title,
+1 -1
View File
@@ -40,7 +40,7 @@ async function handler(ctx) {
const name = $('#gsc_prf_in').text();
const description = `Google Scholar Citation Monitor: ${name}; Profile: ${profile}; HomePage: ${homePage}`;
const list = $('#gsc_a_b .gsc_a_tr').get();
const list = $('#gsc_a_b .gsc_a_tr').toArray();
const out = list.map((item) => {
const $ = load(item);
+1 -1
View File
@@ -48,7 +48,7 @@ async function handler(ctx) {
});
const $ = load(response.data);
const list = $('#gs_res_ccl_mid .gs_r.gs_or.gs_scl .gs_ri').get();
const list = $('#gs_res_ccl_mid .gs_r.gs_or.gs_scl .gs_ri').toArray();
const out = list.map((item) => {
const $ = load(item);
+3 -3
View File
@@ -37,15 +37,15 @@ async function handler() {
const $ = load(response.data);
const list = $('ul.list.whlist li')
.slice(0, 10)
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: new URL(a.attr('href'), `http://www.chinatax.gov.cn`).toString(),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
+3 -3
View File
@@ -34,12 +34,12 @@ async function handler(ctx) {
const $ = load(response.data);
const title = $('span#navigation').children('a').last().text();
const list = $('ul.ul_art_row')
.map((_, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('a').text().trim(),
link: $(item).find('a').attr('href'),
pubDate: timezone(parseDate($(item).find('li.li_art_date').text().trim()), +8),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
+3 -3
View File
@@ -42,7 +42,8 @@ async function handler() {
const $ = load(listPage.data);
const list = $('.table1 tbody tr')
.slice(1)
.map((_, tr) => {
.toArray()
.map((tr) => {
tr = $(tr);
return {
@@ -50,8 +51,7 @@ async function handler() {
link: baseUrl + tr.find('td[title] > a').attr('href'),
author: tr.find('td:last').text(),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+2 -2
View File
@@ -48,7 +48,8 @@ async function handler(ctx) {
const $ = load(response.data);
const list = $('.tg_tb1')
.map((_, item) => {
.toArray()
.map((item) => {
const i = $(item);
const id = i.prop('onclick').match(/openDetail\('(\d+)'\)/)?.[1] || '';
return {
@@ -58,7 +59,6 @@ async function handler(ctx) {
pubDate: '',
};
})
.get()
.filter((e) => e.link);
const items = await Promise.all(
list.map((item) =>
@@ -50,25 +50,23 @@ async function handler() {
return {
title: '济南卫建委-执业考试通知',
link: `${baseUrl}/col/col14418/index.html`,
item: list
.map((_, item) => {
// 获取每个item对应的html字符串
item = $(item).text();
item: list.toArray().map((item) => {
// 获取每个item对应的html字符串
item = $(item).text();
// 解析上一步中的html
const html = load(item);
// 解析上一步中的html
const html = load(item);
const title = html('td[width="620"] a').attr('title');
const link = html('td[width="620"] a').attr('href');
const date = timezone(parseDate(html('td[width="100"]').text()), +8);
return {
title,
description: title,
pubDate: date,
link,
author: '济南市卫生健康委员会',
};
})
.get(),
const title = html('td[width="620"] a').attr('title');
const link = html('td[width="620"] a').attr('href');
const date = timezone(parseDate(html('td[width="100"]').text()), +8);
return {
title,
description: title,
pubDate: date,
link,
author: '济南市卫生健康委员会',
};
}),
};
}
+3 -3
View File
@@ -52,7 +52,8 @@ async function handler(ctx) {
const list = all
.find(`div:nth-child(${columns[cate].order})`)
.find('.mobile_none li , .mobile_clear li')
.map((_, item) => {
.toArray()
.map((item) => {
const title = $(item).find('a.cjcx_biaob').text().trim();
const href = $(item).find('a').attr('href');
@@ -69,8 +70,7 @@ async function handler(ctx) {
title,
link,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
+6 -6
View File
@@ -38,11 +38,11 @@ async function handler(ctx) {
const indexContent = load(cookieResponse.data);
const title = indexContent('div.dqwz > a:nth-child(4)').text();
const dataRequestUrl = indexContent('div.lmy_main_rb > script:nth-child(2)')
.map((_, item) => ({
.toArray()
.map((item) => ({
url: `${rootUrl}${indexContent(item).attr('url')}`,
queryData: JSON.parse(indexContent(item).attr('querydata').replaceAll('"', '|').replaceAll("'", '"').replaceAll('|', '"')),
}))
.get()[0];
}))[0];
const dataUrl = `${dataRequestUrl.url}?${Object.keys(dataRequestUrl.queryData)
.map((key) => `${key}=${dataRequestUrl.queryData[key]}`)
@@ -56,12 +56,12 @@ async function handler(ctx) {
});
const $ = load(response.data.data.html);
const list = $('ul > li')
.map((_, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('a').text(),
link: new URL($(item).find('a').attr('href'), rootUrl).href,
pubDate: parseDate($(item).find('span').text(), 'YYYY-MM-DD'),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>
+6 -6
View File
@@ -37,11 +37,11 @@ async function handler() {
const cookie = cookieResponse.headers['set-cookie'][0].split(';')[0];
const indexContent = load(cookieResponse.data);
const dataRequestUrl = indexContent('div.clist_con > script:nth-child(2)')
.map((_, item) => ({
.toArray()
.map((item) => ({
url: `${rootUrl}${indexContent(item).attr('url')}`,
queryData: JSON.parse(indexContent(item).attr('querydata').replaceAll('"', '|').replaceAll("'", '"').replaceAll('|', '"')),
}))
.get()[0];
}))[0];
const dataUrl = `${dataRequestUrl.url}?${Object.keys(dataRequestUrl.queryData)
.map((key) => `${key}=${dataRequestUrl.queryData[key]}`)
@@ -55,12 +55,12 @@ async function handler() {
});
const $ = load(response.data.data.html);
const list = $('ul > li')
.map((_, item) => ({
.toArray()
.map((item) => ({
title: $(item).find('a').text(),
link: new URL($(item).find('a').attr('href'), rootUrl).href,
pubDate: parseDate($(item).find('span').text(), 'YYYY-MM-DD'),
}))
.get();
}));
const items = await Promise.all(
list.map((item) =>

Some files were not shown because too many files have changed in this diff Show More