Commit 3e6949c17f

3e6949c17fdae5d837a8b85354d9367895f9ced4

parent: 5323e69350

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-05 16:09 UTC

preload amount

Layout: unified · split

docs/.vitepress/theme/components/Search.vue +94 −2
@@ -46,6 +46,7 @@ import {
46 File, 46 File,
47 Globe, 47 Globe,
48 Hash, 48 Hash,
49 Layers,
49 LayoutList, 50 LayoutList,
50 List, 51 List,
51 LocateOff, 52 LocateOff,
@@ -272,6 +273,12 @@ const searchMode = useLocalStorage<'exact' | 'fuzzy' | 'url'>(
272 'exact' 273 'exact'
273) 274)
274 275
276// How many result pages get their excerpts rendered ahead of time
277const excerptPreload = useLocalStorage<'off' | 'next' | 'all'>(
278 'vitepress:local-search-excerpt-preload',
279 'off'
280)
281
275// Cycle through modes on mobile (only active button is visible, tap it to advance) 282// Cycle through modes on mobile (only active button is visible, tap it to advance)
276function cycleSearchMode() { 283function cycleSearchMode() {
277 const modes = ['exact', 'fuzzy', 'url'] as const 284 const modes = ['exact', 'fuzzy', 'url'] as const
@@ -337,7 +344,7 @@ const showSettingsPopup = ref(false)
337const settingsButtonRef = ref<HTMLButtonElement>() 344const settingsButtonRef = ref<HTMLButtonElement>()
338const settingsPopupRef = ref<HTMLDivElement>() 345const settingsPopupRef = ref<HTMLDivElement>()
339const settingsBounding = useElementBounding(settingsButtonRef) 346const settingsBounding = useElementBounding(settingsButtonRef)
340type HelpSection = 'search' | 'view' | 'history' 347type HelpSection = 'search' | 'view' | 'preload' | 'history'
341const activeHelpSection = ref<HelpSection | null>(null) 348const activeHelpSection = ref<HelpSection | null>(null)
342const helpPopupEl = ref<HTMLDivElement>() 349const helpPopupEl = ref<HTMLDivElement>()
343const helpPopupPos = ref({ top: -9999, left: -9999 }) 350const helpPopupPos = ref({ top: -9999, left: -9999 })
@@ -1014,9 +1021,26 @@ async function buildVisibleExcerpts() {
1014 if (token !== excerptBuildToken) return 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
1040watch(excerptPreload, () => {
1041 void buildVisibleExcerpts()
1042})
1043
1020watch(results, () => { 1044watch(results, () => {
1021 if ( 1045 if (
1022 activePageFilter.value && 1046 activePageFilter.value &&
@@ -2548,6 +2572,53 @@ function onMouseMove(e: MouseEvent) {
2548 </button> 2572 </button>
2549 </div> 2573 </div>
2550 </div> 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 <div class="settings-section"> 2622 <div class="settings-section">
2552 <div class="settings-section-header"> 2623 <div class="settings-section-header">
2553 <div class="settings-section-label"> 2624 <div class="settings-section-label">
@@ -2645,6 +2716,27 @@ function onMouseMove(e: MouseEvent) {
2645 </div> 2716 </div>
2646 </div> 2717 </div>
2647 </template> 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 <template v-else-if="activeHelpSection === 'history'"> 2740 <template v-else-if="activeHelpSection === 'history'">
2649 <h4 class="sh-title"> 2741 <h4 class="sh-title">
2650 <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> 2742 <Clock :size="16" stroke-width="1.75" class="sh-title-icon" />