jekyll-lunr 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1638c072050e84916f892bb0f1db712e1dec6f17e65447d56e26200b2c26f73
4
- data.tar.gz: 60638fd94b811724c149a93f9c5a3f3863ae7717b09c3dad4faecaba75f18a58
3
+ metadata.gz: 90eef74feddc378ae3003d595921774aa577af3878613eaeb0fa3f455dc6b8f5
4
+ data.tar.gz: 25d9fec540c555b582dda9e7c6ab7988365e941a64632f7816251987a8928c42
5
5
  SHA512:
6
- metadata.gz: 3f79f6f47efd9717a470d3bb798922b37eb57cf9574ad7d2d46c634aad54e0e17f79ca335791300ab9eb3f7305af5dad415c695d7f14c671f7b63b8fcf6e55d3
7
- data.tar.gz: 29a76ac9fa8a33f5225b922bfd1baa8c3b95682444373dd5d8409f45c8ca89df8ee9d7b427ecc40ceb8e8327d306e902e989fe72f028f949c7995ca1e187b4c1
6
+ metadata.gz: c521546e2bf208f63a5f8564806bdbbc8fbbe148bea463a99cbe1a0417eddceb0348cc62a3fafacf1232a426c69462c906505b2cd16a7d97071fca67eef141ee
7
+ data.tar.gz: cd683d7daafda7439be1d6458bb7432d0fcf121052bdb5554bf3bf3972218a76e1e56bff6cef550392cb4b11d34791bbff3f1acfc97b632c38e794299ab872de
@@ -1,33 +1,46 @@
1
1
  // https://lunrjs.com/guides/index_prebuilding.html
2
- const lunr = require('lunr'),
3
- stdin = process.stdin,
4
- stdout = process.stdout,
5
- lang = process.argv[2]
6
2
 
7
- var buffer = []
3
+ process.stdin.resume()
4
+ process.stdin.setEncoding('utf8')
5
+
6
+ const lunr = require('lunr'),
7
+ readline = require('readline'),
8
+ lang = process.argv[2],
9
+ rl = readline.createInterface({
10
+ input: process.stdin,
11
+ output: process.stdout,
12
+ terminal: false
13
+ })
8
14
 
9
15
  // Load Lunr languages
10
- require("lunr-languages/lunr.stemmer.support")(lunr)
11
- require(`lunr-languages/lunr.${lang}`)(lunr)
12
- require("lunr-languages/lunr.multi")(lunr)
16
+ if (lang !== 'en') {
17
+ require("lunr-languages/lunr.stemmer.support")(lunr)
18
+ require(`lunr-languages/lunr.${lang}`)(lunr)
19
+ }
13
20
 
14
- stdin.resume()
15
- stdin.setEncoding('utf8')
21
+ let builder
16
22
 
17
- stdin.on('data', (data) => buffer.push(data))
23
+ // Process each document as a separate line
24
+ rl.on('line', line => {
25
+ const doc = JSON.parse(line)
18
26
 
19
- stdin.on('end', () => {
20
- const docs = JSON.parse(buffer.join(''))
21
- const fields = [].concat.apply([], docs.map((doc) => Object.keys(doc)))
22
- .filter((item, pos, self) => self.indexOf(item) == pos)
27
+ // If the builder isn't initialized, create it
28
+ if (!builder) {
29
+ builder = new lunr.Builder
30
+ builder.pipeline.add(
31
+ lunr.trimmer,
32
+ lunr.stopWordFilter,
33
+ lunr.stemmer
34
+ )
23
35
 
24
- // We keep this syntax because we don't know enough JS to make `this`
25
- // work with ES16 or whatever it's called
26
- var idx = lunr(function() {
27
- this.use(lunr.multiLanguage(lang, 'en'))
28
- fields.forEach((f) => this.field(f))
29
- docs.forEach((doc) => this.add(doc))
30
- })
36
+ builder.searchPipeline.add(lunr.stemmer)
31
37
 
32
- stdout.write(JSON.stringify(idx))
38
+ if (lang !== 'en') builder.use(lunr[lang])
39
+
40
+ Object.keys(doc).forEach(field => builder.field(field))
41
+ }
42
+
43
+ builder.add(doc)
33
44
  })
45
+
46
+ process.stdin.on('end', () => process.stdout.write(JSON.stringify(builder.build())))
@@ -86,7 +86,9 @@ module Jekyll
86
86
 
87
87
  def index
88
88
  Open3.popen2(indexer) do |stdin, stdout, wait|
89
- stdin.puts indexable_data.to_json
89
+ indexable_data.each do |data|
90
+ stdin.puts data.to_json
91
+ end
90
92
  stdin.close
91
93
 
92
94
  idx = File.new(index_file.path, 'w')
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Lunr
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-lunr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-27 00:00:00.000000000 Z
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: loofah