From bfe2410515850e48d006c985f102c4ce86ee6787 Mon Sep 17 00:00:00 2001 From: Sam James Date: Fri, 1 Nov 2024 00:46:45 +0000 Subject: [PATCH] feat(theme): introduce independent search page --- src/client/app/router.ts | 13 +++- src/client/theme-default/Search.vue | 69 +++++++++++++++++++ .../theme-default/components/VPContent.vue | 4 +- .../components/VPLocalSearchBox.vue | 32 ++++++--- .../theme-default/components/VPNavBar.vue | 6 +- src/shared/shared.ts | 15 +++- types/shared.d.ts | 1 + 7 files changed, 125 insertions(+), 15 deletions(-) create mode 100644 src/client/theme-default/Search.vue diff --git a/src/client/app/router.ts b/src/client/app/router.ts index 3c6fb4f7f42f..9e06d8a95181 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -1,7 +1,7 @@ import type { Component, InjectionKey } from 'vue' import { inject, markRaw, nextTick, reactive, readonly } from 'vue' import type { Awaitable, PageData, PageDataPayload } from '../shared' -import { notFoundPageData, treatAsHtml } from '../shared' +import { notFoundPageData, searchPageData, treatAsHtml } from '../shared' import { siteDataRef } from './data' import { getScrollOffset, inBrowser, withBase } from './utils' @@ -58,7 +58,8 @@ interface PageModule { export function createRouter( loadPageModule: (path: string) => Awaitable, - fallbackComponent?: Component + fallbackComponent?: Component, + searchComponent?: Component ): Router { const route = reactive(getDefaultRoute()) @@ -85,6 +86,14 @@ export function createRouter( if ((await router.onBeforePageLoad?.(href)) === false) return const targetLoc = new URL(href, fakeHost) const pendingPath = (latestPendingPath = targetLoc.pathname) + + if (pendingPath === '/search') { + route.path = inBrowser ? pendingPath : withBase(pendingPath) + route.component = searchComponent ? markRaw(searchComponent) : null + route.data = searchPageData + return + } + try { let page = await loadPageModule(pendingPath) if (!page) { diff --git a/src/client/theme-default/Search.vue b/src/client/theme-default/Search.vue new file mode 100644 index 000000000000..56761d003c9b --- /dev/null +++ b/src/client/theme-default/Search.vue @@ -0,0 +1,69 @@ + + + + + diff --git a/src/client/theme-default/components/VPContent.vue b/src/client/theme-default/components/VPContent.vue index 3b2dbdf6e0ff..6e2e522b9f05 100644 --- a/src/client/theme-default/components/VPContent.vue +++ b/src/client/theme-default/components/VPContent.vue @@ -1,5 +1,6 @@