algoliasearch-jekyll 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +4 -1
  5. data/README.md +8 -0
  6. data/Rakefile +2 -1
  7. data/VERSION +1 -1
  8. data/algoliasearch-jekyll.gemspec +129 -0
  9. data/lib/algoliasearch-jekyll.rb +13 -1
  10. data/lib/credential_checker.rb +74 -0
  11. data/lib/push.rb +52 -89
  12. data/lib/record_extractor.rb +1 -0
  13. data/scripts/check_flay +30 -0
  14. data/scripts/check_flog +31 -0
  15. data/scripts/git_hooks/pre-commit +2 -1
  16. data/scripts/git_hooks/pre-push +6 -1
  17. data/spec/credential_checker_spec.rb +116 -0
  18. data/spec/fixtures/_config.yml +9 -4
  19. data/spec/fixtures/_layouts/default.html +6 -0
  20. data/spec/fixtures/_posts/2015-07-03-test-post-again.md +7 -0
  21. data/spec/fixtures/_site/2015/07/02/test-post.html +26 -0
  22. data/spec/fixtures/_site/2015/07/03/test-post-again.html +3 -0
  23. data/spec/fixtures/_site/about.html +31 -0
  24. data/spec/fixtures/_site/assets/ring.png +0 -0
  25. data/spec/fixtures/_site/authors.html +1 -0
  26. data/spec/fixtures/_site/excluded.html +1 -0
  27. data/spec/fixtures/_site/hierarchy.html +31 -0
  28. data/spec/fixtures/_site/index.html +17 -0
  29. data/spec/fixtures/_site/my-collection/collection-item.html +2 -0
  30. data/spec/fixtures/_site/page2/index.html +40 -0
  31. data/spec/fixtures/_site/weight.html +15 -0
  32. data/spec/fixtures/index.html +13 -0
  33. data/spec/push_spec.rb +134 -113
  34. data/spec/record_extractor_spec.rb +10 -0
  35. data/spec/spec_helper.rb +21 -11
  36. data/spec/spec_helper_simplecov.rb +1 -1
  37. data/txt/api_key_missing +4 -0
  38. data/txt/application_id_missing +8 -0
  39. data/txt/index_name_missing +9 -0
  40. metadata +69 -5
  41. data/scripts/run_tests +0 -2
  42. data/scripts/update_gem +0 -10
@@ -6,6 +6,7 @@ require 'json'
6
6
  class AlgoliaSearchRecordExtractor
7
7
  def initialize(file)
8
8
  @file = file
9
+ @config = file.site.config
9
10
  default_config = {
10
11
  'record_css_selector' => 'p'
11
12
  }
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ MAX_SCORE = 45
4
+
5
+ flay_lines = `flay -s ./lib/`.split("\n")
6
+
7
+ errors = []
8
+ flay_lines.each_with_index do |line, index|
9
+ # Skip header
10
+ next if index < 2
11
+
12
+ pattern = /^ *(.*): (.*)/
13
+ matches = line.match(pattern)
14
+ next if matches.nil?
15
+ score = matches[1].to_f
16
+
17
+ next if score < MAX_SCORE
18
+ errors << {
19
+ score: score,
20
+ file: matches[2]
21
+ }
22
+ end
23
+
24
+ exit 0 if errors.size == 0
25
+
26
+ puts 'Flay test failed:'
27
+ errors.sort_by { |a| a[:score] }.each do |error|
28
+ puts "#{error[:score]} / #{MAX_SCORE} in #{error[:file]}"
29
+ end
30
+ exit 1
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ MAX_SCORE = 45
4
+
5
+ flog_lines = `flog ./lib/`.split("\n")
6
+
7
+ errors = []
8
+ flog_lines.each_with_index do |line, index|
9
+ # Skip header
10
+ next if index < 3
11
+
12
+ pattern = /^ *(.*): (.*) (.*):[0-9]*/
13
+ matches = line.match(pattern)
14
+ next if matches.nil?
15
+ score = matches[1].to_f
16
+
17
+ next if score < MAX_SCORE
18
+ errors << {
19
+ score: score,
20
+ method: matches[2],
21
+ file: matches[3]
22
+ }
23
+ end
24
+
25
+ exit 0 if errors.size == 0
26
+
27
+ puts 'Flog test failed:'
28
+ errors.sort_by { |a| a[:score] }.each do |error|
29
+ puts "#{error[:score]} / #{MAX_SCORE}: #{error[:method]} in #{error[:file]}"
30
+ end
31
+ exit 1
@@ -7,4 +7,5 @@ if grep --color -r 'spec' -E -e '^( |\t)*(fit|fdescribe|xit|xdescribe)'; then
7
7
  fi
