nanoc-algolia 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nanoc-algolia.rb +5 -32
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 870dce1c8736b04a2d8ab13d2510a73cb49a5e07
4
- data.tar.gz: d4bad8dea5215ac2f73f7e73126dbde9b8e72b9b
3
+ metadata.gz: 53f5e8a82ea8ef18ea785ae83047d3b3a2077105
4
+ data.tar.gz: 7723efa1b08bcd3aec24512f5698f0a4bf2446fa
5
5
  SHA512:
6
- metadata.gz: 7756a20f41a2de1130d71233d8ec45f34841d52b00220c0026ca39d22402c49212ffde1bc26f85710b1bb4e919768e6a77ac9e9a84143b23e71deb2a1556d9c2
7
- data.tar.gz: 12e5e04a09accd688e37bad77e5b98cdb7b5b31c6b4220e9f2b36964a14747e86fbcb9e16150b895b0144c95016832b98da5f1fd9741b2ce3fb4f98e38ca6347
6
+ metadata.gz: 69d5db3145174ab4194a994d3bfd5eeac74a24d342d7cc4f9dff20ddab70dbaa9572a5558cb9ea89bec026c520d4b17636c221451d4ee236a2563799387e9596
7
+ data.tar.gz: 2b884a9555983a6cb454cb83762ac74840673838ded0220854ecae5fb07f88257b50ff87699974b738680f5a705018e5f2bbeae51c2c63ce7e5ea0b0528551d5
@@ -3,20 +3,17 @@ require 'algoliasearch'
3
3
  require 'nokogiri'
4
4
 
5
5
  class SearchFilter < Nanoc::Filter
6
- identifier :search
6
+ identifier :algolia
7
7
  type :text
8
8
 
9
9
  def initialize(hash = {})
10
10
  super
11
11
 
12
+ raise ArgumentError.new 'Missing algolia config' unless @config[:algolia]
12
13
  raise ArgumentError.new 'Missing algolia:application_id' unless @config[:algolia][:application_id]
13
14
  raise ArgumentError.new 'Missing algolia:api_key' unless @config[:algolia][:api_key]
14
15
  raise ArgumentError.new 'Missing algolia:index' unless @config[:algolia][:index]
15
16
 
16
- @last_indexed_file = '.nanoc_algolia'
17
-
18
- load_last_timestamp
19
-
20
17
  Algolia.init application_id: @config[:algolia][:application_id],
21
18
  api_key: @config[:algolia][:api_key]
22
19
 
@@ -27,25 +24,17 @@ class SearchFilter < Nanoc::Filter
27
24
  # The main content from each page is extracted and indexed at algolia
28
25
  # The id of each document will be the absolute url to the resource without domain name
29
26
  def run(content, params={})
30
- # only process item that are changed since last regeneration
31
- if (!@last_indexed.nil? && @last_indexed > item.mtime)
32
- return content
33
- end
34
-
35
27
  puts "Indexing page #{@item.identifier}"
36
28
 
37
29
  page_text = extract_text(content)
38
30
 
39
31
  @index.save_object(
40
32
  {
41
- text: => page_text,
42
- title: => @item[:title] || item.identifier
43
- }, item.identifer)
33
+ text: page_text,
34
+ title: @item[:title] || item.identifier
35
+ }, item.identifier)
44
36
  puts 'Indexed ' << item.identifier
45
37
 
46
- @last_indexed = Time.now
47
- write_last_indexed
48
-
49
38
  content
50
39
  end
51
40
 
@@ -53,20 +42,4 @@ class SearchFilter < Nanoc::Filter
53
42
  doc = Nokogiri::HTML(content)
54
43
  doc.xpath('//*/text()').to_a.join(" ").gsub("\r"," ").gsub("\n"," ")
55
44
  end
56
-
57
- def write_last_indexed
58
- begin
59
- File.open(@last_indexed_file, 'w') {|f| Marshal.dump(@last_indexed, f)}
60
- rescue
61
- puts 'WARNING: cannot write indexed timestamps file.'
62
- end
63
- end
64
-
65
- def load_last_timestamp
66
- begin
67
- @last_indexed = File.open(@last_indexed_file, "rb") {|f| Marshal.load(f)}
68
- rescue
69
- @last_indexed = nil
70
- end
71
- end
72
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-algolia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - François de Metz