From fb20835d67c17dcd17e24b5c0a4afd024200765b Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Sat, 28 Dec 2024 22:14:30 -0500 Subject: [PATCH] Simplify page description --- www/components/index/item.tsx | 2 +- www/hooks/use-description-parse.tsx | 10 ++++++++-- www/hooks/use-package.tsx | 13 +++++-------- www/routes/package.tsx | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/www/components/index/item.tsx b/www/components/index/item.tsx index 15652c1..dcec6ae 100644 --- a/www/components/index/item.tsx +++ b/www/components/index/item.tsx @@ -14,7 +14,7 @@ export function PackageIndexItem(props: PackageIndexItemProps) { {pkg.workspace}

- {yield* pkg.MDXDescription()} + {yield* pkg.description()}

); diff --git a/www/hooks/use-description-parse.tsx b/www/hooks/use-description-parse.tsx index 9511dff..8f6998a 100644 --- a/www/hooks/use-description-parse.tsx +++ b/www/hooks/use-description-parse.tsx @@ -10,7 +10,13 @@ import remarkParse from "npm:remark-parse@11.0.0"; import remarkRehype from "npm:remark-rehype@11.1.1"; import { trimAfterHR } from "../lib/trim-after-hr.ts"; -export function* useDescriptionParse(markdown: string): Operation { +export function* useDescription(markdown: string): Operation { + const file = yield* useMarkdownFile(markdown); + + return file.data?.meta?.description ?? ""; +} + +export function* useMarkdownFile(markdown: string): Operation { return yield* call(() => unified() .use(remarkParse) @@ -25,4 +31,4 @@ export function* useDescriptionParse(markdown: string): Operation { markdown, ) ); -} +} \ No newline at end of file diff --git a/www/hooks/use-package.tsx b/www/hooks/use-package.tsx index 7740a66..9b76577 100644 --- a/www/hooks/use-package.tsx +++ b/www/hooks/use-package.tsx @@ -1,12 +1,11 @@ import { all, call, createContext, type Operation, type Result, Ok, Err } from "effection"; -import { dirname, SEPARATOR } from "jsr:@std/path@1.0.6"; -import type { VFile } from "npm:vfile@6.0.3"; +import { SEPARATOR } from "jsr:@std/path@1.0.6"; import { z } from "npm:zod@3.23.8"; import type { JSXElement } from "revolution"; import { type DocNode, useDenoDoc } from "./use-deno-doc.tsx"; import { useMDX } from "./use-mdx.tsx"; -import { useDescriptionParse } from "./use-description-parse.tsx"; +import { useDescription } from "./use-description-parse.tsx"; import { PackageDetailsResult, PackageScoreResult, @@ -97,7 +96,7 @@ export interface Package { */ docs: Record>; MDXContent: () => Operation; - MDXDescription: () => Operation; + description: () => Operation; } export type RenderableDocNode = DocNode & { @@ -294,10 +293,8 @@ export function* createPackage(config: PackageConfig) { return mod.default({}); }, - *MDXDescription(): Operation { - let file: VFile = yield* useDescriptionParse(config.readme); - - return file.data?.meta?.description ? file.data?.meta?.description : ""; + *description(): Operation { + return yield* useDescription(config.readme); }, }; } diff --git a/www/routes/package.tsx b/www/routes/package.tsx index 96d7337..99246dc 100644 --- a/www/routes/package.tsx +++ b/www/routes/package.tsx @@ -42,7 +42,7 @@ export function packageRoute(): SitemapRoute { const AppHTML = yield* useAppHtml({ title: `${pkg.packageName}`, - description: yield* pkg.MDXDescription(), + description: yield* pkg.description(), pageTitle: `${pkg.packageName} | Effection Contrib`, });