Giter VIP home page Giter VIP logo

mvw-search-index's Introduction

Lunr Search Index

Build State NPM version

About

Small module to generate a lunr index with result store.

Can e.g. be used to generate a search index for a static website, generated with hugo, jekyll, gatsby or manually.

Usage

First you have to install this package, then create the index that you use on e.g. a search page. Find samples for everything in the following chapters.

Installation

Use npm install --save-dev mvw-search-index to add the dependency to your package.json.

Index creation

There are multiple possibilities to generate the script. Some are demonstrated in the following sub chapters:

  • From CLI
  • From TypeScript
  • From nodejs

From CLI

mvw-search-index <glob> <destination> [css-selector]

For example:

mvw-search-index ./build/**/*.html ./build/index.json

Or from an npm script e.g. for a hugo page (has to be executed after page creation, obviously):

{
  "scripts": {
    "index": "mvw-search-index './public/**/*.html' './static/suche/index.json' 'main'"
  }
}

From TypeScript

import { SearchIndex } from "mvw-search-index";

let index = SearchIndex.createFromHtml(files, bodySelector);
// or: let index = SearchIndex.createFromInfo(info);
// or: let index = SearchIndex.createFromGlob(glob, bodySelector, cb);

fs.writeFileSync("index.json", JSON.stringify(index));

From node.js

"use strict";

const index = require("mvw-search-index");
const fs = require("fs")

index.SearchIndex.createFromGlob("./build/**/*.html",
                                 "main",
                                 (index) => fs.writeFileSync("./static/suche/index.json",
                                                             JSON.stringify(index)));

Sample usage of the created index

You can run npm run serve from this repository to run the sample site contained in ./demo.

This contains a very basic static website with a search form on the landing page index.html.

Releases

  • 2.2.16: updates dependencies
  • 2.2.10: updates dependencies
  • 2.2.9: gets rid of vinyl and provides a demo application
  • 2.1.4: - 2.1.12: dependency update
  • 2.1.3: added support of glob on API
  • 2.1.1: added CLI
  • 2.1.0: renamed referencedFile to href; allowing to parse HTML files directly
  • 2.0: Reason for major release: API break due to update to lunr 2.0.

mvw-search-index's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar tiliavir avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.