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 {
4646 File,
4747 Globe,
4848 Hash,
49 Layers,
4950 LayoutList,
5051 List,
5152 LocateOff,
@@ -272,6 +273,12 @@ const searchMode = useLocalStorage<'exact' | 'fuzzy' | 'url'>(
272273 'exact'
273274)
274275
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
275282// Cycle through modes on mobile (only active button is visible, tap it to advance)
276283function cycleSearchMode() {
277284 const modes = ['exact', 'fuzzy', 'url'] as const
@@ -337,7 +344,7 @@ const showSettingsPopup = ref(false)
337344const settingsButtonRef = ref<HTMLButtonElement>()
338345const settingsPopupRef = ref<HTMLDivElement>()
339346const settingsBounding = useElementBounding(settingsButtonRef)
340type HelpSection = 'search' | 'view' | 'history'
347type HelpSection = 'search' | 'view' | 'preload' | 'history'
341348const activeHelpSection = ref<HelpSection | null>(null)
342349const helpPopupEl = ref<HTMLDivElement>()
343350const helpPopupPos = ref({ top: -9999, left: -9999 })
@@ -1014,9 +1021,26 @@ async function buildVisibleExcerpts() {
10141021 if (token !== excerptBuildToken) return
10151022 }
10161023
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 }
10181038}
10191039
1040watch(excerptPreload, () => {
1041 void buildVisibleExcerpts()
1042})
1043
10201044watch(results, () => {
10211045 if (
10221046 activePageFilter.value &&
@@ -2548,6 +2572,53 @@ function onMouseMove(e: MouseEvent) {
25482572 </button>
25492573 </div>
25502574 </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>
25512622 <div class="settings-section">
25522623 <div class="settings-section-header">
25532624 <div class="settings-section-label">
@@ -2645,6 +2716,27 @@ function onMouseMove(e: MouseEvent) {
26452716 </div>
26462717 </div>
26472718 </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>
26482740 <template v-else-if="activeHelpSection === 'history'">
26492741 <h4 class="sh-title">
26502742 <Clock :size="16" stroke-width="1.75" class="sh-title-icon" />