mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): 全现在首页 (#8142)
This commit is contained in:
@@ -1,48 +1,7 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
const currentUrl = `${rootUrl}/column/${ctx.params.id}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const id = ctx.params.id;
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.post-list .post')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('p.title').text();
|
||||
item.author = content('a.single-name').eq(0).text();
|
||||
item.description = content('#article-content').html();
|
||||
item.pubDate = new Date(detailResponse.data.match(/time:"(.*?)"\}/)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('p.name').text()} - 全现在`,
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
description: $('p.desc').text(),
|
||||
};
|
||||
ctx.state.data = await utils.processItems(ctx, `${utils.rootUrl}/column/${id}`);
|
||||
};
|
||||
|
||||
@@ -1,47 +1,5 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.post-list .post')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('p.title').text();
|
||||
item.author = content('a.single-name').eq(0).text();
|
||||
item.description = content('#article-content').html();
|
||||
item.pubDate = new Date(detailResponse.data.match(/time:"(.*?)"\}/)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '首页 - 全现在',
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
description: $('p.desc').text(),
|
||||
};
|
||||
ctx.state.data = await utils.processItems(ctx, utils.rootUrl);
|
||||
};
|
||||
|
||||
@@ -1,47 +1,7 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
const currentUrl = `${rootUrl}/tag/${ctx.params.id}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const id = ctx.params.id;
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.post-list .post')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('p.title').text();
|
||||
item.author = content('a.single-name').eq(0).text();
|
||||
item.description = content('#article-content').html();
|
||||
item.pubDate = new Date(detailResponse.data.match(/time:"(.*?)"\}/)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('p.title').eq(0).text()} - 全现在`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
ctx.state.data = await utils.processItems(ctx, `${utils.rootUrl}/tag/${id}`);
|
||||
};
|
||||
|
||||
@@ -1,47 +1,7 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
const currentUrl = `${rootUrl}/user/${ctx.params.id}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const id = ctx.params.id;
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('.post-list .post')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('p.title').text();
|
||||
item.author = content('a.single-name').eq(0).text();
|
||||
item.description = content('#article-content').html();
|
||||
item.pubDate = new Date(detailResponse.data.match(/time:"(.*?)"\}/)[1] + ' GMT+8').toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('p.title').eq(0).text()} - 全现在`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
ctx.state.data = await utils.processItems(ctx, `${utils.rootUrl}/user/${id}`);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const rootUrl = 'https://www.allnow.com';
|
||||
|
||||
module.exports = {
|
||||
rootUrl,
|
||||
|
||||
processItems: async (ctx, currentUrl) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.post-list .post')
|
||||
.slice(0, ctx.params.limit ? parseInt(ctx.params.limit) : 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
|
||||
return {
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.author = detailResponse.data.match(/authorName:"(.*?)",avatar/)[1];
|
||||
item.title = content('title')
|
||||
.text()
|
||||
.replace(/-全现在官方网站/, '');
|
||||
item.pubDate = timezone(parseDate(detailResponse.data.match(/time:"(.*)",type/)[1]), +8);
|
||||
item.category = detailResponse.data
|
||||
.match(/tags:\[(.*)\],columns/)[1]
|
||||
.split('},')
|
||||
.map((category) => category.match(/title:"(.*)"/)[1]);
|
||||
item.description = content('#article-content').html() ?? content('.summary').html() ?? '';
|
||||
|
||||
content('video').each(function () {
|
||||
item.description += `<video src="https:${content(this).attr('src')}" controls></video>`;
|
||||
});
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
description: $('.desc').eq(0).text(),
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user