From aedcc010b51be9c887f890c8a2b90bea4ec083b4 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 23 Jul 2024 18:09:16 +0800 Subject: [PATCH] feat: get default view from rsshub route --- src/renderer/src/hono.ts | 1 + src/renderer/src/lib/utils.ts | 22 +++++++++++++ .../modules/discover/content-components.tsx | 4 +-- src/renderer/src/modules/discover/types.ts | 31 ++++++++++++++++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/hono.ts b/src/renderer/src/hono.ts index 5e5cc3c1c..0d201a835 100644 --- a/src/renderer/src/hono.ts +++ b/src/renderer/src/hono.ts @@ -3041,6 +3041,7 @@ declare const _routes: hono_hono_base.HonoBase) => { } return newObj } + +const rsshubCategoryMap: Partial> = { + "design": FeedViewType.Pictures, + "forecast": FeedViewType.Notifications, + "live": FeedViewType.Notifications, + "picture": FeedViewType.Pictures, + "program-update": FeedViewType.Notifications, + "social-media": FeedViewType.SocialMedia, +} + +export const getViewFromRoute = (route: RSSHubRoute) => { + if (route.view) { + return route.view + } + for (const categories of route.categories) { + if (rsshubCategoryMap[categories]) { + return rsshubCategoryMap[categories] + } + } +} diff --git a/src/renderer/src/modules/discover/content-components.tsx b/src/renderer/src/modules/discover/content-components.tsx index bd5c10b21..f16f25428 100644 --- a/src/renderer/src/modules/discover/content-components.tsx +++ b/src/renderer/src/modules/discover/content-components.tsx @@ -20,7 +20,7 @@ import { parseRegexpPathParams, regexpPathToPath, } from "@renderer/lib/path-parser" -import { cn } from "@renderer/lib/utils" +import { cn, getViewFromRoute } from "@renderer/lib/utils" import { omit } from "lodash-es" import type { FC } from "react" import { @@ -146,7 +146,7 @@ export const DiscoverFeedForm = ({ try { const fillRegexpPath = regexpPathToPath(route.path, data) const url = `rsshub://${routePrefix}${fillRegexpPath}` - const defaultView = getSidebarActiveView() as FeedViewType + const defaultView = getViewFromRoute(route) || getSidebarActiveView() as FeedViewType present({ title: "Add follow", diff --git a/src/renderer/src/modules/discover/types.ts b/src/renderer/src/modules/discover/types.ts index bda351b26..9de142ea0 100644 --- a/src/renderer/src/modules/discover/types.ts +++ b/src/renderer/src/modules/discover/types.ts @@ -1,3 +1,5 @@ +import type { FeedViewType } from "@renderer/lib/enum" + export type RSSHubRouteType = Record export interface RSSHubRouteDeclaration { routes: Routes @@ -17,13 +19,14 @@ export type RSSHubParameterObject = { export type RSSHubParameter = string | RSSHubParameterObject export type RSSHubRoute = { path: string - categories: string[] + categories: RSSHubCategory[] example: string parameters: Record name: string maintainers: string[] location: string description: string + view?: FeedViewType // features: Features // radar: RadarItem[] @@ -41,3 +44,29 @@ export type RSSHubRoute = { // source: string[] // target: string // } + +export type RSSHubCategory = + | "popular" + | "social-media" + | "new-media" + | "traditional-media" + | "bbs" + | "blog" + | "programming" + | "design" + | "live" + | "multimedia" + | "picture" + | "anime" + | "program-update" + | "university" + | "forecast" + | "travel" + | "shopping" + | "game" + | "reading" + | "government" + | "study" + | "journal" + | "finance" + | "other"