forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add route "4KHD" (DIYgod#18308)
- Loading branch information
Showing
6 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { WPPost } from './types'; | ||
|
||
const processImages = ($) => { | ||
$('a').each((_, elem) => { | ||
const $elem = $(elem); | ||
const largePhotoUrl = $elem.attr('href').replace('i0.wp.com/pic', 'img'); | ||
if (largePhotoUrl) { | ||
$elem.attr('href', largePhotoUrl); | ||
$elem.find('img').attr('src', largePhotoUrl); | ||
} | ||
}); | ||
}; | ||
|
||
function loadArticle(item: WPPost) { | ||
const article = load(item.content.rendered); | ||
processImages(article); | ||
|
||
return { | ||
title: item.title.rendered, | ||
description: article.html() ?? '', | ||
pubDate: parseDate(item.date_gmt), | ||
link: item.link, | ||
}; | ||
} | ||
|
||
export default loadArticle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Route } from '@/types'; | ||
import got from '@/utils/got'; | ||
import { SUB_NAME_PREFIX, SUB_URL } from './const'; | ||
import loadArticle from './article'; | ||
import { WPPost } from './types'; | ||
|
||
export const route: Route = { | ||
path: '/category/:category', | ||
categories: ['picture'], | ||
example: '/4khd/category/cosplay', | ||
parameters: { category: 'Category' }, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.4khd.com/pages/:category'], | ||
target: '/category/:category', | ||
}, | ||
], | ||
name: 'Category', | ||
maintainers: ['AiraNadih'], | ||
handler, | ||
url: 'www.4khd.com/', | ||
}; | ||
|
||
async function handler(ctx) { | ||
const limit = Number.parseInt(ctx.req.query('limit')) || 20; | ||
const category = ctx.req.param('category'); | ||
const categoryUrl = `${SUB_URL}pages/${category}/`; | ||
const slug = category === 'album' ? 'photo' : category; | ||
|
||
const { | ||
data: [{ id: categoryId }], | ||
} = await got(`${SUB_URL}wp-json/wp/v2/categories?slug=${slug}`); | ||
const { data: posts } = await got(`${SUB_URL}wp-json/wp/v2/posts?categories=${categoryId}&per_page=${limit}`); | ||
|
||
return { | ||
title: `${SUB_NAME_PREFIX} - Category: ${category}`, | ||
link: categoryUrl, | ||
item: posts.map((post) => loadArticle(post as WPPost)), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const SUB_NAME_PREFIX = '4KHD'; | ||
const SUB_URL = 'https://www.4khd.com/'; | ||
|
||
export { SUB_NAME_PREFIX, SUB_URL }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Route } from '@/types'; | ||
import got from '@/utils/got'; | ||
import { SUB_NAME_PREFIX, SUB_URL } from './const'; | ||
import loadArticle from './article'; | ||
import { WPPost } from './types'; | ||
|
||
export const route: Route = { | ||
path: '/', | ||
categories: ['picture'], | ||
example: '/4khd', | ||
parameters: {}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.4khd.com/'], | ||
target: '', | ||
}, | ||
], | ||
name: 'Latest', | ||
maintainers: ['AiraNadih'], | ||
handler, | ||
url: 'www.4khd.com/', | ||
}; | ||
|
||
async function handler(ctx) { | ||
const limit = Number.parseInt(ctx.req.query('limit')) || 20; | ||
const { data: posts } = await got(`${SUB_URL}wp-json/wp/v2/posts?per_page=${limit}`); | ||
|
||
return { | ||
title: `${SUB_NAME_PREFIX} - Latest`, | ||
link: SUB_URL, | ||
item: posts.map((post) => loadArticle(post as WPPost)), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: '4KHD', | ||
url: 'www.4khd.net', | ||
description: '4KHD - HD Beautiful Girls', | ||
lang: 'en', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
interface WPPost { | ||
title: { | ||
rendered: string; | ||
}; | ||
content: { | ||
rendered: string; | ||
}; | ||
date_gmt: string; | ||
link: string; | ||
} | ||
|
||
export type { WPPost }; |