jekyll-lunr 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-lunr.rb +5 -4
- data/lib/jekyll/lunr.rb +70 -51
- metadata +22 -20
- data/.gitignore +0 -9
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -5
- data/Rakefile +0 -12
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/jekyll-lunr.gemspec +0 -36
- data/lib/jekyll/lunr/version.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e18aceb9b02aa376f8c9006f399c0135362db2cdf2c429876e7e4a5856b560d8
|
4
|
+
data.tar.gz: e3fed8cb38dd1610db828a54ae1b3a9361b795e9b816f2df4c8826f72d566bd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 530ec545d0ce6d20ed562534d2e77f0d6abdac0510e816f525fd12196d05d675fd0286190944aaebed329399af744451115324a43aa285062b8c92e04f4409d3
|
7
|
+
data.tar.gz: 88a4ef07c75174d03aaa89ebf0834b1665b53c3219c0c89a3d72e36915149270142b76d7ee9aa630c947dcb2b68a0cc4ad65195fee35761345c707513f11540f
|
data/lib/jekyll-lunr.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'jekyll/lunr'
|
2
2
|
|
3
3
|
Jekyll::Hooks.register :site, :pre_render do |site|
|
4
|
-
lunr = Jekyll::Lunr::Indexer.new site: site
|
5
|
-
|
6
4
|
Jekyll.logger.info 'Generating data.json'
|
7
|
-
|
5
|
+
site.indexer.write
|
8
6
|
|
9
7
|
Jekyll.logger.info 'Generating idx.json'
|
10
|
-
|
8
|
+
site.indexer.index
|
9
|
+
|
10
|
+
Jekyll.logger.info 'Freeing memory'
|
11
|
+
site.indexer.free
|
11
12
|
end
|
data/lib/jekyll/lunr.rb
CHANGED
@@ -9,60 +9,81 @@ module Jekyll
|
|
9
9
|
# Error
|
10
10
|
class Error < StandardError; end
|
11
11
|
|
12
|
+
module IndexableSite
|
13
|
+
def self.included(base)
|
14
|
+
base.class_eval do
|
15
|
+
def indexer
|
16
|
+
@indexer ||= Jekyll::Lunr::Indexer.new self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module IndexableDocument
|
23
|
+
def self.included(base)
|
24
|
+
base.class_eval do
|
25
|
+
def to_data
|
26
|
+
data
|
27
|
+
.slice(*site.indexer.fields)
|
28
|
+
.transform_values { |value| extract_data_recursively(value) }
|
29
|
+
.merge('content' => Loofah.fragment(content).to_text,
|
30
|
+
'url' => url,
|
31
|
+
'id' => url,
|
32
|
+
'year' => date&.year)
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_data_recursively(value)
|
36
|
+
case value
|
37
|
+
when Array then value.map { |v| extract_data(v) }
|
38
|
+
when Hash then value.transform_values { |v| extract_data(v) }
|
39
|
+
when Jekyll::Document then extract_data(value)
|
40
|
+
when Jekyll::Page then extract_data(value)
|
41
|
+
else value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_data(value)
|
46
|
+
value.respond_to?(:to_data) ? value.to_data : value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
12
52
|
# Generates a Lunr index from documents
|
13
53
|
class Indexer
|
14
|
-
attr_reader :site
|
54
|
+
attr_reader :site
|
15
55
|
|
16
|
-
def initialize(site
|
56
|
+
def initialize(site)
|
17
57
|
@site = site
|
18
58
|
end
|
19
59
|
|
20
60
|
# The data is the register where Lunr looks for results.
|
21
61
|
# TODO: Write a single data file per doc?
|
22
62
|
def data
|
23
|
-
@data ||= documents.map
|
24
|
-
doc.data.dup
|
25
|
-
.keep_if { |k,_| fields.include? k }
|
26
|
-
.merge(content: Loofah.fragment(doc.content).to_text,
|
27
|
-
url: doc.url,
|
28
|
-
id: doc.url,
|
29
|
-
year: doc.date.year)
|
30
|
-
end.compact
|
63
|
+
@data ||= site.documents.map(&:to_data)
|
31
64
|
end
|
32
65
|
|
33
66
|
def data_file
|
34
|
-
@data_file ||= Jekyll::StaticFile.new(
|
35
|
-
site,
|
36
|
-
site.source,
|
37
|
-
'.',
|
38
|
-
'data.json'
|
39
|
-
)
|
67
|
+
@data_file ||= Jekyll::StaticFile.new(site, site.source, '.', 'data.json')
|
40
68
|
end
|
41
69
|
|
42
70
|
# Convert data to strings since Lunr can't index objects
|
43
|
-
# TODO: make elegant
|
44
71
|
def indexable_data
|
45
72
|
@indexable_data ||= data.map do |d|
|
46
73
|
d.transform_values do |v|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
v.join(', ')
|
52
|
-
end
|
53
|
-
elsif v.is_a? Hash
|
54
|
-
v.values.join(', ')
|
55
|
-
else
|
56
|
-
v.to_s
|
74
|
+
case v
|
75
|
+
when Array then v.join(', ')
|
76
|
+
when Hash then v.values.join(', ')
|
77
|
+
else v.to_s
|
57
78
|
end
|
58
79
|
end
|
59
80
|
end
|
60
81
|
end
|
61
82
|
|
62
83
|
def write
|
63
|
-
|
64
|
-
|
65
|
-
|
84
|
+
File.open(data_file.path, 'w') do |df|
|
85
|
+
df.write data.to_json
|
86
|
+
end
|
66
87
|
|
67
88
|
site.static_files << data_file
|
68
89
|
end
|
@@ -72,28 +93,27 @@ module Jekyll
|
|
72
93
|
end
|
73
94
|
|
74
95
|
def index_file
|
75
|
-
@index_file ||= Jekyll::StaticFile.new(
|
76
|
-
site,
|
77
|
-
site.source,
|
78
|
-
'.',
|
79
|
-
'idx.json'
|
80
|
-
)
|
96
|
+
@index_file ||= Jekyll::StaticFile.new(site, site.source, '.', 'idx.json')
|
81
97
|
end
|
82
98
|
|
83
99
|
def indexer
|
84
|
-
|
100
|
+
@indexer ||= ['node', File.join(dir, 'lib', 'assets', 'javascript', 'indexer.js'), lang].freeze
|
101
|
+
end
|
102
|
+
|
103
|
+
def env
|
104
|
+
@env ||= { 'NODE_PATH' => File.join(site.source, 'node_modules') }
|
85
105
|
end
|
86
106
|
|
87
107
|
def index
|
88
|
-
Open3.popen2(indexer) do |stdin, stdout, wait|
|
108
|
+
Open3.popen2(env, *indexer) do |stdin, stdout, wait|
|
89
109
|
indexable_data.each do |data|
|
90
110
|
stdin.puts data.to_json
|
91
111
|
end
|
92
112
|
stdin.close
|
93
113
|
|
94
|
-
|
95
|
-
|
96
|
-
|
114
|
+
File.open(index_file.path, 'w') do |idx|
|
115
|
+
idx.write(stdout.read)
|
116
|
+
end
|
97
117
|
|
98
118
|
site.static_files << index_file
|
99
119
|
|
@@ -103,23 +123,22 @@ module Jekyll
|
|
103
123
|
|
104
124
|
# Site lang
|
105
125
|
def lang
|
106
|
-
@lang ||= site.config.dig('lang')
|
126
|
+
@lang ||= site.config.dig('lang').freeze
|
107
127
|
end
|
108
128
|
|
109
129
|
# Indexable fields
|
110
130
|
def fields
|
111
|
-
@fields ||= ((site.config.dig('jekyll-lunr', 'fields') || []) +
|
131
|
+
@fields ||= Set.new((site.config.dig('jekyll-lunr', 'fields') || []) + %w[title description]).freeze
|
112
132
|
end
|
113
133
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
# Indexable documents
|
119
|
-
# TODO: make configurable
|
120
|
-
def documents
|
121
|
-
site.collections.values.map(&:docs).flatten
|
134
|
+
def free
|
135
|
+
@data = nil
|
136
|
+
@indexable_data = nil
|
122
137
|
end
|
123
138
|
end
|
124
139
|
end
|
125
140
|
end
|
141
|
+
|
142
|
+
Jekyll::Site.include Jekyll::Lunr::IndexableSite
|
143
|
+
Jekyll::Document.include Jekyll::Lunr::IndexableDocument
|
144
|
+
Jekyll::Page.include Jekyll::Lunr::IndexableDocument
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: loofah
|
@@ -57,46 +57,48 @@ email:
|
|
57
57
|
- f@sutty.nl
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
|
-
extra_rdoc_files:
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README.md
|
62
|
+
- LICENSE.txt
|
61
63
|
files:
|
62
|
-
- ".gitignore"
|
63
|
-
- CODE_OF_CONDUCT.md
|
64
|
-
- Gemfile
|
65
64
|
- LICENSE.txt
|
66
65
|
- README.md
|
67
|
-
- Rakefile
|
68
|
-
- bin/console
|
69
|
-
- bin/setup
|
70
|
-
- jekyll-lunr.gemspec
|
71
66
|
- lib/assets/javascript/indexer.js
|
72
67
|
- lib/jekyll-lunr.rb
|
73
68
|
- lib/jekyll/lunr.rb
|
74
|
-
- lib/jekyll/lunr/version.rb
|
75
69
|
homepage: https://0xacab.org/sutty/jekyll/jekyll-lunr
|
76
70
|
licenses:
|
77
71
|
- GPL-3.0
|
78
72
|
metadata:
|
79
|
-
|
73
|
+
bug_tracker_uri: https://0xacab.org/sutty/jekyll/jekyll-lunr/issues
|
80
74
|
homepage_uri: https://0xacab.org/sutty/jekyll/jekyll-lunr
|
81
75
|
source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-lunr
|
82
|
-
changelog_uri: https://0xacab.org/sutty/jekyll/jekyll-lunr
|
83
|
-
|
84
|
-
|
76
|
+
changelog_uri: https://0xacab.org/sutty/jekyll/jekyll-lunr/-/blob/master/CHANGELOG.md
|
77
|
+
documentation_uri: https://rubydoc.info/gems/jekyll-lunr
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- "--title"
|
81
|
+
- jekyll-lunr - Lunr indexer for Jekyll
|
82
|
+
- "--main"
|
83
|
+
- README.md
|
84
|
+
- "--line-numbers"
|
85
|
+
- "--inline-source"
|
86
|
+
- "--quiet"
|
85
87
|
require_paths:
|
86
88
|
- lib
|
87
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
90
|
requirements:
|
89
91
|
- - ">="
|
90
92
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
93
|
+
version: 2.6.0
|
92
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
95
|
requirements:
|
94
96
|
- - ">="
|
95
97
|
- !ruby/object:Gem::Version
|
96
98
|
version: '0'
|
97
99
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
100
|
+
rubygems_version: 3.1.2
|
101
|
+
signing_key:
|
100
102
|
specification_version: 4
|
101
103
|
summary: Lunr indexer for Jekyll
|
102
104
|
test_files: []
|
data/.gitignore
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at f@sutty.nl. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'jekyll/lunr'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/jekyll-lunr.gemspec
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'jekyll/lunr/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'jekyll-lunr'
|
9
|
-
spec.version = Jekyll::Lunr::VERSION
|
10
|
-
spec.authors = ['f']
|
11
|
-
spec.email = ['f@sutty.nl']
|
12
|
-
|
13
|
-
spec.summary = 'Lunr indexer for Jekyll'
|
14
|
-
spec.description = 'Builds the LunrJS index and data documents during site generation'
|
15
|
-
spec.homepage = 'https://0xacab.org/sutty/jekyll/jekyll-lunr'
|
16
|
-
spec.license = 'GPL-3.0'
|
17
|
-
|
18
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
-
|
20
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
22
|
-
spec.metadata['changelog_uri'] = spec.homepage
|
23
|
-
|
24
|
-
# Specify which files should be added to the gem when it is released.
|
25
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
-
end
|
29
|
-
spec.bindir = 'exe'
|
30
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ['lib']
|
32
|
-
|
33
|
-
spec.add_dependency 'loofah', '~> 2.4'
|
34
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
35
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
-
end
|