Socket
Socket
Sign inDemoInstall

pagefind

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagefind - npm Package Compare versions

Comparing version 1.0.0-beta.3 to 1.0.0-beta.4

checksums/pagefind_extended-v1.0.0-beta.4-aarch64-apple-darwin.tar.gz.sha256

12

package.json
{
"name": "pagefind",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"type": "module",

@@ -22,7 +22,7 @@ "description": "Implement search on any static website.",

"optionalDependencies": {
"@pagefind/linux-x64": "1.0.0-beta.3",
"@pagefind/linux-arm64": "1.0.0-beta.3",
"@pagefind/darwin-x64": "1.0.0-beta.3",
"@pagefind/darwin-arm64": "1.0.0-beta.3",
"@pagefind/windows-x64": "1.0.0-beta.3"
"@pagefind/linux-x64": "1.0.0-beta.4",
"@pagefind/linux-arm64": "1.0.0-beta.4",
"@pagefind/darwin-x64": "1.0.0-beta.4",
"@pagefind/darwin-arm64": "1.0.0-beta.4",
"@pagefind/windows-x64": "1.0.0-beta.4"
},

@@ -29,0 +29,0 @@ "keywords": [

@@ -13,5 +13,5 @@ # Pagefind Static Search

```bash
npx pagefind --site "public"
```
npx pagefind --source "public"
```

@@ -23,13 +23,3 @@ For more details on using the Pagefind binary, see [Installing and running Pagefind](https://pagefind.app/docs/installation/#running-via-npx), and the rest of the Pagefind documentation.

This package also provides an interface to the Pagefind binary directly as a package you can import.
This generally isn't required, and running the binary directly on your source code is the recommended approach
for the majority of use-cases.
The rest of this documentation assumes you have a solid understanding of how to use Pagefind conventionally. Read through the [standard Pagefind documentation](https://pagefind.app/) first, if you haven't.
***
Using this indexing library is handy if you're integrating Pagefind directly into a static site generator, or for complex tasks like indexing JSON files or other non-HTML sources of content.
Example usage:
```js

@@ -41,159 +31,23 @@ import * as pagefind from "pagefind";

// Add content to it
await index.addHTMLFile({
path: "my_file/index.html",
content: "<html><body><h1>Testing, testing</h1></body></html>"
// Index all HTML files in a directory
await index.addDirectory({
path: "public"
});
// Get the index in-memory
await index.getFiles();
// Write the index to disk
await index.writeFiles({
outputPath: "./public/pagefind"
});
```
All interations with Pagefind are asynchronous, as they communicate with the native Pagefind binary in the background.
### `pagefind.createIndex`
Creates a Pagefind index that files can be added to.
The index object returned is unique, and multiple calls to `pagefind.createIndex()` can be made without conflicts.
```js
import * as pagefind from "pagefind";
const { index } = await pagefind.createIndex();
// ... do things with `index`
```
`createIndex` optionally takes a configuration object that can apply parts of the [Pagefind CLI config](https://pagefind.app/docs/config-options/). The options available at this level are:
```js
const { index } = await pagefind.createIndex({
rootSelector: "html",
excludeSelectors: [".my-code-blocks"],
forceLanguage: "en",
keepIndexUrl: false,
verbose: false,
logfile: "debug.log"
});
```
See the relevant documentation of each configuration option in the [Configuring the Pagefind CLI](https://pagefind.app/docs/config-options/) documentation.
### index.addDirectory
Indexes a directory from disk using the standard Pagefind indexing behaviour. This is the same action as running the Pagefind binary with `--source <dir>`. It can be handy to run this indexing step, and then add custom non-HTML records to the index before writing it to disk.
```js
const { errors, page_count } = await index.addDirectory({
path: "public",
glob: "**/*.{html}" // optional
});
```
If relative, `path` will be relative to the current working directory of your Node process.
Optionally, a custom `glob` can be supplied, which controls which files Pagefind will consume within the directory. The default is shown, and the `glob` option can be omitted entirely.
A response with an `errors` array containing error messages indicates that Pagefind failed to process this directory.
If successful, `page_count` will be the number of pages that were added to the index.
### index.addHTMLFile
Adds a virtual HTML file to the Pagefind index. Useful for files that don't exist on disk, for example a static site generator that is serving files from memory.
```js
const { errors, file } = await index.addHTMLFile({
path: "contact/index.html",
content: "<html><body> <h1>A Full HTML Document</h1> <p> . . . </p> </body></html>"
});
```
The `path` here should represent the output path of this HTML file if it were to exist on disk. Pagefind will use this path to generate the URL.
The `content` should be the full HTML source, including the outer `<html> </html>` tags. This will be run through Pagefind's standard HTML indexing process, and should contain any required Pagefind attributes to control behaviour.
A response with an `errors` array containing error messages indicates that Pagefind failed to index this content.
If successful, the `file` object is returned containing some metadata about the completed indexing.
### index.addCustomRecord
Adds a direct virtual record to the Pagefind index. Useful for adding non-HTML content to the index.
```js
const { errors, file } = await index.addHTMLFile({
url: "/contact/",
content: "My raw content to be indexed for search. Will be lightly processed by Pagefind.",
// Add extra content
await index.addCustomRecord({
url: "/resume.pdf",
content: "Aenean lacinia bibendum nulla sed consectetur",
language: "en",
meta: {
title: "Contact",
category: "Landing Page"
},
filters: {
tags: ["landing", "company"]
},
sort: {
weight: "20"
}
});
```
The `url`, `content`, and `language` fields are all required. `language` should be an [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
// Get the index files in-memory
const { files } = await index.getFiles();
`meta` is strictly a flat object of keys to string values. See the [Metadata documentation](https://pagefind.app/docs/metadata/) for semantics.
`filters` is strictly a flat object of keys to arrays of string values. See the [Filters documentation](https://pagefind.app/docs/filtering/) for semantics.
`sort` is strictly a flat object of keys to string values. See the [Sort documentation](https://pagefind.app/docs/sorts/) for semantics. *When Pagefind is processing an index, number-like strings will be sorted numerically rather than alphabetically.*
A response with an `errors` array containing error messages indicates that Pagefind failed to index this content.
If successful, the `file` object is returned containing some metadata about the completed indexing.
### index.getFiles
Get raw data of all files in the Pagefind index. Useful for integrating a Pagefind index into the development mode of a static site generator and hosting these files yourself.
```js
const { errors, files } = await index.getFiles();
for (const file of files) {
console.log(file.path);
// do something with the file.content Uint8Array
}
```
A response with an `errors` array containing error messages indicates that Pagefind failed to action this request.
If successful, `files` will be an array containing file objects. Each object contains a `path` key, which is the URL this file should be served at, and a `content` key containing the raw data as a Uint8Array.
### index.writeFiles
Writes the index files to disk, as they would be written when running the standard Pagefind binary directly.
```js
const { errors } = await index.writeFiles({
outputPath: "./public/pagefind"
// Or, write the index to disk
await index.writeFiles({
outputPath: "public/pagefind"
});
```
The `outputPath` option should contain the path to the desired Pagefind bundle directory. If relative, is relative to the current working directory of your Node process.
A response with an `errors` array containing error messages indicates that Pagefind failed to action this request.
### index.deleteIndex
Deletes the data for the given index from the Pagefind binary service. Doesn't affect any written files or Buffers returned by `getFiles()`.
```js
await index.deleteIndex();
```
Calling `index.getFiles()` or `index.writeFiles()` doesn't consume the index, and further modifications can be made. In situations where many indexes are being created, the `deleteIndex` call helps your clear out memory from the Pagefind binary service.
Reusing the `index` object you called this on will cause errors to be returned.
Not calling this method is fine — these indexes will be cleaned up when your Node process exits.
For more details on using Pagefind as a library, see [Indexing content using the NodeJS API](https://pagefind.app/docs/node-api/).

@@ -81,3 +81,4 @@ /**

/**
* The source path of the HTML file if it were to exist on disk. Must be a relative path.
* The source path of the HTML file if it were to exist on disk.
* Must be a relative path, or an absolute path within the current working directory.
* Pagefind will compute the result URL from this path.

@@ -84,0 +85,0 @@ *

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc