# Vuepress-plugin-offlinesearch

The search is based on the official vuepress search plugin. But instead of just indexing headers, it leverages lunrjs to enable a (simplistic) full-text search. Although the Algolia search is great, it may not be an option for teams sitting behind a corporate firewall.

For each search result, the page title and the title of the section, where the text was found, are displayed. The links take you right to that section.

# Demo

We created a sample project that showcases the search. Check it out here: https://datev.gitlab.io/vuepress-plugin-offlinesearch-example/

# Usage

  • Add the plugin as dependency:
npm i @datev/vuepress-plugin-offlinesearch
  • Add the plugin to .vuepress/config.js
    plugins: [
        ['@datev/vuepress-plugin-offlinesearch', {searchMaxSuggestions: 7, documents: require('../.vuepress/public/documents.json')}]

# Options

# searchMaxSuggestions

Defines the maximum number of search results displayed.

  • Type: number
  • Default: 5 Disclaimer: taken form here

# searchHotkeys

  • Configure the hotkeys which when pressed will focus the search box. Set to an empty array to disable this feature.
  • Type: Array<string>
  • Default: ['s', '/']` Disclaimer: taken form here

# activateStemming

  • Activates lunr's stemming feature. In our experience, the search works better when this option is disabled. Please refer to the official docs for more information on stemming.
  • Type: boolean
  • Default: false

# documents

  • Path to your documents file, e.g. '../.vuepress/public/documents.json'. Note that the file needs to be deployed as an asset.
  • Type: string
  • required

The plugin requires the following json structure to build its index. The json can be either generated by your own generator, by hand or by using our npm-cli tool

If you choose to use the vuepress-documents-parser-cli, generating the documents.json file is as simple as installing the package with

npm i @datev/vuepress-offlinesearch-parse-cli

and executing the command generate-documents from your command line.

If you choose to build your own documents.json file, please comply with following json structure:

    "pageTitle": "exampleTitle",
    "sectionHeader": "ExampleHeader",
    "sectionSlug": "/exampleSite.html#exampleSection",
    "sectionContent": "This is example Content"

Note that the sectionHeader and sectionContent are the field that will later be used to match search queries.

After these steps the search for your vuepress Site should be set up and ready to go.

# Contributing

Contributions are welcome !

If you want to contribute or have a question please just open a new Issue.

Made with ❤️ by Ahmad Mostafa - @z3by