feat: get default view from rsshub route

This commit is contained in:
DIYgod
2024-07-23 18:09:16 +08:00
parent 5d8bf9f454
commit aedcc010b5
4 changed files with 55 additions and 3 deletions
+1
View File
@@ -3041,6 +3041,7 @@ declare const _routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
categories: string[];
maintainers: string[];
location: string;
view?: number | undefined;
};
};
};
+22
View File
@@ -1,9 +1,11 @@
import type { RSSHubCategory, RSSHubRoute } from "@renderer/modules/discover/types"
import type { ClassValue } from "clsx"
import { clsx } from "clsx"
import { memoize } from "lodash-es"
import { twMerge } from "tailwind-merge"
import { FEED_COLLECTION_LIST, ROUTE_FEED_PENDING } from "../constants/app"
import { FeedViewType } from "./enum"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
@@ -150,3 +152,23 @@ export const omitObjectUndefinedValue = (obj: Record<string, any>) => {
}
return newObj
}
const rsshubCategoryMap: Partial<Record<RSSHubCategory, FeedViewType>> = {
"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]
}
}
}
@@ -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",
+30 -1
View File
@@ -1,3 +1,5 @@
import type { FeedViewType } from "@renderer/lib/enum"
export type RSSHubRouteType = Record<string, RSSHubRouteDeclaration>
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<string, RSSHubParameter>
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"