8
8
 
9
9
  # Match style guide
10
- rubocop './lib/' './spec'
10
+ rubocop -F './lib/' './spec' || exit 1
11
+
@@ -1,3 +1,8 @@
1
1
  #!/usr/bin/env bash
2
+ rake spec || exit 1
2
3
 
3
- bundle exec rspec --format documentation
4
+ # No over-complex methods
5
+ ./scripts/check_flog || exit 1
6
+
7
+ # No duplication
8
+ ./scripts/check_flay
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe(AlgoliaSearchCredentialChecker) do
4
+ let(:config) do
5
+ {
6
+ 'source' => File.expand_path('./spec/fixtures'),
7
+ 'markdown_ext' => 'md,mkd',
8
+ 'algolia' => {
9
+ 'application_id' => 'APPID',
10
+ 'index_name' => 'INDEXNAME'
11
+ }
12
+ }
13
+ end
14
+ let(:checker) { AlgoliaSearchCredentialChecker.new(config) }
15
+
16
+ describe 'api_key' do
17
+ it 'returns nil if no key found' do
18
+ # Given
19
+
20
+ # When
21
+ actual = checker.api_key
22
+
23
+ # Then
24
+ expect(actual).to be_nil
25
+ end
26
+
27
+ it 'reads from ENV var if set' do
28
+ # Given
29
+ stub_const('ENV', 'ALGOLIA_API_KEY' => 'APIKEY_FROM_ENV')
30
+
31
+ # When
32
+ actual = checker.api_key
33
+
34
+ # Then
35
+ expect(actual).to eq 'APIKEY_FROM_ENV'
36
+ end
37
+
38
+ it 'reads from _algolia_api_key in source if set' do
39
+ # Given
40
+ checker.config['source'] = File.join(config['source'], 'api_key_dir')
41
+
42
+ # When
43
+ actual = checker.api_key
44
+
45
+ # Then
46
+ expect(actual).to eq 'APIKEY_FROM_FILE'
47
+ end
48
+
49
+ it 'reads from ENV before from file' do
50
+ # Given
51
+ checker.config['source'] = File.join(config['source'], 'api_key_dir')
52
+ stub_const('ENV', 'ALGOLIA_API_KEY' => 'APIKEY_FROM_ENV')
53
+
54
+ # When
55
+ actual = checker.api_key
56
+
57
+ # Then
58
+ expect(actual).to eq 'APIKEY_FROM_ENV'
59
+ end
60
+ end
61
+
62
+ describe 'assert_valid' do
63
+ it 'should display error if no api key' do
64
+ # Given
65
+ allow(checker).to receive(:api_key) { nil }
66
+
67
+ # Then
68
+ expect(Jekyll.logger).to receive(:error).with(/api key/i)
69
+ expect(Jekyll.logger).to receive(:warn).at_least(:once)
70
+ expect(-> { checker.assert_valid }).to raise_error SystemExit
71
+ end
72
+
73
+ it 'should display error if no application id' do
74
+ # Given
75
+ checker.config['algolia'] = {
76
+ 'application_id' => nil,
77
+ 'index_name' => 'INDEX_NAME'
78
+ }
79
+ stub_const('ENV', 'ALGOLIA_API_KEY' => 'APIKEY_FROM_ENV')
80
+
81
+ # Then
82
+ expect(Jekyll.logger).to receive(:error).with(/application id/i)
83
+ expect(Jekyll.logger).to receive(:warn).at_least(:once)
84
+ expect(-> { checker.assert_valid }).to raise_error SystemExit
85
+ end
86
+
87
+ it 'should display error if no index name' do
88
+ # Given
89
+ checker.config['algolia'] = {
90
+ 'application_id' => 'APPLICATION_ID',
91
+ 'index_name' => nil
92
+ }
93
+ stub_const('ENV', 'ALGOLIA_API_KEY' => 'APIKEY_FROM_ENV')
94
+
95
+ # Then
96
+ expect(Jekyll.logger).to receive(:error).with(/index name/i)
97
+ expect(Jekyll.logger).to receive(:warn).at_least(:once)
98
+ expect(-> { checker.assert_valid }).to raise_error SystemExit
99
+ end
100
+
101
+ it 'should init the Algolia client' do
102
+ # Given
103
+ stub_const('ENV', 'ALGOLIA_API_KEY' => 'APIKEY_FROM_ENV')
104
+ allow(Algolia).to receive(:init)
105
+
106
+ # When
107
+ checker.assert_valid
108
+
109
+ # Then
110
+ expect(Algolia).to have_received(:init).with(
111
+ application_id: 'APPID',
112
+ api_key: 'APIKEY_FROM_ENV'
113
+ )
114
+ end
115
+ end
116
+ end
@@ -1,7 +1,12 @@
1
- algolia:
2
- application_id: 'APPID'
3
- index_name: 'INDEXNAME'
4
-
5
1
  collections:
