From d9d807ab1297302bcba37d0b6fba684cc6201ecb Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sat, 15 Nov 2025 00:15:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E5=B0=BE=E5=B7=B4=E8=A7=86=E9=A2=91=20(#20470)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 数字尾巴视频 * fix pubDate --- lib/routes/dgtle/templates/description.art | 20 ++ lib/routes/dgtle/video.ts | 202 +++++++++++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 lib/routes/dgtle/video.ts diff --git a/lib/routes/dgtle/templates/description.art b/lib/routes/dgtle/templates/description.art index 249654e7e..5b807209c 100644 --- a/lib/routes/dgtle/templates/description.art +++ b/lib/routes/dgtle/templates/description.art @@ -12,6 +12,26 @@ {{ /each }} {{ /if }} +{{ if videos }} + {{ each videos video }} + {{ if video?.src }} + + {{ /if }} + {{ /each }} +{{ /if }} + {{ if intro }}
{{ intro }}{{ /if }} diff --git a/lib/routes/dgtle/video.ts b/lib/routes/dgtle/video.ts new file mode 100644 index 000000000..9b6147722 --- /dev/null +++ b/lib/routes/dgtle/video.ts @@ -0,0 +1,202 @@ +import { type Data, type DataItem, type Route, ViewType } from '@/types'; + +import { art } from '@/utils/render'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { parseRelativeDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +import { type CheerioAPI, type Cheerio, load } from 'cheerio'; +import type { Element } from 'domhandler'; +import { type Context } from 'hono'; +import path from 'node:path'; + +export const handler = async (ctx: Context): Promise => { + const limit: number = Number.parseInt(ctx.req.query('limit') ?? '18', 10); + + const baseUrl: string = 'https://www.dgtle.com'; + const targetUrl: string = new URL('video', baseUrl).href; + const apiUrl: string = new URL('video/list/1', baseUrl).href; + + const targetResponse = await ofetch(targetUrl); + const $: CheerioAPI = load(targetResponse); + const language = $('html').attr('lang') ?? 'zh-CN'; + + const response = await ofetch(apiUrl); + + let items: DataItem[] = []; + + items = response.data.list.slice(0, limit).map((item): DataItem => { + const title: string = item.title; + const image: string | undefined = item.cover?.split(/\?/)?.[0]; + const description: string | undefined = art(path.join(__dirname, 'templates/description.art'), { + images: image + ? [ + { + src: image, + alt: title, + }, + ] + : undefined, + intro: item.description, + }); + const linkUrl: string | undefined = item.url; + const authors: DataItem['author'] = [ + { + name: item.author.username, + url: undefined, + avatar: item.author.avatar_path?.split(/\?/)?.[0], + }, + ]; + const guid: string = `dgtle-${item.id}`; + + const processedItem: DataItem = { + title, + description, + link: linkUrl, + author: authors, + guid, + id: guid, + content: { + html: description, + text: description, + }, + image, + banner: image, + language, + enclosure_length: item.duration, + }; + + return processedItem; + }); + + items = await Promise.all( + items.map((item) => { + if (!item.link) { + return item; + } + + return cache.tryGet(item.link, async (): Promise