diff --git a/.eslintrc.yml b/.eslintrc.yml index aff44cbbb..a8907fe08 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -4,3 +4,4 @@ extends: rules: no-case-declarations: 0 no-restricted-syntax: 0 + react/no-unescaped-entities: 0 diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 000000000..544138be4 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/src/apps/devdoc/.eslintrc.yml b/src/apps/devdoc/.eslintrc.yml index 46801b426..561b1e490 100644 --- a/src/apps/devdoc/.eslintrc.yml +++ b/src/apps/devdoc/.eslintrc.yml @@ -55,6 +55,7 @@ rules: # pritter rules # ts rules + react/no-unescaped-entities: 0 react/jsx-no-useless-fragment: 0 react/jsx-filename-extension: 0 react/require-default-props : 0 diff --git a/src/apps/devdoc/app/components/flexsearch.tsx b/src/apps/devdoc/app/components/flexsearch.tsx index 467df176c..7c872fff8 100644 --- a/src/apps/devdoc/app/components/flexsearch.tsx +++ b/src/apps/devdoc/app/components/flexsearch.tsx @@ -65,10 +65,10 @@ const loadIndexesPromises = new Map>(); const loadIndexesImpl = async ( basePath: string, - locale: string + locale: string, ): Promise => { const response = await fetch( - `${basePath}/_next/static/chunks/nextra-data-${locale}.json` + `${basePath}/_next/static/chunks/nextra-data-${locale}.json`, ); const searchData = (await response.json()) as SearchData; @@ -103,6 +103,8 @@ const loadIndexesImpl = async ( }, }); + console.log('searchData', sectionIndex); + let pageId = 0; for (const [route, structurizedData] of Object.entries(searchData)) { @@ -165,6 +167,8 @@ export function Flexsearch(): ReactElement { const [results, setResults] = useState([]); const [search, setSearch] = useState(''); + const router = useRouter(); + const doSearch = (search: string) => { if (!search) return; const [pageIndex, sectionIndex] = indexes[locale]; @@ -211,7 +215,7 @@ export function Flexsearch(): ReactElement { prefix: isFirstItemOfPage && (
{result.doc.title} @@ -219,11 +223,11 @@ export function Flexsearch(): ReactElement { ), children: ( <> -
+
{content && ( -
+
)} @@ -246,13 +250,20 @@ export function Flexsearch(): ReactElement { } return a._page_rk - b._page_rk; }) + .filter( + (res) => + (res.route.startsWith('/docs') && + router.route.startsWith('/docs')) || + (res.route.startsWith('/blog') && router.route.startsWith('/blog')), + ) .map((res) => ({ id: `${res._page_rk}_${res._section_rk}`, route: res.route, prefix: res.prefix, children: res.children, - })) + })), ); + console.log(router); }; const preload = useCallback( @@ -267,7 +278,7 @@ export function Flexsearch(): ReactElement { setLoading(false); } }, - [locale, basePath] + [locale, basePath], ); const handleChange = async (value: string) => { @@ -298,6 +309,7 @@ export function Flexsearch(): ReactElement { setSearch(''); } }, [show]); + return ( - -
-
- + +
+
+ - ⌘K -
+ + ⌘K + +
{results.length === 0 && ( -
+
No recent results
)} {results.length > 0 && ( {results.map((res) => ( -
-
{res.prefix}
+
+
{res.prefix}
{res.children} diff --git a/src/apps/devdoc/app/components/footer.tsx b/src/apps/devdoc/app/components/footer.tsx index 40b344ce5..d2502bcc2 100644 --- a/src/apps/devdoc/app/components/footer.tsx +++ b/src/apps/devdoc/app/components/footer.tsx @@ -182,7 +182,7 @@ const Footer = ({ config }: { config: IConfig }) => { 'menu' in config.footer ) return ( -