jekyll_search 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93f638b21ff6bac656f0b96a2fb8976fec06b956
4
- data.tar.gz: 83ed6b3e6770ad95b9525e73832c17be3098e650
3
+ metadata.gz: b9f5a6e19df158ca78f8a482e24ed2c8e119863e
4
+ data.tar.gz: 72cb71a8338ef6ca12dd5a0f646b9b19dabdba69
5
5
  SHA512:
6
- metadata.gz: 8e78345248b71e96def1cf31dd344fba3f70b62c9d14ccc3e45244bd36e04abd25dc03ff6195aee41e3bb55674c6a185259704013c8cd39b5b715be48a3f5f39
7
- data.tar.gz: 10d31a2a55029a583ce597dc4ba30c4b53d0bb3d91dced2db670173d10b32d796936af3979bef62ba2a110921679f59fb7d199eff0ea663ab47cf6173e8a8bb8
6
+ metadata.gz: 6993e0271bcb0b4eb10cd73ca0b7c7fb49fffda454c747bca26fa62bde403b17acaa41644c7ce2991eca7b393ad9c039f3c74b1fbe72086e259e2553ecca7f94
7
+ data.tar.gz: 752b3aeedfb31a8881f694ec899bc6746bf60102b04b43f7903a748e8b181be0fc2dfd0415df932506eff57afb84759aa7f47073be4e9fd29169ce52dc1eb1a9
data/README.md CHANGED
@@ -4,6 +4,10 @@
4
4
  [![gem](https://img.shields.io/gem/v/jekyll_search.svg)](https://rubygems.org/gems/jekyll_search)
5
5
  [![license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](http://opensource.org/licenses/MIT)
6
6
 
7
+ ## Live demo
8
+
9
+ See it in action on my [blog](http://choffmeister.de/search.html).
10
+
7
11
  ## Installation
8
12
 
9
13
  Add this line to your application's Gemfile:
@@ -26,7 +26,7 @@ module JekyllSearch
26
26
  if node.name =~ /^h\d$/
27
27
  result << current
28
28
  current = { :id => nil, :title => nil, :content => '' }
29
- current[:id] = if node.has_attribute?('id') then node.attribute('id').value else nil end
29
+ current[:id] = extract_headline_id(node)
30
30
  current[:title] = node.text
31
31
  else
32
32
  current[:content] += node.to_html
@@ -38,5 +38,21 @@ module JekyllSearch
38
38
 
39
39
  result
40
40
  end
41
+
42
+ def self.extract_headline_id(node)
43
+ if node.has_attribute?('id')
44
+ node.attribute('id').value
45
+ else
46
+ children = []
47
+ node.traverse { |n| children << n }
48
+ children_with_id = children.select { |n| n['id'] }
49
+
50
+ if children_with_id.count == 1
51
+ children_with_id.first['id']
52
+ else
53
+ nil
54
+ end
55
+ end
56
+ end
41
57
  end
42
58
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllSearch
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -8,16 +8,30 @@ RSpec.describe JekyllSearch::HtmlProcessor do
8
8
 
9
9
  it 'detects sections' do
10
10
  expect(JekyllSearch::HtmlProcessor.detect_sections('test')).to eq [
11
- { :id => nil, :title => nil, :content => 'test'}
11
+ { :id => nil, :title => nil, :content => 'test' }
12
+ ]
13
+ end
14
+
15
+ it 'detects sections' do
16
+ expect(JekyllSearch::HtmlProcessor.detect_sections('<h1>foo</h1>test')).to eq [
17
+ { :id => nil, :title => nil, :content => '' },
18
+ { :id => nil, :title => 'foo', :content => 'test' }
12
19
  ]
13
20
  end
14
21
 
15
22
  it 'detects sections' do
16
23
  expect(JekyllSearch::HtmlProcessor.detect_sections("foo<h1>first</h1>bar <p>\npara\n</p>\n\n<H4 ID=\"sec\">sec<span>ond</span></H4>apple<h2>third</h2>")).to eq [
17
- { :id => nil, :title => nil, :content => "foo"},
18
- { :id => nil, :title => 'first', :content => "bar <p>\npara\n</p>\n\n"},
24
+ { :id => nil, :title => nil, :content => "foo" },
25
+ { :id => nil, :title => 'first', :content => "bar <p>\npara\n</p>\n\n" },
19
26
  { :id => 'sec', :title => 'second', :content => "apple" },
20
27
  { :id => nil, :title => 'third', :content => '' }
21
28
  ]
22
29
  end
30
+
31
+ it 'detects sections' do
32
+ expect(JekyllSearch::HtmlProcessor.detect_sections("<h1>foo<div id=\"inner-id\"></div></h1>bar")).to eq [
33
+ { :id => nil, :title => nil, :content => '' },
34
+ { :id => 'inner-id', :title => 'foo', :content => 'bar' }
35
+ ]
36
+ end
23
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Hoffmeister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-20 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.0.14
137
+ rubygems_version: 2.4.6
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: An Elasticsearch full text search index generator for Jekyll.