diff --git a/src/components/ReferenceDirectory/index.astro b/src/components/ReferenceDirectory/index.astro new file mode 100644 index 0000000000..ee13f92967 --- /dev/null +++ b/src/components/ReferenceDirectory/index.astro @@ -0,0 +1,92 @@ +--- +import type { ReferenceDocContentItem } from "@/src/content/types"; +import flask from "@src/content/ui/images/icons/flask.svg?raw"; +import warning from "@src/content/ui/images/icons/warning.svg?raw"; + +type ReferenceDirectoryEntry = ReferenceDocContentItem & { + data: { + path: string; + title: string; + description: string; + beta?: boolean; + deprecated?: boolean; + }; +}; + +interface Props { + categoryData: { + name: string; + subcats: { + name: string; + entry?: ReferenceDirectoryEntry; + entries: ReferenceDirectoryEntry[]; + }[]; + }[]; +} + +const { categoryData } = Astro.props; + +const getOneLineDescription = (description: string): string => { + const firstParagraphRegex = /^
(.*?)<\/p>/; + let [oneLineDescription] = + description.replace(/\n/g, " ").trim().match(firstParagraphRegex) ?? []; + + if (!oneLineDescription && description) oneLineDescription = description; + + return ( + oneLineDescription + ?.replace(/^
|<\/p>$/g, "")
+ .replace(/<\/?code>/g, "")
+ .replace(/(\d+?)(\d+?)<\/sup><\/var>/g, "$1^$2")
+ .replace(/|<\/a>/g, "")
+ .split(/\.\s|\?\s|!\s|।\s|。/)[0] ?? ""
+ );
+};
+---
+
\ No newline at end of file
diff --git a/src/components/ReferenceDirectoryWithFilter/index.tsx b/src/components/ReferenceDirectoryWithFilter/index.tsx
index 5ce59bcd73..a31c922343 100644
--- a/src/components/ReferenceDirectoryWithFilter/index.tsx
+++ b/src/components/ReferenceDirectoryWithFilter/index.tsx
@@ -1,202 +1,17 @@
-import type { ReferenceDocContentItem } from "@/src/content/types";
-import { useMemo, useRef, useState } from "preact/hooks";
+import { useRef, useState } from "preact/hooks";
import { type JSX } from "preact";
import { Icon } from "../Icon";
-import flask from "@src/content/ui/images/icons/flask.svg?raw";
-import warning from "@src/content/ui/images/icons/warning.svg?raw";
-
-type ReferenceDirectoryEntry = ReferenceDocContentItem & {
- data: {
- path: string;
- title: string;
- description: string;
- };
-};
-
-type FilteredCategoryData = {
- name: string;
- subcats: {
- name: string;
- entries: ReferenceDirectoryEntry[];
- }[];
-};
type ReferenceDirectoryWithFilterProps = {
- categoryData: {
- name: string;
- subcats: {
- name: string;
- entry?: ReferenceDirectoryEntry;
- entries: ReferenceDirectoryEntry[];
- }[];
- }[];
uiTranslations: { [key: string]: string };
};
-/**
- * Convert Reference description to one-line description
- * @param description String description
- * @returns One-line description
- */
-const getOneLineDescription = (description: string): string => {
- // Matches first paragraph tag, remove HTML tags, then trim to first fullstop
- const firstParagraphRegex = /^ (.*?)<\/p>/;
- let [oneLineDescription] =
- description.replace(/\n/g, " ").trim().match(firstParagraphRegex) ?? [];
-
- if (!oneLineDescription && description) {
- oneLineDescription = description;
- }
-
- if (oneLineDescription) {
- oneLineDescription = oneLineDescription
- .replace(/^ |<\/p>$/g, "")
- .replace(/<\/?code>/g, "")
- .replace(/(\d+?)(\d+?)<\/sup><\/var>/g, "$1^$2")
- .replace(/|<\/a>/g, "")
- .split(/\.\s|\?\s|!\s|।\s|。/)[0];
- }
-
- return oneLineDescription ?? "";
-};
-
export const ReferenceDirectoryWithFilter = ({
- categoryData,
uiTranslations,
}: ReferenceDirectoryWithFilterProps) => {
const [searchKeyword, setSearchKeyword] = useState("");
const inputRef = useRef{subcat.name}
-
- ) : (
-
- {subcat.name}
-
- )}
- >
- );
- };
-
- const renderCategoryData = () => {
- if (filteredEntries.length === 0) {
- return
- {category.name}
-
- {category.subcats.map((subcat) => (
-