diff --git a/pagefind/src/output/stubs/search.js b/pagefind/src/output/stubs/search.js index a34775b8..174c5476 100644 --- a/pagefind/src/output/stubs/search.js +++ b/pagefind/src/output/stubs/search.js @@ -177,7 +177,7 @@ class Pagefind { let ptr = await this.getPtr(); // Strip special characters to match the indexing operation let exact_search = /^\s*".+"\s*$/.test(term); - term = term.toLowerCase().trim().replace(/[^\w\s]/g, "").trim(); + term = term.toLowerCase().trim().replace(/[^\w\s]/g, "").replace(/\s{2,}/g, " ").trim(); let filter_list = []; for (let [filter, values] of Object.entries(options.filters)) { diff --git a/pagefind_ui/dev_files/_pagefind/pagefind.js b/pagefind_ui/dev_files/_pagefind/pagefind.js index 9b6fb6e7..f1c8d416 100644 --- a/pagefind_ui/dev_files/_pagefind/pagefind.js +++ b/pagefind_ui/dev_files/_pagefind/pagefind.js @@ -1,6 +1,68 @@ // This is a Pagefind testing stub that needs to be updated if src/output/search.js is changed const stubbed_results = [ + { + id: 123, + data: { + content: [ + `Cras mattis consectetur purus sit amet fermentum. Maecenas sed diam eget risus varius blandit sit amet non magna. Sed posuere consectetur est at lobortis. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.`, + `Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam.`, + `Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec ullamcorper nulla non metus auctor fringilla.` + ].join('\n'), + url: "/cats/", + filters: { + color: ["Red"] + }, + meta: { + title: `Post about TERM`, + image: "https://placekitten.com/800/400" + }, + word_count: 12, + excerpt: `some excerpt that references TERM with a nice highlighted element.` + } + }, + { + id: 1234, + data: { + content: [ + `Cras mattis consectetur purus sit amet fermentum. Maecenas sed diam eget risus varius blandit sit amet non magna. Sed posuere consectetur est at lobortis. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.`, + `Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam.`, + `Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec ullamcorper nulla non metus auctor fringilla.` + ].join('\n'), + url: "/dogs/", + filters: { + color: ["Blue", "Gold"] + }, + meta: { + title: `TERM and TERM-like things`, + image: "https://placekitten.com/1000/500" + }, + word_count: 15, + excerpt: `I like TERM and also TERM...` + } + }, + { + id: 12345, + data: { + content: [ + `Cras mattis consectetur purus sit amet fermentum. Maecenas sed diam eget risus varius blandit sit amet non magna. Sed posuere consectetur est at lobortis. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.`, + `Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam.`, + `Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec ullamcorper nulla non metus auctor fringilla.` + ].join('\n'), + url: "/llamas/", + filters: { + color: ["White"], + smell: ["Sweet"] + }, + meta: { + title: `TERM the llama`, + image: "https://placekitten.com/900/600", + name: "Steve" + }, + word_count: 100, + excerpt: `Nullam id dolor id nibh ultricies TERM vehicula ut id elit.` + } + }, { id: 123, data: { diff --git a/pagefind_ui/svelte/filters.svelte b/pagefind_ui/svelte/filters.svelte index 499f1fb7..c5c5f578 100644 --- a/pagefind_ui/svelte/filters.svelte +++ b/pagefind_ui/svelte/filters.svelte @@ -3,26 +3,29 @@ export const selected_filters = {}; -
- Filters +
+ Filters {#if available_filters} {#each Object.entries(available_filters) as [filter, values]} -
- + {filter.replace(/^(\w)/, (c) => c.toLocaleUpperCase() )} -
- {filter} +
+ {filter} {#each Object.entries(values) as [value, count]}
- {value} ({count})
{/each} @@ -40,114 +44,118 @@
{/each} {:else} -

..........

+

..........

{/if}
diff --git a/pagefind_ui/svelte/reset.svelte b/pagefind_ui/svelte/reset.svelte index a145c177..9e13e202 100644 --- a/pagefind_ui/svelte/reset.svelte +++ b/pagefind_ui/svelte/reset.svelte @@ -10,7 +10,7 @@ Remove all the styles of the "User-Agent-Stylesheet", except for the 'display' property - The "symbol *" part is to solve Firefox SVG sprite bug */ - :global(.pagefind-reset + :global(.pagefind-ui--reset *:where(:not(html, iframe, canvas, img, svg, video):not(svg *, symbol *))) { all: unset; @@ -18,62 +18,63 @@ } /* Preferred box-sizing value */ - :global(.pagefind-reset *, .pagefind-reset *::before, .pagefind-reset - *::after) { + :global(.pagefind-ui--reset *, .pagefind-ui--reset + *::before, .pagefind-ui--reset *::after) { box-sizing: border-box; } /* Reapply the pointer cursor for anchor tags */ - :global(.pagefind-reset a, .pagefind-reset button) { + :global(.pagefind-ui--reset a, .pagefind-ui--reset button) { cursor: revert; } /* Remove list styles (bullets/numbers) */ - :global(.pagefind-reset ol, .pagefind-reset ul, .pagefind-reset menu) { + :global(.pagefind-ui--reset ol, .pagefind-ui--reset ul, .pagefind-ui--reset + menu) { list-style: none; } /* For images to not be able to exceed their container */ - :global(.pagefind-reset img) { + :global(.pagefind-ui--reset img) { max-width: 100%; } /* removes spacing between cells in tables */ - :global(.pagefind-reset table) { + :global(.pagefind-ui--reset table) { border-collapse: collapse; } /* Safari - solving issue when using user-select:none on the text input doesn't working */ - :global(.pagefind-reset input, .pagefind-reset textarea) { + :global(.pagefind-ui--reset input, .pagefind-ui--reset textarea) { -webkit-user-select: auto; } /* revert the 'white-space' property for textarea elements on Safari */ - :global(.pagefind-reset textarea) { + :global(.pagefind-ui--reset textarea) { white-space: revert; } /* minimum style to allow to style meter element */ - :global(.pagefind-reset meter) { + :global(.pagefind-ui--reset meter) { -webkit-appearance: revert; appearance: revert; } /* reset default text opacity of input placeholder */ - :global(.pagefind-reset ::placeholder) { + :global(.pagefind-ui--reset ::placeholder) { color: unset; } /* fix the feature of 'hidden' attribute. display:revert; revert to element instead of attribute */ - :global(.pagefind-reset :where([hidden])) { + :global(.pagefind-ui--reset :where([hidden])) { display: none; } /* revert for bug in Chromium browsers - fix for the content editable attribute will work properly. - webkit-user-select: auto; added for Safari in case of using user-select:none on wrapper element*/ - :global(.pagefind-reset + :global(.pagefind-ui--reset :where([contenteditable]:not([contenteditable="false"]))) { -moz-user-modify: read-write; -webkit-user-modify: read-write; @@ -83,7 +84,12 @@ } /* apply back the draggable feature - exist only in Chromium and Safari */ - :global(.pagefind-reset :where([draggable="true"])) { + :global(.pagefind-ui--reset :where([draggable="true"])) { -webkit-user-drag: element; } + + /* Pagefind specific — use the default mark styling */ + :global(.pagefind-ui--reset mark) { + all: revert; + } diff --git a/pagefind_ui/svelte/result.svelte b/pagefind_ui/svelte/result.svelte index de5c4805..c470589d 100644 --- a/pagefind_ui/svelte/result.svelte +++ b/pagefind_ui/svelte/result.svelte @@ -18,20 +18,28 @@ }; -
  • +
  • {#if data} - {#if data.meta.image} - {data.meta?.title} - {:else} -
    - {/if} -
    -

    {data.meta?.title}

    -

    {@html data.excerpt}

    +
    + {#if data.meta.image} + {data.meta?.title} + {/if} +
    +
    +

    + {data.meta?.title} +

    +

    {@html data.excerpt}

    {#if meta.length} -
      +
        {#each meta as [metaTitle, metaValue]} -
      • +
      • {metaTitle.replace(/^(\w)/, (c) => c.toLocaleUpperCase() )}: {metaValue} @@ -41,83 +49,111 @@ {/if}
    {:else} -
    -
    -

    {placeholder(30)}

    -

    {placeholder(40)}

    +
    +
    +

    + {placeholder(30)} +

    +

    + {placeholder(40)} +

    {/if}
  • diff --git a/pagefind_ui/svelte/ui.svelte b/pagefind_ui/svelte/ui.svelte index 00e871fe..7d90cd2c 100644 --- a/pagefind_ui/svelte/ui.svelte +++ b/pagefind_ui/svelte/ui.svelte @@ -4,6 +4,7 @@ import Reset from "./reset.svelte"; export let base_path = "/_pagefind/"; + export let reset_styles = true; export let pagefind_options = {}; let val = ""; @@ -84,143 +85,161 @@ }; -
    +
    diff --git a/pagefind_ui/ui.js b/pagefind_ui/ui.js index af664a3a..6fe080a6 100644 --- a/pagefind_ui/ui.js +++ b/pagefind_ui/ui.js @@ -4,6 +4,7 @@ class PagefindUI { constructor(opts) { let selector = opts.element ?? "[data-pagefind-ui]"; let bundlePath = opts.bundlePath; + let resetStyles = opts.resetStyles ?? true; if (!bundlePath) { try { @@ -19,6 +20,7 @@ class PagefindUI { // Remove the UI-specific config before passing it along to the Pagefind backend delete opts["element"]; delete opts["bundlePath"]; + delete opts["resetStyles"]; const dom = document.querySelector(selector); if (dom) { @@ -26,6 +28,7 @@ class PagefindUI { target: dom, props: { base_path: bundlePath, + reset_styles: resetStyles, pagefind_options: opts, } })