jekyll_lunrjs 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jekyll_lunrjs.rb +81 -0
  3. metadata +133 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 111b04d7cd4887f1d6e8d2b85306fd2dba9c004ba173dd24b19cd2f00d6692de
4
+ data.tar.gz: aeae1bb229f9e2933918e9559d00d8de87ef3b511335027779d46e5b2cdaf786
5
+ SHA512:
6
+ metadata.gz: 4472b07acbbe767a4a244d71d01e7761723b18909d18fa53bbcc8c14f96d29e4675f65fce92cc0182c1dcdce066882409b1eabe52ecd65725d017fbdfa72be76
7
+ data.tar.gz: 1f476e2568d4678bdf982a4ae3765b225b4c289545938d88ffab4f1de2f58f1d82f01b6df979e37824ac8973e3e1a029635416a4f00f755f785e74b03e3f0eec
@@ -0,0 +1,81 @@
1
+ require "jekyll"
2
+ require 'v8'
3
+ require 'json'
4
+
5
+ module Jekyll
6
+ docs = Array.new
7
+ myHash = Hash.new
8
+
9
+ Jekyll::Hooks.register :site, :post_write do |site|
10
+
11
+ #input values
12
+ lunr_config_id = site.config["lunr_config_id"]
13
+ lunr_config_boost = site.config["lunr_config_boost"]
14
+
15
+ #This is specific to indexing with lunrjs
16
+ #lunr_config_id = {:id => 'id'} # structure of index
17
+ #lunr_config_boost= {:fields => {:title => 10, :tag => 20}} #structure for boost
18
+ lunr_config = lunr_config_boost.merge(lunr_config_id)
19
+
20
+ #The path to the files
21
+ folder_root = site.source
22
+ file_path = site.config['path_json'] #The path where it saves the json search file
23
+ file_data_json = site.config['data_path_json'] #The path where it saves the json file with all data
24
+ folder_lunar_js = folder_root + '/_site/assets/js/lunr/lunr.js' # Path lunrjs
25
+ folder_json = folder_root + '/_site/assets/json' #Path folder json files
26
+
27
+
28
+ # Comprobamos que existe la carpeta de los jsons
29
+ if !Dir.exist?(folder_json)
30
+ Dir.mkdir(folder_json)
31
+ end
32
+ #Comprobamos que existe el fichero en la carpeta con el json indexado
33
+ if file_path.nil?
34
+ file_path = folder_json.to_s + '/search.json'
35
+ end
36
+ #Comprobamos que existe el fichero en la carpeta con el json de datos
37
+ if file_data_json.nil?
38
+ file_data_json = folder_json.to_s + '/data.json'
39
+ end
40
+ # Comprobamos que existe el lunarjs
41
+ if !File.exist?(folder_lunar_js)
42
+ raise "Could not find lunr.js into #{folder_lunar_js}"
43
+ end
44
+
45
+ cxt = V8::Context.new
46
+ cxt.load(folder_lunar_js)
47
+ # add new method to lunr index
48
+ cxt.eval('lunr.Index.prototype.indexJson = function () {return JSON.stringify(this);}')
49
+ #Get the lunjs object
50
+ val = cxt.eval('lunr')
51
+ #puts val.version
52
+ #puts "### file_path '#{file_path}'"
53
+ #This is specific to 2.x versions.
54
+ lunr_conf = proc do |this|
55
+ this.ref('id')
56
+ lunr_config[:fields].each_pair do |name, boost|
57
+ this.field(name, {:boost => boost})
58
+ end
59
+ for page in site.pages
60
+ if !page.data['metadata'].nil?
61
+ valor = page.data['metadata']
62
+ tags_search = valor['tags']
63
+ tags_search.split(',').each do |tag_search|
64
+ myHash = Hash[:id => page.url.to_s, :title => page.data['title'].to_s, :tag => tag_search.to_s, :summary => page.content.split(/[\r\n]+/).slice(0).gsub(/<\/?[^>]*>/, "")]
65
+ #puts 'Name tag '+ tag_search
66
+ #puts 'Url of site ' + page.url
67
+ #puts 'Tags for search ' +valor[tag_search].to_s
68
+ this.add(myHash)
69
+ end
70
+ docs.push(myHash)
71
+ end
72
+ end
73
+ end
74
+ idx = val.call(lunr_conf)
75
+ total = idx.indexJson()
76
+ # Write the file index
77
+ File.open(file_path, 'w') { |f| f.write(total) }
78
+ # Write the file data
79
+ File.open(file_data_json, 'w') { |f| f.write(docs.to_json) }
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_lunrjs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jorge Novo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: therubyracer
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.12.3
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.12.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '12.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '12.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop-jekyll
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.4'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.4'
103
+ description:
104
+ email: jnovos@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - lib/jekyll_lunrjs.rb
110
+ homepage: https://github.com/jnovos/lunarjs-jekyll
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 2.4.0
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.3.8
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Index LunarJs plugin for Jekyll
133
+ test_files: []