site-search
TypeScript icon, indicating that this package has built-in type declarations

0.0.10 • Public • Published

site-search

A lightweight self-hosted alternative to DocSearch.

site-search will run your website locally, crawl its pages and index their content in a lunr index. It also provides a node.js request handler that can be initialized with this index to provide a search endpoint for your website.

How to use

  1. Install the package
yarn add -D site-search
  1. Add a site-search.config.js to the root of your project containing
module.exports = {
  siteStartCmd: `yarn start`,
  siteOrigin: 'http://localhost:3000',
  startUrl: '/',
  outputPath: './site-search-index.json',
  rules: [
    {
      hierarchy: [
        { selector: 'h1' },
        { selector: 'h2' },
        { selector: 'h3' },
        { selector: 'h4' },
      ],
      text: { selector: 'p' },
    },
  ],
};
  1. Run site-search:

  2. Add the search endpoint to your app:

const path = require('path');
const handler = require('site-search/handler');
// ...
app.use(
  '/search',
  handler({
    filename: path.resolve(__dirname, '../site-search-index.json'),
  })
);
  1. Now you can use /search?q=foo to find documents matching "foo"

Config

siteStartCmd: Command that should be run to start your website siteOrigin: Url of where the running website can be reached startUrl: Url where crawling should start outputPath: Where to store the resulting index data rules: Rules to extract hierarchy. A bit similar to how Algolia does it

Readme

Keywords

none

Package Sidebar

Install

npm i site-search

Weekly Downloads

0

Version

0.0.10

License

MIT

Unpacked Size

105 kB

Total Files

30

Last publish

Collaborators

  • janpotoms