From f6f787bc0713a7fca5b64897412796de8c1463b2 Mon Sep 17 00:00:00 2001 From: yjl9903 Date: Tue, 1 Oct 2024 19:51:13 +0800 Subject: [PATCH] feat(web): add rss feed url --- apps/frontend/web/app/layouts/Layout.tsx | 26 +++++++++---------- apps/frontend/web/app/routes/_index/route.tsx | 15 ++++++++--- .../app/routes/resources.($page)/route.tsx | 14 +++++++--- apps/frontend/web/app/utils/feed.ts | 25 ++++++++++++++++++ apps/frontend/web/uno.config.ts | 4 +++ 5 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 apps/frontend/web/app/utils/feed.ts diff --git a/apps/frontend/web/app/layouts/Layout.tsx b/apps/frontend/web/app/layouts/Layout.tsx index 96403e00f..0666bc416 100644 --- a/apps/frontend/web/app/layouts/Layout.tsx +++ b/apps/frontend/web/app/layouts/Layout.tsx @@ -11,12 +11,12 @@ const MaxPaddingTop = 152; const MaxPaddingBottom = 96; const SearchHeight = NavHeight; -export default function Layout(props: { children?: React.ReactNode; rss?: string }) { - const { rss } = props; +export default function Layout(props: { children?: React.ReactNode; feedURL?: string }) { + const { feedURL } = props; return (
- +
{ }; }; -function Hero(props: { rss?: string }) { +function Hero(props: { feedURL?: string }) { const { height, paddingTop, paddingBottom, injectScript } = useHero(); return ( @@ -79,7 +79,7 @@ function Hero(props: { rss?: string }) { suppressHydrationWarning={true} style={{ height: `${height}px` }} >
-
+
@@ -129,27 +129,27 @@ function Header(props: { rss?: string }) { 🌸
- + 动画
- + 字幕组
- + 资源
- {rss && ( + {feedURL && ( RSS diff --git a/apps/frontend/web/app/routes/_index/route.tsx b/apps/frontend/web/app/routes/_index/route.tsx index 0b5353257..1a99e3e1c 100644 --- a/apps/frontend/web/app/routes/_index/route.tsx +++ b/apps/frontend/web/app/routes/_index/route.tsx @@ -1,10 +1,12 @@ -import type { Resource } from 'animegarden'; - -import { useLoaderData, useNavigate } from '@remix-run/react'; +import { useMemo } from 'react'; +import { useLoaderData, useLocation } from '@remix-run/react'; import { type LoaderFunctionArgs, type MetaFunction, json } from '@remix-run/cloudflare'; +import type { Resource } from 'animegarden'; + import Layout from '~/layouts/Layout'; import Resources from '~/components/Resources'; +import { generateFeed } from '~/utils/feed'; import { fetchResources } from '~/utils'; import { Error } from '../resources.($page)/Error'; @@ -26,10 +28,15 @@ export const meta: MetaFunction = () => { }; export default function Index() { + const location = useLocation(); const { ok, resources, timestamp } = useLoaderData(); + const feedURL = useMemo( + () => `/feed.xml?filter=${generateFeed(new URLSearchParams(location.search))}`, + [location] + ); return ( - +
{ok ? ( { export default function ResourcesIndex() { const location = useLocation(); const { ok, resources, complete, filter, page, timestamp } = useLoaderData(); + const feedURL = useMemo( + () => `/feed.xml?filter=${generateFeed(new URLSearchParams(location.search))}`, + [location] + ); return ( - +
{ok ? ( <> diff --git a/apps/frontend/web/app/utils/feed.ts b/apps/frontend/web/app/utils/feed.ts new file mode 100644 index 000000000..011cef2f3 --- /dev/null +++ b/apps/frontend/web/app/utils/feed.ts @@ -0,0 +1,25 @@ +import { parseSearchURL, type ResolvedFilterOptions } from 'animegarden'; + +import { removeQuote } from './string'; + +export function generateFeed(...params: URLSearchParams[]) { + const filters: any[] = []; + for (const param of params) { + const filter: Partial = parseSearchURL(param); + // Hack: manually remove duplicate + if (!filter.provider && filter.duplicate === false) { + delete filter['duplicate']; + } + if (filter.search) { + filter.search = removeQuote(filter.search); + } + if (filter.page) { + delete filter['page']; + } + if (filter.pageSize) { + delete filter['pageSize']; + } + filters.push({ ...filter }); + } + return encodeURIComponent(JSON.stringify(filters)); +} diff --git a/apps/frontend/web/uno.config.ts b/apps/frontend/web/uno.config.ts index bd9c739da..1a6083630 100644 --- a/apps/frontend/web/uno.config.ts +++ b/apps/frontend/web/uno.config.ts @@ -75,6 +75,10 @@ export default defineConfig({ }, theme: { colors: { + zinc: { + '25': '#fbfbfc', + '50': '#f9f9fa' + }, 'main-50': '#fafafa', 'main-100': '#f5f5f5', 'main-200': '#e5e5e5',