middleman-lunrjs 0.0.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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/lib/middleman-lunrjs/extension.rb +100 -0
- data/lib/middleman-lunrjs/version.rb +6 -0
- data/lib/middleman-lunrjs.rb +9 -0
- data/lib/middleman_extension.rb +1 -0
- data/make_gem.sh +8 -0
- data/middleman-lunrjs.gemspec +25 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c57f358905b1b42f443dbff6462c1da38c5b41e8
|
4
|
+
data.tar.gz: 0134b5a94988bf11e5b3d656bd324e84d7f1c833
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1880bde24e526c1da5c1f46dc155a92927d3e381512b5a0f005540dcb85a8d7278ebbd725fc1e27ae8f5cab4392ae722593d32413c3608da9186fa0a01708103
|
7
|
+
data.tar.gz: 7f7b573c049219f8eb92c1099d373f572accabf86fa1e00f76156683b40b01c95c1328a1f2c265be85a94a3bded72fee85a3d2fd554855b6d7f6bff446853519
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Jorge Novo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Middleman::Lunrjs
|
2
|
+
|
3
|
+
This is a plugin the lunr-js for middleman
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'middleman-lunrjs'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install middleman-lunrjs
|
20
|
+
|
21
|
+
You can install the gem in local with shell script
|
22
|
+
|
23
|
+
$ ./make_gem.sh
|
24
|
+
|
25
|
+
You have to install lunr.js into the javascript folder of middlemanapp project
|
26
|
+
|
27
|
+
$ bower install lunr.js
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
Put in Gemfile the Middleman extension lunrjs
|
31
|
+
|
32
|
+
$ gem "middleman-lunrjs"
|
33
|
+
|
34
|
+
and config.rb
|
35
|
+
|
36
|
+
configure :build do
|
37
|
+
activate :lunrjs do |config|
|
38
|
+
config.index_tags = %w(title ) # Optional Hash with tags of metadata
|
39
|
+
config.file_path # Optional folder where save index json file. By default "source/json/search.json".
|
40
|
+
config.lunr_config # Optional Hash with config of lunrjs. See http://lunrjs.com/docs/#lunr
|
41
|
+
config.lunr_javascript_dir = /source/javascripts/bower_components/lunr.js/lunr.js # Optional directory + file where the lunar.js is.
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/jnovos/middleman-lunrjs/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
52
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "middleman-core"
|
2
|
+
require 'v8'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Middleman
|
6
|
+
module Indexer
|
7
|
+
class Lunrjs < Middleman::Extension
|
8
|
+
# Options
|
9
|
+
option :file_path, nil, 'The path where it saves the json file'
|
10
|
+
option :index_tags, [], 'are tags in yaml or data file for search'
|
11
|
+
option :lunr_config_id, {:id => 'id'}, 'structure of index'
|
12
|
+
option :lunr_config_boost, {:fields => {:title => 10, :path => 20}}, 'structure for boost'
|
13
|
+
option :lunr_javascript_dir, '/bower_components/lunr.js/lunr.js', 'Directory by default lunar.js'
|
14
|
+
|
15
|
+
def initialize(app, options_hash={}, &block)
|
16
|
+
puts ('Init lunrjs ')
|
17
|
+
super
|
18
|
+
return unless app.environment == :build
|
19
|
+
opts = options.dup.to_h
|
20
|
+
opts.delete_if { |k, v| v.nil? }
|
21
|
+
app.before_build do
|
22
|
+
opts[:sitemap] = sitemap
|
23
|
+
Indexer.new(app, opts)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Indexer
|
28
|
+
def initialize(app, opts = {})
|
29
|
+
puts ' Run Indexer Inizialite '
|
30
|
+
tags_search = opts[:index_tags]
|
31
|
+
file_path = opts[:file_path]
|
32
|
+
lunr_config_id = opts[:lunr_config_id]
|
33
|
+
lunr_config_boost = opts[:lunr_config_boost]
|
34
|
+
lunr_js_directory = opts[:lunr_javascript_dir]
|
35
|
+
lunr_config = lunr_config_boost.merge(lunr_config_id)
|
36
|
+
|
37
|
+
sitemap = opts[:sitemap]
|
38
|
+
folder_root = app.root_path
|
39
|
+
folder_source = app.root_path + app.inst.source.to_s
|
40
|
+
instsource = app.inst.source.to_s
|
41
|
+
docs = Array.new
|
42
|
+
folder_json = folder_source.to_s + '/json'
|
43
|
+
if !Dir.exist?(folder_json)
|
44
|
+
Dir.mkdir(folder_json)
|
45
|
+
end
|
46
|
+
if file_path.nil?
|
47
|
+
file_path = folder_source.to_s + '/json/search.json'
|
48
|
+
end
|
49
|
+
sitemap.resources.each do |resource|
|
50
|
+
tags_search.each do |tag_search|
|
51
|
+
if resource.data[tag_search] && !resource.url.to_s.start_with?('/localizable/')
|
52
|
+
doc = Hash[:id => resource.url.to_s, :title => resource.data[tag_search], :path => resource.url.to_s]
|
53
|
+
puts 'Name tag '+ tag_search
|
54
|
+
puts 'Url of site ' + resource.url
|
55
|
+
puts 'Tags for search ' + resource.data[tag_search].to_s
|
56
|
+
docs.push(doc)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
if File.exist?(folder_root.to_s + '/.bowerrc')
|
61
|
+
file=File.open(folder_root.to_s + '/.bowerrc').read
|
62
|
+
data_hash = JSON.parse(file)
|
63
|
+
#path of lunr.js folder
|
64
|
+
folder_lunar_js = folder_root.to_s + '/' + data_hash['directory'].to_s + '/lunr.js/lunr.js'
|
65
|
+
else
|
66
|
+
#path of lunr.js folder
|
67
|
+
folder_lunar_js = folder_root.to_s + lunr_js_directory
|
68
|
+
puts 'pasaaaaaaaaaaaaa'
|
69
|
+
end
|
70
|
+
puts 'XXXXXXXXXXXXXXXXXXXXXX' + folder_root.to_s
|
71
|
+
puts 'XXXXXXXXXXXXXXXXXXXXXX' + folder_lunar_js
|
72
|
+
|
73
|
+
if !File.exist?(folder_lunar_js)
|
74
|
+
raise "Could not find lunr.js into #{folder_lunar_js}"
|
75
|
+
end
|
76
|
+
cxt = V8::Context.new
|
77
|
+
cxt.load(folder_lunar_js)
|
78
|
+
# add new method to lunr index
|
79
|
+
cxt.eval('lunr.Index.prototype.indexJson = function () {return JSON.stringify(this);}')
|
80
|
+
#Get the lunjs object
|
81
|
+
val = cxt.eval('lunr')
|
82
|
+
lunr_conf = proc do |this|
|
83
|
+
this.ref('id')
|
84
|
+
lunr_config[:fields].each_pair do |name, boost|
|
85
|
+
this.field(name, {:boost => boost})
|
86
|
+
end
|
87
|
+
end
|
88
|
+
puts val.version
|
89
|
+
#Get the IDX Object
|
90
|
+
idx = val.call(lunr_conf)
|
91
|
+
docs.each do |doc|
|
92
|
+
idx.add(doc)
|
93
|
+
end
|
94
|
+
total = idx.indexJson()
|
95
|
+
File.open(file_path, 'w') { |f| f.write(total) }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'middleman-lunrjs'
|
data/make_gem.sh
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require File.expand_path('../lib/middleman-lunrjs/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = Middleman::Lunrjs::PACKAGE
|
7
|
+
spec.version = Middleman::Lunrjs::VERSION
|
8
|
+
spec.authors = ["Jorge Novo"]
|
9
|
+
spec.email = ["jnovos@gmail.com"]
|
10
|
+
spec.summary = %q{This is a plugin of middleman for lunrjs.}
|
11
|
+
spec.description = %q{Write a longer description. Optional.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'middleman-core', '~> 3.0'
|
21
|
+
spec.add_runtime_dependency("therubyracer", '~> 0.8')
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-lunrjs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jorge Novo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: therubyracer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Write a longer description. Optional.
|
70
|
+
email:
|
71
|
+
- jnovos@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/middleman-lunrjs.rb
|
81
|
+
- lib/middleman-lunrjs/extension.rb
|
82
|
+
- lib/middleman-lunrjs/version.rb
|
83
|
+
- lib/middleman_extension.rb
|
84
|
+
- make_gem.sh
|
85
|
+
- middleman-lunrjs.gemspec
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.2.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: This is a plugin of middleman for lunrjs.
|
110
|
+
test_files: []
|