From 7c1feab986be70cc4f04aee6351451690186e451 Mon Sep 17 00:00:00 2001 From: Reed Nelson Date: Sun, 14 Jan 2024 00:56:51 -0600 Subject: [PATCH] clean doc styling --- src/layouts/Search.tsx | 181 ----------------------- src/layouts/components/DocBrowser.astro | 14 +- src/layouts/components/DocContents.astro | 50 +++---- src/layouts/components/Header.astro | 85 +---------- src/layouts/components/SearchBar.astro | 86 +++++++++++ 5 files changed, 121 insertions(+), 295 deletions(-) delete mode 100755 src/layouts/Search.tsx create mode 100644 src/layouts/components/SearchBar.astro diff --git a/src/layouts/Search.tsx b/src/layouts/Search.tsx deleted file mode 100755 index 858393f..0000000 --- a/src/layouts/Search.tsx +++ /dev/null @@ -1,181 +0,0 @@ -import config from "@/config/config.json"; -import { humanize, plainify, slugify } from "@/lib/utils/textConverter"; -import Fuse from "fuse.js"; -import React, { useEffect, useRef, useState } from "react"; -import { - FaRegFolder, - FaRegUserCircle, - FaSearch, -} from "react-icons/fa/index.js"; - -const { summary_length, blog_folder } = config.settings; - -export type SearchItem = { - slug: string; - data: any; - content: any; -}; - -interface Props { - searchList: SearchItem[]; -} - -interface SearchResult { - item: SearchItem; - refIndex: number; -} - -const Search = ({ searchList }: Props) => { - const inputRef = useRef(null); - const [inputVal, setInputVal] = useState(""); - const [searchResults, setSearchResults] = useState([]); - - const handleChange = (e: React.FormEvent) => { - setInputVal(e.currentTarget.value); - }; - - const fuse = new Fuse(searchList, { - keys: ["data.title", "data.categories", "data.tags"], - includeMatches: true, - minMatchCharLength: 3, - threshold: 0.5, - }); - - useEffect(() => { - const searchUrl = new URLSearchParams(window.location.search); - const searchStr = searchUrl.get("q"); - if (searchStr) setInputVal(searchStr); - - setTimeout(function () { - inputRef.current!.selectionStart = inputRef.current!.selectionEnd = - searchStr?.length || 0; - }, 50); - }, []); - - useEffect(() => { - let inputResult = inputVal.length > 2 ? fuse.search(inputVal) : []; - setSearchResults(inputResult); - - if (inputVal.length > 0) { - const searchParams = new URLSearchParams(window.location.search); - searchParams.set("q", inputVal); - const newRelativePathQuery = - window.location.pathname + "?" + searchParams.toString(); - history.pushState(null, "", newRelativePathQuery); - } else { - history.pushState(null, "", window.location.pathname); - } - }, [inputVal]); - - return ( -
-
-
-
-
- - -
-
-
- - {/* {inputVal.length > 1 && ( -
- Found {searchResults?.length} - {searchResults?.length && searchResults?.length === 1 - ? " result" - : " results"}{" "} - for '{inputVal}' -
- )} */} -
- {searchResults?.length < 1 ? ( -
- no-search-found -

- {inputVal.length < 1 ? "Search Post Here" : "No Search Found!"} -

-

- {inputVal.length < 1 - ? "Search for posts by title, category, or tag." - : "We couldn't find what you searched for. Try searching again."} -

-
- ) : ( - searchResults?.map(({ item }, index) => ( -
-
- {item.data.image && ( - {item.data.title} - )} -

- - {item.data.title} - -

- -

- {plainify(item.content?.slice(0, Number(summary_length)))} -

- - read more - -
-
- )) - )} -
-
-
- ); -}; - -export default Search; diff --git a/src/layouts/components/DocBrowser.astro b/src/layouts/components/DocBrowser.astro index c6d71d3..48591bb 100644 --- a/src/layouts/components/DocBrowser.astro +++ b/src/layouts/components/DocBrowser.astro @@ -12,10 +12,10 @@ const isCurrentPage = (item) => { const getLinkClasses = (link) => { const baseClasses = - "block py-2 px-6 my-1 transition-colors border-l hover:border-slate-400 text-slate-500 hover:text-slate-900"; + "text-xl block py-1 px-2 my-1 rounded hover:bg-theme-light dark:hover:bg-darkmode-theme-light"; if (isCurrentPage(link)) { - return baseClasses + " border-slate-500 text-slate-900"; + return baseClasses + "rounded bg-theme-light dark:bg-darkmode-theme-light"; } else { return baseClasses; } @@ -31,15 +31,17 @@ const { main }: { main: doc_data[] } = docs; --- - - diff --git a/src/layouts/components/SearchBar.astro b/src/layouts/components/SearchBar.astro new file mode 100644 index 0000000..8015c60 --- /dev/null +++ b/src/layouts/components/SearchBar.astro @@ -0,0 +1,86 @@ +--- +import { IoSearch, IoClose } from "react-icons/io5/index.js"; +--- + +
+
+ +
+ + + + +