Commit 3e6949c17f
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/Search.vue +94 −2
| @@ -46,6 +46,7 @@ import { | ||
| 46 | 46 | File, |
| 47 | 47 | Globe, |
| 48 | 48 | Hash, |
| 49 | Layers, | |
| 49 | 50 | LayoutList, |
| 50 | 51 | List, |
| 51 | 52 | LocateOff, |
| @@ -272,6 +273,12 @@ const searchMode = useLocalStorage<'exact' | 'fuzzy' | 'url'>( | ||
| 272 | 273 | 'exact' |
| 273 | 274 | ) |
| 274 | 275 | |
| 276 | // How many result pages get their excerpts rendered ahead of time | |
| 277 | const excerptPreload = useLocalStorage<'off' | 'next' | 'all'>( | |
| 278 | 'vitepress:local-search-excerpt-preload', | |
| 279 | 'off' | |
| 280 | ) | |
| 281 | ||
| 275 | 282 | // Cycle through modes on mobile (only active button is visible, tap it to advance) |
| 276 | 283 | function cycleSearchMode() { |
| 277 | 284 | const modes = ['exact', 'fuzzy', 'url'] as const |
| @@ -337,7 +344,7 @@ const showSettingsPopup = ref(false) | ||
| 337 | 344 | const settingsButtonRef = ref<HTMLButtonElement>() |
| 338 | 345 | const settingsPopupRef = ref<HTMLDivElement>() |
| 339 | 346 | const settingsBounding = useElementBounding(settingsButtonRef) |
| 340 | type HelpSection = 'search' | 'view' | 'history' | |
| 347 | type HelpSection = 'search' | 'view' | 'preload' | 'history' | |
| 341 | 348 | const activeHelpSection = ref<HelpSection | null>(null) |
| 342 | 349 | const helpPopupEl = ref<HTMLDivElement>() |
| 343 | 350 | const helpPopupPos = ref({ top: -9999, left: -9999 }) |
| @@ -1014,9 +1021,26 @@ async function buildVisibleExcerpts() { | ||
| 1014 | 1021 | if (token !== excerptBuildToken) return |
| 1015 | 1022 | } |
| 1016 | 1023 | |
| 1017 | await buildAll(visiblePageDocs(1)) | |
| 1024 | if (excerptPreload.value === 'next') { | |
| 1025 | await buildAll(visiblePageDocs(1)) | |
| 1026 | } else if (excerptPreload.value === 'all') { | |
| 1027 | const seen = new Set<string>() | |
| 1028 | const docs: string[] = [] | |
| 1029 | for (const r of results.value) { | |
| 1030 | const docId = getDocId(String(r.id)) | |
| 1031 | if (!seen.has(docId)) { | |
| 1032 | seen.add(docId) | |
| 1033 | docs.push(docId) | |
| 1034 | } | |
| 1035 | } | |
| 1036 | await buildAll(docs) | |
| 1037 | } | |
| 1018 | 1038 | } |
| 1019 | 1039 | |
| 1040 | watch(excerptPreload, () => { | |
| 1041 | void buildVisibleExcerpts() | |
| 1042 | }) | |
| 1043 | ||
| 1020 | 1044 | watch(results, () => { |
| 1021 | 1045 | if ( |
| 1022 | 1046 | activePageFilter.value && |
| @@ -2548,6 +2572,53 @@ function onMouseMove(e: MouseEvent) { | ||
| 2548 | 2572 | </button> |
| 2549 | 2573 | </div> |
| 2550 | 2574 | </div> |
| 2575 | <div | |
| 2576 | v-if="!disableDetailedView && searchMode !== 'url' && | |
| 2577 | showDetailedList" | |
| 2578 | class="settings-section" | |
| 2579 | > | |
| 2580 | <div class="settings-section-header"> | |
| 2581 | <div class="settings-section-label"> | |
| 2582 | <Layers :size="14" stroke-width="1.75" /> | |
| 2583 | Preload | |
| 2584 | </div> | |
| 2585 | <button | |
| 2586 | type="button" | |
| 2587 | class="settings-help-btn" | |
| 2588 | :class="{ active: activeHelpSection === 'preload' }" | |
| 2589 | aria-label="Excerpt preload help" | |
| 2590 | @click.stop="toggleHelpSection('preload', $event)" | |
| 2591 | > | |
| 2592 | <span class="i-carbon:help-filled settings-help-icon" /> | |
| 2593 | </button> | |
| 2594 | </div> | |
| 2595 | <div class="settings-options"> | |
| 2596 | <button | |
| 2597 | type="button" | |
| 2598 | class="settings-option" | |
| 2599 | :class="{ active: excerptPreload === 'off' }" | |
| 2600 | @click="excerptPreload = 'off'" | |
| 2601 | > | |
| 2602 | <span>Off</span> | |
| 2603 | </button> | |
| 2604 | <button | |
| 2605 | type="button" | |
| 2606 | class="settings-option" | |
| 2607 | :class="{ active: excerptPreload === 'next' }" | |
| 2608 | @click="excerptPreload = 'next'" | |
| 2609 | > | |
| 2610 | <span>One</span> | |
| 2611 | </button> | |
| 2612 | <button | |
| 2613 | type="button" | |
| 2614 | class="settings-option" | |
| 2615 | :class="{ active: excerptPreload === 'all' }" | |
| 2616 | @click="excerptPreload = 'all'" | |
| 2617 | > | |
| 2618 | <span>All</span> | |
| 2619 | </button> | |
| 2620 | </div> | |
| 2621 | </div> | |
| 2551 | 2622 | <div class="settings-section"> |
| 2552 | 2623 | <div class="settings-section-header"> |
| 2553 | 2624 | <div class="settings-section-label"> |
| @@ -2645,6 +2716,27 @@ function onMouseMove(e: MouseEvent) { | ||
| 2645 | 2716 | </div> |
| 2646 | 2717 | </div> |
| 2647 | 2718 | </template> |
| 2719 | <template v-else-if="activeHelpSection === 'preload'"> | |
| 2720 | <h4 class="sh-title"> | |
| 2721 | <Layers :size="16" stroke-width="1.75" class="sh-title-icon" /> | |
| 2722 | Excerpt Preload | |
| 2723 | </h4> | |
| 2724 | <p class="sh-desc">Renders excerpts for upcoming result pages ahead of time in Detail view.</p> | |
| 2725 | <div class="sh-options"> | |
| 2726 | <div class="sh-option"> | |
| 2727 | <strong>Off</strong> | |
| 2728 | <span>Only the visible page. Uses the least memory.</span> | |
| 2729 | </div> | |
| 2730 | <div class="sh-option"> | |
| 2731 | <strong>One</strong> | |
| 2732 | <span>Also prepares the next page so flipping forward is instant</span> | |
| 2733 | </div> | |
| 2734 | <div class="sh-option"> | |
| 2735 | <strong>All</strong> | |
| 2736 | <span>Prepares every result page. Uses more memory.</span> | |
| 2737 | </div> | |
| 2738 | </div> | |
| 2739 | </template> | |
| 2648 | 2740 | <template v-else-if="activeHelpSection === 'history'"> |
| 2649 | 2741 | <h4 class="sh-title"> |
| 2650 | 2742 | <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> |