Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gitbook-plugin-lunr

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitbook-plugin-lunr - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

2

assets/search-lunr.js

@@ -59,2 +59,2 @@ require([

});
});
});
var lunr = require('lunr');
var Entities = require('html-entities').AllHtmlEntities;
// Create search index
var searchIndex = lunr(function () {
this.ref('url');
var Html = new Entities();
this.field('title', { boost: 10 });
this.field('body');
});
var searchIndex;
// Called with the `this` context provided by Gitbook
function getSearchIndex(context) {
if (!searchIndex) {
// Create search index
var ignoreSpecialCharacters = context.config.get('pluginsConfig.lunr.ignoreSpecialCharacters') || context.config.get('lunr.ignoreSpecialCharacters');
searchIndex = lunr(function () {
this.ref('url');
this.field('title', { boost: 10 });
this.field('keywords', { boost: 15 });
this.field('body');
if (!ignoreSpecialCharacters) {
// Don't trim non words characters (to allow search such as "C++")
this.pipeline.remove(lunr.trimmer);
}
});
}
return searchIndex;
}
// Map of Lunr ref to document

@@ -33,8 +50,11 @@ var documentsStore = {};

var text, maxIndexSize;
maxIndexSize = this.config.get('pluginsConfig.search.maxIndexSize') || this.config.get('search.maxIndexSize');
maxIndexSize = this.config.get('pluginsConfig.lunr.maxIndexSize') || this.config.get('lunr.maxIndexSize');
this.log.debug.ln('index page', page.path);
// Transform as TEXT
text = page.content.replace(/(<([^>]+)>)/ig, '');
text = page.content;
// Decode HTML
text = Html.decode(text);
// Strip HTML tags
text = text.replace(/(<([^>]+)>)/ig, '');

@@ -48,2 +68,7 @@ indexSize = indexSize + text.length;

var keywords = [];
if (page.search) {
keywords = page.search.keywords || [];
}
// Add to index

@@ -54,2 +79,3 @@ var doc = {

summary: page.description,
keywords: keywords.join(' '),
body: text

@@ -59,3 +85,3 @@ };

documentsStore[doc.url] = doc;
searchIndex.add(doc);
getSearchIndex(this).add(doc);

@@ -71,3 +97,3 @@ return page;

return this.output.writeFile('search_index.json', JSON.stringify({
index: searchIndex,
index: getSearchIndex(this),
store: documentsStore

@@ -74,0 +100,0 @@ }));

@@ -5,3 +5,3 @@ {

"main": "index.js",
"version": "1.1.0",
"version": "1.2.0",
"engines": {

@@ -11,4 +11,5 @@ "gitbook": ">=3.0.0-pre.0"

"dependencies": {
"lunr": "0.5.12",
"gitbook-plugin-search": "*"
"gitbook-plugin-search": "*",
"html-entities": "1.2.0",
"lunr": "0.5.12"
},

@@ -26,7 +27,12 @@ "homepage": "https://github.com/GitbookIO/plugin-lunr",

"properties": {
"maxIndexSize": {
"type": "number",
"title": "Limit size for the index",
"default": 1000000
}
"maxIndexSize": {
"type": "number",
"title": "Limit size for the index",
"default": 1000000
},
"ignoreSpecialCharacters": {
"type": "boolean",
"title": "Ignore special characters in words",
"default": false
}
}

@@ -33,0 +39,0 @@ },

@@ -33,4 +33,20 @@ # lunr

### Disable indexing of a page
### Adding keywords to a page
You can specify explicit keywords for any page. When searching for these keywords, the page will rank higher in the results.
```md
---
search:
keywords: ['keyword1', 'keyword2', 'etc.']
---
# My Page
This page will rank better if we search for 'keyword1'.
```
### Disabling indexing of a page
You can disable the indexing of a specific page by adding a YAML header to the page:

@@ -48,1 +64,15 @@

### Ignoring special characters
By default, special characters will be taken into account, to allow special searches like "C++" or "#word". You can disable this if your text is essentially English prose with the `ignoreSpecialCharacters` option:
```js
{
"pluginsConfig": {
"lunr": {
"ignoreSpecialCharacters": true
}
}
}
```
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