-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Feature: Base UI Tests | ||
Background: | ||
Given I have the environment variables: | ||
| PAGEFIND_SOURCE | public | | ||
Given I have a "public/index.html" file with the body: | ||
""" | ||
<div id="search"></div> | ||
<script src="/_pagefind/pagefind-ui.js" type="text/javascript"></script> | ||
<script> | ||
new PagefindUI({ element: "#search" }); | ||
</script> | ||
""" | ||
|
||
Scenario: Pagefind UI loads | ||
Given I have a "public/cat/index.html" file with the body: | ||
""" | ||
<h1>world</h1> | ||
""" | ||
When I run my program | ||
Then I should see "Running Pagefind" in stdout | ||
Then I should see the file "public/_pagefind/pagefind.js" | ||
When I serve the "public" directory | ||
When I load "/" | ||
Then There should be no logs | ||
Then The selector ".pagefind-ui" should exist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
import PagefindUi from './svelte/ui.svelte'; | ||
import Pagefind from './svelte/ui.svelte'; | ||
|
||
(() => { | ||
let base_path = "/_pagefind/"; | ||
try { | ||
base_path = new URL(document.currentScript.src).pathname.match(/^(.*\/)(?:pagefind-)?ui.js.*$/)[1]; | ||
} catch (e) { | ||
console.warn("Pagefind couldn't determine the base of the bundle from the import path. Falling back to the default."); | ||
} | ||
class PagefindUi { | ||
constructor(opts) { | ||
let selector = opts.element ?? "[data-pagefind-ui]"; | ||
let bundlePath = opts.bundlePath; | ||
|
||
if (!bundlePath) { | ||
try { | ||
bundlePath = new URL(document.currentScript.src).pathname.match(/^(.*\/)(?:pagefind-)?ui.js.*$/)[1]; | ||
} catch (e) { | ||
bundlePath = "/_pagefind/"; | ||
console.warn(`Pagefind couldn't determine the base of the bundle from the javascript import path. Falling back to the default of ${bundlePath}.`); | ||
console.warn("You can configure this by passing a bundlePath option to PagefindUi"); | ||
} | ||
} | ||
|
||
const dom = document.querySelector("[data-pagefind-ui]"); | ||
new PagefindUi({ | ||
target: dom, | ||
props: { | ||
base_path | ||
// Remove the UI-specific config before passing it along to the Pagefind backend | ||
delete opts["element"]; | ||
delete opts["bundlePath"]; | ||
|
||
const dom = document.querySelector(selector); | ||
if (dom) { | ||
new Pagefind({ | ||
target: dom, | ||
props: { | ||
base_path: bundlePath, | ||
pagefind_options: opts, | ||
} | ||
}) | ||
} else { | ||
console.error(`Pagefind UI couldn't find the selector ${selector}`); | ||
} | ||
}) | ||
})(); | ||
} | ||
} | ||
|
||
window.PagefindUi = PagefindUi; |