Skip to content

Expose Node.js API #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bglw opened this issue Sep 16, 2022 · 5 comments
Closed

Expose Node.js API #72

bglw opened this issue Sep 16, 2022 · 5 comments
Labels
Available on prerelease improvement Not a bug Pagefind CLI The CLI responsible for indexing content
Milestone

Comments

@bglw
Copy link
Contributor

bglw commented Sep 16, 2022

Add support for using the npm pagefind package via node as discussed in #71

@bglw bglw added improvement Not a bug Pagefind CLI The CLI responsible for indexing content labels Sep 16, 2022
@airhorns
Copy link

Could I register a vote for the nodejs API to support passing files on disk, but also passing actual entries to add to the index instead of HTML to be parsed? If you want to customize how an HTML document is turned into search results (or in my case, already have all that customization built), a node.js API that allowed adding individual results would make pagefind super useful. Folks would still be able to wire up pagefind's indexing and frontend bits, and could still use the CLI to generate indexes if they were starting from scratch, but if they wanted to customize it'd be super powerful to programmatically build up the index!

@bglw
Copy link
Contributor Author

bglw commented Sep 21, 2022

Good suggestion @airhorns — I might spin that up as a separate issue after implementing the simple version of the API.

To start with, the API will be setting CLI flags and running the Pagefind binary. To support adding entries I'll probably need to expand on the JS↔Binary communication for a nice way to pass in entries, since they don't really fit as CLI flags.

@bglw
Copy link
Contributor Author

bglw commented Mar 27, 2023

An update for anyone following the issue — work for this is underway. (Including passing actual entries @airhorns 👀).

Sample:

import * as pagefind from "pagefind";

const { errors, index } = await pagefind.createIndex({ /* opts */ });

await index.addFile("testing/index.html", "<html><body><h1>Testing, testing</h1></body></html>");

await index.writeFiles({ /* opts */ });

Still to come: index.getFiles to get the contents of the index instead of writing to disk, and a method to add direct entries rather than parsing HTML contents.

@Jieiku
Copy link

Jieiku commented Jul 28, 2023

Awesome, can't wait :)

@bglw
Copy link
Contributor Author

bglw commented Sep 13, 2023

Hey all ! 👋

Good news — this has landed in Pagefind v1.0.0! ✨

See the full release notes here: https://github.com/CloudCannon/pagefind/releases/tag/v1.0.0 💙

See the library guide here: https://pagefind.app/docs/node-api/

@bglw bglw closed this as completed Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Available on prerelease improvement Not a bug Pagefind CLI The CLI responsible for indexing content
Projects
None yet
Development

No branches or pull requests

3 participants