feat(route): add route "4KHD" (#18308)

This commit is contained in:
AiraNadih
2025-02-11 00:53:47 +08:00
committed by GitHub
parent 46368b2c6c
commit 46877a1c44
6 changed files with 141 additions and 0 deletions
+28
View File
@@ -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;
+48
View File
@@ -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)),
};
}
+4
View File
@@ -0,0 +1,4 @@
const SUB_NAME_PREFIX = '4KHD';
const SUB_URL = 'https://www.4khd.com/';
export { SUB_NAME_PREFIX, SUB_URL };
+41
View File
@@ -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)),
};
}
+8
View File
@@ -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',
};
+12
View File
@@ -0,0 +1,12 @@
interface WPPost {
title: {
rendered: string;
};
content: {
rendered: string;
};
date_gmt: string;
link: string;
}
export type { WPPost };