6
2
  my-collection:
7
3
  output: true
4
+ markdown_ext: 'md,mkd'
5
+ paginate: 1
6
+ timezone: Europe/Paris
7
+
8
+ algolia:
9
+ application_id: APPID
10
+ index_name: INDEXNAME
11
+ excluded_files:
12
+ - excluded.html
@@ -0,0 +1,6 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-us">
3
+ <body>
4
+ {{ content }}
5
+ </body>
6
+ </html>
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: "Test post again"
3
+ ---
4
+
5
+ The goal of this post is simply to trigger pagination, and see that we do not
6
+ index the pagination results.
7
+
@@ -0,0 +1,26 @@
1
+ <p>Introduction text that also includes <a href="https://www.algolia.com">some link</a>. To
2
+ add a bit of fancy, we will also <strong>bold</strong> and <em>italicize</em> some text.</p>
3
+
4
+ <h1 id="main-title">Main title</h1>
5
+
6
+ <p>We like writing stuff and then indexing it in a very fast engine. Here is why
7
+ a fast engine is good for you:</p>
8
+
9
+ <ul>
10
+ <li>fast</li>
11
+ <li>fast</li>
12
+ <li>fast</li>
13
+ <li>and fast</li>
14
+ </ul>
15
+
16
+ <h2 id="built-with-hands">Built with hands</h2>
17
+
18
+ <p>All this text was typed with my own hands, on my own keyboard. I also did use
19
+ a Chair© and a Table™.</p>
20
+
21
+ <h2 id="features">Features</h2>
22
+
23
+ <p>The whole plugin is composed of parts of <code>code</code>, and sometime even
24
+ <code>&lt;code&gt;</code>.</p>
25
+
26
+ <p>Code is <strong>✔ checked</strong> and errors are <strong>✘ deleted</strong>.</p>
@@ -0,0 +1,3 @@
1
+ <p>The goal of this post is simply to trigger pagination, and see that we do not
2
+ index the pagination results.</p>
3
+
@@ -0,0 +1,31 @@
1
+ <h1 id="heading-1">Heading 1</h1>
2
+
3
+ <p>Text 1</p>
4
+
5
+ <h2 id="heading-2">Heading 2</h2>
6
+
7
+ <p>Text 2</p>
8
+
9
+ <h3 id="heading-3">Heading 3</h3>
10
+
11
+ <p>Text 3</p>
12
+
13
+ <ul>
14
+ <li>item 1</li>
15
+ <li>item 2</li>
16
+ <li>item 3</li>
17
+ </ul>
18
+
19
+ <h3 id="another-heading-3">Another Heading 3</h3>
20
+
21
+ <p id="text4">Another text 4</p>
22
+
23
+ <h2 id="heading2b">Another Heading 2</h2>
24
+
25
+ <p>Another <code>&lt;text&gt;</code> 5</p>
26
+
27
+ <h3 id="last-heading-3">Last Heading 3</h3>
28
+
29
+ <div>Just a div</div>
30
+
31
+ <div><p>Last text 6 </p></div>
Binary file
@@ -0,0 +1 @@
1
+ <p>This is an HTML page</p>
@@ -0,0 +1 @@
1
+ <p>This should not be indexed</p>
@@ -0,0 +1,31 @@
1
+ <h1 id="h1">H1</h1>
2
+
3
+ <p>TEXT1-H1</p>
4
+
5
+ <h2 id="h2a">H2A</h2>
6
+
7
+ <p>TEXT2-H2A-H1</p>
8
+
9
+ <p>TEXT3-H2A-H1</p>
10
+
11
+ <h2 id="h2b">H2B</h2>
12
+
13
+ <p>TEXT4-H2B-H1</p>
14
+
15
+ <h3 id="h3a">H3A</h3>
16
+
17
+ <p>TEXT5-H3-H2B-H1</p>
18
+
19
+ <div>
20
+ <h4>H4</h4>
21
+ <p>TEXT7-H4-H3-H2B-H1</p>
22
+ </div>
23
+
24
+ <h2 id="h2c">H2C</h2>
25
+
26
+ <p>TEXT8-H2C-H1</p>
27
+
28
+ <h3 id="h3b-code">H3B <code>&lt;code&gt;</code></h3>
29
+
30
+ <p>TEXT9-H3B-H2C-H1</p>
31
+
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-us">
3
+ <body>
4
+ This default index page is used to display the paginated posts
5
+
6
+
7
+ <a href="/2015/07/03/test-post-again.html">
8
+ Test post again
9
+ </a>
10
+ <p>The goal of this post is simply to trigger pagination, and see that we do not
11
+ index the pagination results.</p>
12
+
13
+
14
+
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,2 @@
1
+ <p>The grandest of omelettes. Those that feast on dragon eggs often find that there
2
+ is very little they would not dare to do.</p>
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-us">
3
+ <body>
4
+ This default index page is used to display the paginated posts
5
+
6
+
7
+ <a href="/2015/07/02/test-post.html">
8
+ Test post
9
+ </a>
10
+ <p>Introduction text that also includes <a href="https://www.algolia.com">some link</a>. To
11
+ add a bit of fancy, we will also <strong>bold</strong> and <em>italicize</em> some text.</p>
12
+
13
+ <h1 id="main-title">Main title</h1>
14
+
15
+ <p>We like writing stuff and then indexing it in a very fast engine. Here is why
16
+ a fast engine is good for you:</p>
17
+
18
+ <ul>
19
+ <li>fast</li>
20
+ <li>fast</li>
21
+ <li>fast</li>
22
+ <li>and fast</li>
23
+ </ul>
24
+
25
+ <h2 id="built-with-hands">Built with hands</h2>
26
+
27
+ <p>All this text was typed with my own hands, on my own keyboard. I also did use
28
+ a Chair© and a Table™.</p>
29
+
30
+ <h2 id="features">Features</h2>
31
+
32
+ <p>The whole plugin is composed of parts of <code>code</code>, and sometime even
33
+ <code>&lt;code&gt;</code>.</p>
34
+
35
+ <p>Code is <strong>✔ checked</strong> and errors are <strong>✘ deleted</strong>.</p>
36
+
37
+
38
+
39
+ </body>
40
+ </html>
@@ -0,0 +1,15 @@
1
+ <h1 id="aaa-bbb-ccc-ddd">AAA BBB CCC DDD</h1>
2
+
3
+ <p>aaa xxx aaa xxx aaa</p>
4
+
5
+ <h2 id="aaa-bbb">AAA BBB</h2>
6
+
7
+ <p>aaa bbb</p>
8
+
9
+ <h2 id="ccc-ddd">CCC DDD</h2>
10
+
11
+ <p>ccc ddd</p>
12
+
13
+ <h3 id="ddd">DDD</h3>
14
+
15
+ <p>aaa bbb ccc dddd</p>
@@ -0,0 +1,13 @@
1
+ ---
2
+ layout: default
3
+ title: Home
4
+ ---
5
+
6
+ This default index page is used to display the paginated posts
7
+
8
+ {% for post in paginator.posts %}
9
+ <a href="{{ site.baseurl }}{{ post.url }}">
10
+ {{ post.title }}
11
+ </a>
12
+ {{ post.content }}
13
+ {% endfor %}