feat: search filtering and better weighting
This commit is contained in:
parent
7cc57b770d
commit
e7aee4f394
4 changed files with 57 additions and 9 deletions
|
|
@ -11,7 +11,7 @@ import magnifierIcon from "@icons/magnifier.svg?raw";
|
||||||
aria-keyshortcuts="Control+K"
|
aria-keyshortcuts="Control+K"
|
||||||
class="search-button"
|
class="search-button"
|
||||||
>
|
>
|
||||||
<Fragment set :html={magnifierIcon} />
|
<Fragment set:html={magnifierIcon} />
|
||||||
<span class="search-label" aria-hidden="true">Search</span>
|
<span class="search-label" aria-hidden="true">Search</span>
|
||||||
<kbd class="search-kbd"> <kbd>Ctrl</kbd><kbd>K</kbd> </kbd>
|
<kbd class="search-kbd"> <kbd>Ctrl</kbd><kbd>K</kbd> </kbd>
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -129,28 +129,35 @@ import magnifierIcon from "@icons/magnifier.svg?raw";
|
||||||
const onIdle = window.requestIdleCallback || (cb => setTimeout(cb, 1));
|
const onIdle = window.requestIdleCallback || (cb => setTimeout(cb, 1));
|
||||||
onIdle(async () => {
|
onIdle(async () => {
|
||||||
const { PagefindUI } = await import(
|
const { PagefindUI } = await import(
|
||||||
//@ts-expect-error — Missing types for @pagefind/default-ui package.
|
//Missing types for @pagefind/default-ui package.
|
||||||
|
//@ts-expect-error
|
||||||
"@pagefind/default-ui"
|
"@pagefind/default-ui"
|
||||||
);
|
);
|
||||||
new PagefindUI({
|
new PagefindUI({
|
||||||
element: "#qs_search",
|
element: "#qs_search",
|
||||||
|
// resetStyles: false,
|
||||||
|
sort: { version: "desc" },
|
||||||
baseUrl: import.meta.env.BASE_URL,
|
baseUrl: import.meta.env.BASE_URL,
|
||||||
bundlePath:
|
bundlePath:
|
||||||
import.meta.env.BASE_URL.replace(/\/$/, "") + "/pagefind/",
|
import.meta.env.BASE_URL.replace(/\/$/, "") + "/pagefind/",
|
||||||
showImages: false,
|
showImages: false,
|
||||||
showSubResults: true,
|
showSubResults: true,
|
||||||
processResult: (result: {
|
highlightParam: "highlight",
|
||||||
|
openFilters: ["Tags"],
|
||||||
|
processResult: function (result: {
|
||||||
url: string;
|
url: string;
|
||||||
excerpt: string;
|
excerpt: string;
|
||||||
meta: {
|
meta: {
|
||||||
source: string;
|
source: string;
|
||||||
|
title: string;
|
||||||
|
version: string;
|
||||||
};
|
};
|
||||||
extra_class: string;
|
extra_class: string;
|
||||||
sub_results: Array<{
|
sub_results: Array<{
|
||||||
url: string;
|
url: string;
|
||||||
excerpt: string;
|
excerpt: string;
|
||||||
}>;
|
}>;
|
||||||
}) => {
|
}) {
|
||||||
if (result.meta.source === "Qt Framework") {
|
if (result.meta.source === "Qt Framework") {
|
||||||
result.extra_class = "qt-result-badge";
|
result.extra_class = "qt-result-badge";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
src/config/io/search.ts
Normal file
13
src/config/io/search.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
function getSearchWeight(version: string) {
|
||||||
|
const versionArr = version.split(".");
|
||||||
|
versionArr[0] = versionArr[0].substring(1);
|
||||||
|
const searchWeightArr = versionArr.map(w => parseInt(w));
|
||||||
|
const weight = searchWeightArr.reduce((p, c, i, _) => {
|
||||||
|
const mult = i - 1 === 0 || i === 0 ? 10 : 1;
|
||||||
|
const acc = p * mult + c * mult;
|
||||||
|
return acc;
|
||||||
|
});
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getSearchWeight };
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
---
|
---
|
||||||
import { getQMLTypeLink } from "@config/io/helpers";
|
import { getQMLTypeLink } from "@config/io/helpers";
|
||||||
|
import { getSearchWeight } from "@config/io/search";
|
||||||
import { processMarkdown } from "@config/io/markdown";
|
import { processMarkdown } from "@config/io/markdown";
|
||||||
import { getVersionsData } from "@config/io/generateTypeData";
|
import { getVersionsData } from "@config/io/generateTypeData";
|
||||||
import DocsLayout from "@layouts/DocsLayout.astro";
|
import DocsLayout from "@layouts/DocsLayout.astro";
|
||||||
|
|
@ -41,6 +42,9 @@ const superLink = type.super ? getQMLTypeLink(version.name, type.super) : null;
|
||||||
const details = type.details
|
const details = type.details
|
||||||
? await processMarkdown(version.name, type.details)
|
? await processMarkdown(version.name, type.details)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
const searchWeight =
|
||||||
|
version.name != "master" ? getSearchWeight(version.name) : 999.0;
|
||||||
---
|
---
|
||||||
|
|
||||||
<DocsLayout
|
<DocsLayout
|
||||||
|
|
@ -48,12 +52,12 @@ const details = type.details
|
||||||
description={type.description ?? ""}
|
description={type.description ?? ""}
|
||||||
type={type}
|
type={type}
|
||||||
>
|
>
|
||||||
<div class="docs">
|
<div class="docs" data-pagefind-weight=`${searchWeight}` data-pagefind-meta=`version:${version.name}` data-pagefind-filter=`version:${version.name}`>
|
||||||
<div class="docs-content typedocs-content">
|
<div class="docs-content typedocs-content">
|
||||||
<hr>
|
<hr>
|
||||||
<section class="typedocs-title">
|
<section class="typedocs-title">
|
||||||
<h2 class="typedocs-title-text" data-pagefind-weight="10">
|
<h2 class="typedocs-title-text" data-pagefind-weight=`${searchWeight}` data-pagefind-meta="title" >
|
||||||
{type.name}:
|
{type.name}<span data-pagefind-ignore>:</span>
|
||||||
{type.super?.name ? (
|
{type.super?.name ? (
|
||||||
<a
|
<a
|
||||||
href={superLink!}
|
href={superLink!}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@
|
||||||
width: calc(100% - var(--search-cancel-space));
|
width: calc(100% - var(--search-cancel-space));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#qs_search .pagefind-ui__filter-panel {
|
||||||
|
min-width: max-content;
|
||||||
|
}
|
||||||
|
|
||||||
#qs_search input:focus {
|
#qs_search input:focus {
|
||||||
--pagefind-ui-border: hsl(var(--accent-500));
|
--pagefind-ui-border: hsl(var(--accent-500));
|
||||||
}
|
}
|
||||||
|
|
@ -70,8 +74,14 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#qs_search .pagefind-ui__results > * + * {
|
#qs_search .pagefind-ui__results-area {
|
||||||
|
margin-bottom: calc(20px * var(--pagefind-ui-scale));
|
||||||
|
}
|
||||||
|
|
||||||
|
#qs_search .pagefind-ui__results {
|
||||||
|
& > * + * {
|
||||||
margin-top: var(--search-result-spacing);
|
margin-top: var(--search-result-spacing);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#qs_search .pagefind-ui__result {
|
#qs_search .pagefind-ui__result {
|
||||||
|
|
@ -79,6 +89,20 @@
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#qs_search .pagefind-ui__result-tag {
|
||||||
|
display: flex;
|
||||||
|
gap: var(--sm);
|
||||||
|
& #text:nth-child(1),
|
||||||
|
#text:nth-child(2) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
background-color: transparent;
|
||||||
|
color: hsl(var(--accent-600));
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
outline: 1px solid hsl(var(--accent-600));
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
#qs_search .pagefind-ui__result-nested {
|
#qs_search .pagefind-ui__result-nested {
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: var(--search-result-nested-pad-block)
|
padding: var(--search-result-nested-pad-block)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue