diff --git a/docs/content/docs/_index.md b/docs/content/docs/_index.md index 027c0c46..274c81fc 100644 --- a/docs/content/docs/_index.md +++ b/docs/content/docs/_index.md @@ -53,19 +53,6 @@ We can see that a bunch of content was indexed, and Pagefind will be running a p Loading this in your browser, you should see a search input on your page. Try searching for some content and you will see results appear from your site. -## Highlighting - -To highlight the search terms on results page, add the following snippet on every page that has been indexed - -```html - - - ``` -To see the options available to PagefindHighlight, see [Highlight Config](/docs/highlight-config). +Ensure that the `highlightParam` configured here matches the `highlightParam` given to Pagefind when searching. + +To see all options available to PagefindHighlight, see [Highlight Config](/docs/highlight-config). diff --git a/docs/content/docs/search-config.md b/docs/content/docs/search-config.md index b1697222..7fb114e9 100644 --- a/docs/content/docs/search-config.md +++ b/docs/content/docs/search-config.md @@ -67,6 +67,18 @@ Overrides the bundle directory. In most cases this should be automatically detec Set the maximum length for generated excerpts. Defaults to `30`. +### Highlight query parameter + +```json +{ + "highlightParam": "highlight" +} +``` + +If set, Pagefind will add the search term as a query parameter under the same name. + +If using the [Pagefind highlight script](/docs/highlighting/), make sure this is configured to match. + ### Index weight See [multisite search > weighting](/docs/multisite/#changing-the-weighting-of-individual-indexes) diff --git a/docs/content/docs/ui.md b/docs/content/docs/ui.md index 2ef280b7..a578e9fe 100644 --- a/docs/content/docs/ui.md +++ b/docs/content/docs/ui.md @@ -152,19 +152,6 @@ new PagefindUI({ The number of milliseconds to wait after a user stops typing before performing a search. Defaults to `300`. If you wish to disable this, set to `0`. -### Highlight query param name - -{{< diffcode >}} -```javascript -new PagefindUI({ - element: "#search", -+ highlightQueryParamName: 'highlight' -}); -``` -{{< /diffcode >}} - -If the parameter is changed here, it *must* be changed in the [`PagefindHighlight` object](/docs/highlight-config/#pagefindQueryParamName) as well. - ### Translations {{< diffcode >}} diff --git a/pagefind/features/highlighting/highlighting_base.feature b/pagefind/features/highlighting/highlighting_results.feature similarity index 98% rename from pagefind/features/highlighting/highlighting_base.feature rename to pagefind/features/highlighting/highlighting_results.feature index 4ec035ed..fdd63ffb 100644 --- a/pagefind/features/highlighting/highlighting_base.feature +++ b/pagefind/features/highlighting/highlighting_results.feature @@ -1,4 +1,4 @@ -Feature: Highlighting Tests +Feature: Highlighting Result Tests Background: Given I have the environment variables: @@ -56,7 +56,7 @@ Feature: Highlighting Tests - """ + """ Given I have a "public/cat/index.html" file with the body: """
{@html data.excerpt}
- {#if meta.length} - - {/if} -{@html data.excerpt}
+ {#if meta.length} + + {/if} ++ {placeholder(30)} +
++ {placeholder(40)} +
+- {placeholder(30)} -
-- {placeholder(40)} -
-- {@html data.meta?.title}{data.meta?.title}
{#if has_root_sub_result} @@ -77,11 +70,8 @@ {#each non_root_sub_results as subres}- {@html subres.title}{subres.title}
{@html subres.excerpt}
@@ -92,7 +82,7 @@ diff --git a/pagefind_ui/default/svelte/ui.svelte b/pagefind_ui/default/svelte/ui.svelte index c74cdb5e..1522b7fa 100644 --- a/pagefind_ui/default/svelte/ui.svelte +++ b/pagefind_ui/default/svelte/ui.svelte @@ -34,9 +34,6 @@ export let merge_index = []; export let trigger_search_term = ""; export let translations = {}; - // this is the name of the query param which is used to highlight the search terms after the user has navigated to a result page - // consider exposing the prop in the constructor in camelCase if needed - export let highlight_query_param_name = "pagefind-highlight"; let val = ""; $: if (trigger_search_term) { @@ -44,16 +41,6 @@ trigger_search_term = ""; } - // this could be changed to not split if the value is quoted - // ex: val = `hello world "foo bar"` highlightWords = ["hello", "world", "foo bar"] - - $: highlightWords = val.split(" "); - - $: highlight_query_param = new URLSearchParams( - highlightWords.map((word) => { - return [highlight_query_param_name, word]; - }) - ).toString(); let pagefind; let input_el, clear_el, @@ -318,23 +305,9 @@