algoliasearch-jekyll 0.3.0 → 0.4.0
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 +4 -4
- data/README.md +34 -2
- data/VERSION +1 -1
- data/algoliasearch-jekyll.gemspec +4 -3
- data/lib/push.rb +17 -14
- data/scripts/git_hooks/pre-commit +5 -0
- data/scripts/git_hooks/pre-push +6 -0
- data/spec/fixtures/page2/index.html +6 -0
- data/spec/push_spec.rb +18 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01338e91416f0b4f645c7e45859916acbc9aaf95
|
4
|
+
data.tar.gz: 44fcc786e516d984eb6855ae49d38c55a870cd04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc60ade6df6d584e3df15c680e0dd6c01b65b4c9425139f698abecaef37d1bf0e3cc1d877669344b91495f1162e9fcddf01b23cf53b653dd57c569cac36503dd
|
7
|
+
data.tar.gz: 29789884292d9814e43efa8d7b7201ff07e5b3994143279d1a53e2fbbf4eb9485707872aa5102b09bc9b4e1e84ceaafdae0871d45c0fbf8b736a27804b489a56
|
data/README.md
CHANGED
@@ -134,10 +134,42 @@ class AlgoliaSearchRecordExtractor
|
|
134
134
|
end
|
135
135
|
```
|
136
136
|
|
137
|
+
The `AlgoliaSearchJekyllPush` class also lets user define the
|
138
|
+
`custom_hook_excluded_file?` method. This method is called on every file that
|
139
|
+
the plugin thinks it should parse and index. If it returns `true`, the file is
|
140
|
+
not indexed. You can add here your custom logic to exclude some files.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
class AlgoliaSearchJekyllPush < Jekyll::Command
|
144
|
+
class << self
|
145
|
+
# Hook to exclude some files from indexing
|
146
|
+
def custom_hook_excluded_file?(file)
|
147
|
+
return true if filepath =~ %r{^/excluded_dir/}
|
148
|
+
false
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
## Command line
|
155
|
+
|
156
|
+
Here is the list of command line options you can pass to the `jekyll algolia
|
157
|
+
push` command:
|
158
|
+
|
159
|
+
| Flag | Description |
|
160
|
+
| ---- | ----- |
|
161
|
+
| `--config ./_config.yml` | You can here specify the config file to use. Default is `_config.yml` |
|
162
|
+
| `--future` | With this flag, the command will also index posts with a future date |
|
163
|
+
| `--limit_posts 10` | Limits the number of posts to parse and index |
|
164
|
+
| `--drafts` | Index drafts in the `_drafts` folder as well |
|
165
|
+
| `--dry-run` or `-n` | Do a dry run, do not actually push anything to your index |
|
166
|
+
| `--verbose` | Display more information about what is going to be indexed |
|
167
|
+
|
137
168
|
## Dependencies
|
138
169
|
|
139
|
-
The `algoliasearch-jekyll` plugin works
|
140
|
-
2.5, with a version of Ruby of at least 2.0.
|
170
|
+
The `algoliasearch-jekyll` plugin works for versions of Jekyll starting from
|
171
|
+
2.5, with a version of Ruby of at least 2.0. You also need
|
172
|
+
[Bundler](http://bundler.io/) to easily add the gem as a dependency to Jekyll.
|
141
173
|
|
142
174
|
## Searching
|
143
175
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: algoliasearch-jekyll 0.
|
5
|
+
# stub: algoliasearch-jekyll 0.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "algoliasearch-jekyll"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Tim Carry"]
|
14
|
-
s.date = "2015-07-
|
14
|
+
s.date = "2015-07-28"
|
15
15
|
s.description = "Index all your pages and posts to an Algolia index with `jekyll algolia push`"
|
16
16
|
s.email = "tim@pixelastic.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
|
|
63
63
|
"spec/fixtures/excluded.html",
|
64
64
|
"spec/fixtures/hierarchy.md",
|
65
65
|
"spec/fixtures/index.html",
|
66
|
+
"spec/fixtures/page2/index.html",
|
66
67
|
"spec/fixtures/weight.md",
|
67
68
|
"spec/push_spec.rb",
|
68
69
|
"spec/record_extractor_spec.rb",
|
data/lib/push.rb
CHANGED
@@ -41,13 +41,13 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
|
|
41
41
|
end
|
42
42
|
return false unless allowed_extensions.include?(extname)
|
43
43
|
|
44
|
-
return false if excluded_file?(file
|
44
|
+
return false if excluded_file?(file)
|
45
45
|
|
46
46
|
true
|
47
47
|
end
|
48
48
|
|
49
49
|
# Check if the file is in the list of excluded files
|
50
|
-
def excluded_file?(
|
50
|
+
def excluded_file?(file)
|
51
51
|
excluded = [
|
52
52
|
%r{^page([0-9]*)/index\.html}
|
53
53
|
]
|
@@ -55,10 +55,21 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
|
|
55
55
|
excluded += (@config['algolia']['excluded_files'] || [])
|
56
56
|
end
|
57
57
|
|
58
|
+
# Exclude files explicitly excluded in _config
|
58
59
|
excluded.each do |pattern|
|
59
60
|
pattern = /#{Regexp.quote(pattern)}/ if pattern.is_a? String
|
60
|
-
return true if
|
61
|
+
return true if file.path =~ pattern
|
61
62
|
end
|
63
|
+
|
64
|
+
# Call user custom exclude hook on remaining files
|
65
|
+
return true if custom_hook_excluded_file?(file)
|
66
|
+
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
# User custom method to exclude some files when algolia.excluded_files is
|
71
|
+
# not enough
|
72
|
+
def custom_hook_excluded_file?(_file)
|
62
73
|
false
|
63
74
|
end
|
64
75
|
|
@@ -76,6 +87,7 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
|
|
76
87
|
Jekyll.logger.info "Extracting data from #{file.path}" if is_verbose
|
77
88
|
new_items = AlgoliaSearchRecordExtractor.new(file).extract
|
78
89
|
next if new_items.nil?
|
90
|
+
ap new_items if is_verbose
|
79
91
|
|
80
92
|
items += new_items
|
81
93
|
end
|
@@ -89,23 +101,14 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
|
|
89
101
|
def configure_index(index)
|
90
102
|
settings = {
|
91
103
|
distinct: true,
|
92
|
-
attributeForDistinct: '
|
104
|
+
attributeForDistinct: 'url',
|
93
105
|
attributesForFaceting: %w(tags type title),
|
94
106
|
attributesToIndex: %w(
|
95
107
|
title h1 h2 h3 h4 h5 h6
|
96
108
|
unordered(text)
|
97
109
|
unordered(tags)
|
98
110
|
),
|
99
|
-
attributesToRetrieve:
|
100
|
-
title h1 h2 h3 h4 h5 h6
|
101
|
-
url
|
102
|
-
tag_name
|
103
|
-
raw_html
|
104
|
-
text
|
105
|
-
posted_at
|
106
|
-
css_selector
|
107
|
-
css_selector_parent
|
108
|
-
),
|
111
|
+
attributesToRetrieve: nil,
|
109
112
|
customRanking: ['desc(posted_at)', 'desc(weight)'],
|
110
113
|
highlightPreTag: '<span class="algolia__result-highlight">',
|
111
114
|
highlightPostTag: '</span>'
|
@@ -1,5 +1,10 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
+
# Succeed fast if we did not change any ruby file
|
4
|
+
if ! git status --short | grep -q '\.rb$'; then
|
5
|
+
exit 0
|
6
|
+
fi
|
7
|
+
|
3
8
|
# Do not commit any focused or excluded tests
|
4
9
|
if grep --color -r 'spec' -E -e '^( |\t)*(fit|fdescribe|xit|xdescribe)'; then
|
5
10
|
echo '✘ You have focused and/or skipped tests'
|
data/scripts/git_hooks/pre-push
CHANGED
data/spec/push_spec.rb
CHANGED
@@ -72,12 +72,28 @@ describe(AlgoliaSearchJekyllPush) do
|
|
72
72
|
push.init_options(nil, {}, site.config)
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'should not exclude normal pages' do
|
76
|
+
expect(push.excluded_file?(html_page_file)).to eq false
|
77
|
+
end
|
78
|
+
|
75
79
|
it 'should alway exclude pagination pages' do
|
76
|
-
expect(push.excluded_file?(
|
80
|
+
expect(push.excluded_file?(pagination_page)).to eq true
|
77
81
|
end
|
78
82
|
|
79
83
|
it 'should exclude user specified strings' do
|
80
|
-
expect(push.excluded_file?(
|
84
|
+
expect(push.excluded_file?(excluded_page_file)).to eq true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'custom_hook_excluded_file?' do
|
89
|
+
it 'let the user call a custom hook to exclude some files' do
|
90
|
+
# Given
|
91
|
+
def push.custom_hook_excluded_file?(_file)
|
92
|
+
true
|
93
|
+
end
|
94
|
+
|
95
|
+
# Then
|
96
|
+
expect(push.excluded_file?(html_page_file)).to eq true
|
81
97
|
end
|
82
98
|
end
|
83
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch-jekyll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Carry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: algoliasearch
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- spec/fixtures/excluded.html
|
246
246
|
- spec/fixtures/hierarchy.md
|
247
247
|
- spec/fixtures/index.html
|
248
|
+
- spec/fixtures/page2/index.html
|
248
249
|
- spec/fixtures/weight.md
|
249
250
|
- spec/push_spec.rb
|
250
251
|
- spec/record_extractor_spec.rb
|