-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(route): add Nicesss呦糖社 #14364
feat(route): add Nicesss呦糖社 #14364
Changes from all commits
cd39d13
c002e29
abb8f2f
01642f6
f44d47e
8025f2c
18dc959
df87a65
8188d54
7a76157
e4fd5c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const utils = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const limit = ctx.params.limit || 20; | ||
const items = []; | ||
const categoryID = ctx.params.category_id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
let pages = Math.ceil(limit / 10); | ||
pages = pages > 10 ? 10 : pages; | ||
const urls = Array.from({ length: pages }, (_, i) => `https://www.nicesss.com/wp-json/wp/v2/posts?categories=${categoryID}&page=${i + 1}`); | ||
|
||
const itemPromises = urls.map((url) => utils.processUrl(url, ctx)); | ||
const allItems = await Promise.all(itemPromises); | ||
items.push(...allItems.flat()); | ||
Comment on lines
+8
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract data from the first page only. As mentioned before in #14364 (review), you can adjust the no. of articles returned in the API using |
||
|
||
const category = await utils.processCategory(ctx, categoryID); | ||
|
||
ctx.state.data = { | ||
title: `呦糖社 - “${category.name}”Category结果`, | ||
link: category.link, | ||
description: `呦糖社 - “${category.name}”Category结果`, | ||
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png', | ||
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
item: items.slice(0, limit), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const utils = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const limit = ctx.params.limit || 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the common parameter |
||
const items = []; | ||
|
||
let pages = Math.ceil(limit / 10); | ||
pages = pages > 10 ? 10 : pages; | ||
const urls = Array.from({ length: pages }, (_, i) => `https://www.nicesss.com/wp-json/wp/v2/posts?page=${i + 1}`); | ||
|
||
const itemPromises = urls.map((url) => utils.processUrl(url, ctx)); | ||
const allItems = await Promise.all(itemPromises); | ||
items.push(...allItems.flat()); | ||
Comment on lines
+7
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract data from the first page only. As mentioned before in #14364 (review), you can adjust the no. of articles returned in the API using |
||
|
||
ctx.state.data = { | ||
title: '呦糖社 - 最新', | ||
link: 'https://www.nicesss.com/', | ||
description: '呦糖社 - 最新', | ||
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png', | ||
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
item: items.slice(0, limit), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
'/:limit?': ['Steven-Fake'], | ||
'/search/:keyword/:limit?': ['Steven-Fake'], | ||
'/tag/:tag_id/:limit?': ['Steven-Fake'], | ||
'/category/:category_id/:limit?': ['Steven-Fake'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module.exports = { | ||
'nicesss.com': { | ||
_name: 'Nicesss 呦糖社 ', | ||
www: [ | ||
{ | ||
title: '首页 Homepage', | ||
docs: 'https://docs.rsshub.app/routes/picture#you-tang-she', | ||
source: ['/', '/page/:page'], | ||
target: `/nicesss/`, | ||
}, | ||
{ | ||
title: '搜索 Search', | ||
docs: 'https://docs.rsshub.app/routes/picture#you-tang-she', | ||
source: ['/', '/page/:page'], | ||
target: (_, url) => `/nicesss/search/${new URL(url).searchParams.get('s')}`, | ||
}, | ||
{ | ||
title: '标签 Tag', | ||
docs: 'https://docs.rsshub.app/routes/picture#you-tang-she', | ||
source: ['/archives/tag/:tag', '/archives/tag/:tag/page/:page?'], | ||
target: (params) => `/nicesss/tag/${params.tag}`, | ||
}, | ||
{ | ||
title: '类别 Category', | ||
docs: 'https://docs.rsshub.app/routes/picture#you-tang-she', | ||
source: ['/:category/', '/:category/page/:page'], | ||
target: (_, url) => { | ||
const param = new URL(url).pathname.split('/').find(Boolean); | ||
return param === 'archives' || param === 'page' || param === undefined ? `/nicesss/` : `/nicesss/category/${param}`; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = (router) => { | ||
router.get('/:limit?', require('./index')); | ||
router.get('/search/:keyword/:limit?', require('./search')); | ||
router.get('/tag/:tag_id/:limit?', require('./tag')); | ||
router.get('/category/:category_id/:limit?', require('./category')); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const utils = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const limit = ctx.params.limit || 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the common parameter |
||
const items = []; | ||
const keyword = decodeURIComponent(ctx.params.keyword); | ||
|
||
let pages = Math.ceil(limit / 10); | ||
pages = pages > 10 ? 10 : pages; | ||
const urls = Array.from({ length: pages }, (_, i) => `https://www.nicesss.com/wp-json/wp/v2/posts?search=${keyword}&page=${i + 1}`); | ||
|
||
const itemPromises = urls.map((url) => utils.processUrl(url, ctx)); | ||
const allItems = await Promise.all(itemPromises); | ||
items.push(...allItems.flat()); | ||
Comment on lines
+8
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract data from the first page only. As mentioned before in #14364 (review), you can adjust the no. of articles returned in the API using |
||
|
||
ctx.state.data = { | ||
title: `呦糖社 - “${keyword}”搜索结果`, | ||
link: `https://www.nicesss.com/?s=${keyword}`, | ||
description: `呦糖社 - “${keyword}”搜索结果`, | ||
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png', | ||
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
item: items.slice(0, limit), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const utils = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const limit = ctx.params.limit || 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the common parameter |
||
const items = []; | ||
const tagID = ctx.params.tag_id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
let pages = Math.ceil(limit / 10); | ||
pages = pages > 10 ? 10 : pages; | ||
const urls = Array.from({ length: pages }, (_, i) => `https://www.nicesss.com/wp-json/wp/v2/posts?tags=${tagID}&page=${i + 1}`); | ||
|
||
const itemPromises = urls.map((url) => utils.processUrl(url, ctx)); | ||
const allItems = await Promise.all(itemPromises); | ||
items.push(...allItems.flat()); | ||
|
||
const tag = await utils.processTag(ctx, tagID); | ||
Comment on lines
+8
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract data from the first page only. As mentioned before in #14364 (review), you can adjust the no. of articles returned in the API using |
||
|
||
ctx.state.data = { | ||
title: `呦糖社 - “${tag.name}”Tag结果`, | ||
link: tag.link, | ||
description: `呦糖社 - “${tag.name}”Tag结果`, | ||
image: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/logo/logo-light.png', | ||
icon: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
logo: 'https://www.nicesss.com/wp-content/themes/ripro/assets/images/favicon/favicon.png', | ||
item: items.slice(0, limit), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
function parseContent(content) { | ||
// 处理Content | ||
const $ = cheerio.load(content); | ||
$('noscript').remove(); // 删除所有的<noscript>元素 | ||
$('img').each(function () { | ||
// 更新所有<img>元素的src属性为data-srcset的值 | ||
const srcset = $(this).attr('data-srcset'); | ||
if (srcset) { | ||
$(this).attr('src', srcset); | ||
} | ||
}); | ||
return $.html(); | ||
} | ||
|
||
async function processCategory(ctx, id) { | ||
// 获取Category | ||
return await ctx.cache.tryGet(`nicesss_categories:${id}`, async () => { | ||
const { data: response } = await got(`https://www.nicesss.com/wp-json/wp/v2/categories/${id}`); | ||
return response; | ||
}); | ||
} | ||
|
||
async function processTag(ctx, id) { | ||
// 获取Tag | ||
return await ctx.cache.tryGet(`nicesss_tags:${id}`, async () => { | ||
const { data: response } = await got(`https://www.nicesss.com/wp-json/wp/v2/tags/${id}`); | ||
return response; | ||
}); | ||
} | ||
|
||
async function processItems(ctx, response) { | ||
let items = response.map(async (item) => ({ | ||
title: item.title.rendered, | ||
link: item.link, | ||
description: parseContent(item.content.rendered), | ||
author: await processCategory(ctx, item.categories[0]).then((category) => category.name), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
category: item.tags, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As mentioned before in #14364 (review), you can include the |
||
guid: item.guid.rendered, | ||
pubDate: parseDate(item.date_gmt), | ||
updated: parseDate(item.modified_gmt), | ||
})); | ||
items = await Promise.all(items); | ||
return items; | ||
} | ||
|
||
module.exports = { | ||
processUrl: async (url, ctx) => { | ||
const { data: json } = await got(url); | ||
return await processItems(ctx, json); | ||
}, | ||
processCategory, | ||
processTag, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the common parameter
limit
fromctx.query.limit
.docs: https://docs.rsshub.app/parameter#limit-entries