jekyll-blogsearch 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: f0b40ac907c5b5dba89e66dcd21a40dd28fd6a3d4db9060205537828ee07ac5a
4
- data.tar.gz: daff275e6b58d22d0f3fea2338beb077e48573c38f1aa2c29e53d4124e694042
3
+ metadata.gz: 00a72fa00fcd6eeb9abda9d86b88d93311876485e58a473a088245a0e1286d5f
4
+ data.tar.gz: 6963e739e06e8633d5102d5f6f2c86ed563961d6c3590bb16a4fb7e7c703849b
5
5
  SHA512:
6
- metadata.gz: d642d53ef7d51942ad62c5677067cb6c72292ee3e3d0002084407e3456ff398e0adc40b438a0b8a979497a5ea130abd5eb7bb3c5d52917d8d33655f03dae9853
7
- data.tar.gz: 0a95a6c803630be4f6a222c68f1c9ea2d8b7a004ae66d8d2bdfb4c5f4528c398aded065667278b9bea478f86d1b8a3a4f7c35438ff7e5bfe1143a9715f107f7d
6
+ metadata.gz: 82e54befed2ae88361e405465b4eace8890f721663c64961a9ca8cedf94db2d032aab50f07865fef806e95a6dcb83e65962373a10da8e908267b1549d0498e0d
7
+ data.tar.gz: 2b363e29e3907bc7f9aada8d32766f462bc370ac1d7cd1740aecc226a05818a1dc3dda2c3e3b2fce00178420ea39a07f27a023f77b2a9a6461ce23a2c66dba10
@@ -3,19 +3,49 @@ require 'jekyll/plugin'
3
3
  require 'jekyll/generator'
4
4
  require 'sqlite3'
5
5
  require 'jekyll/blogsearch/version'
6
- require "nokogiri"
6
+ require 'nokogiri'
7
+ # require 'pp'
7
8
 
8
9
  begin
9
10
  fields_config = {}
10
11
  db = {}
11
12
  rowid_counter = 0
12
13
  baseurl = ''
14
+ default_config = {
15
+ 'title' => {
16
+ 'enabled' => true,
17
+ 'indexed' => true,
18
+ 'hasContent' => true,
19
+ },
20
+ 'body' => {
21
+ 'enabled' => true,
22
+ 'indexed' => true,
23
+ 'hasContent' => true,
24
+ },
25
+ 'url' => {
26
+ 'enabled' => true,
27
+ 'indexed' => false,
28
+ 'hasContent' => true,
29
+ },
30
+ 'categories' => {
31
+ 'enabled' => true,
32
+ 'indexed' => true,
33
+ 'hasContent' => true,
34
+ },
35
+ 'tags' => {
36
+ 'enabled' => true,
37
+ 'indexed' => true,
38
+ 'hasContent' => true,
39
+ },
40
+ }
13
41
 
14
42
  # Start
15
43
  Jekyll::Hooks.register(:site, :post_read) do |site|
16
44
  # https://www.rubydoc.info/github/jekyll/jekyll/Jekyll/Site
17
- fields_config = site.config['blogsearch']['fields']
18
-
45
+ fields_config = default_config.merge(site.config['blogsearch']['fields'])
46
+ .keep_if { |_, config| config['enabled'] }
47
+ # pp fields_config
48
+
19
49
  db_path = site.config['blogsearch']['output']
20
50
  db_dir = File.dirname(db_path)
21
51
  Dir.mkdir(db_dir) if not Dir.exist?(db_dir)
@@ -33,11 +63,7 @@ begin
33
63
  db.execute <<-SQL
34
64
  CREATE TABLE blogsearch_ext_content (
35
65
  rowid INTEGER PRIMARY KEY,
36
- title,
37
- body,
38
- url,
39
- categories,
40
- tags
66
+ #{fields_config.keys.map{ |field| field + (fields_config[field]['indexed'] ? '' : ' UNINDEXED') }.join(',')}
41
67
  );
42
68
  SQL
43
69
 
@@ -45,16 +71,19 @@ begin
45
71
  db.execute <<-SQL
46
72
  CREATE VIRTUAL TABLE blogsearch
47
73
  USING fts5 (
48
- title,
49
- body,
50
- url,
51
- categories,
52
- tags,
74
+ #{ fields_config.keys.join(',') },
53
75
  tokenize = 'porter unicode61 remove_diacritics 1',
54
76
  content=blogsearch_ext_content,
55
77
  content_rowid=rowid
56
78
  );
57
79
  SQL
80
+
81
+ # Add 'rowid' block to match contents hash when inserted to the db.
82
+ fields_config['rowid'] = {
83
+ 'enabled' => true,
84
+ 'indexed' => false,
85
+ 'hasContent' => true,
86
+ }
58
87
  end
59
88
 
60
89
  # End
@@ -65,52 +94,45 @@ begin
65
94
  # Post and etc.
66
95
  Jekyll::Hooks.register :documents, :post_render do |document|
67
96
  # https://www.rubydoc.info/github/jekyll/jekyll/Jekyll/Document
97
+ # pp document.data
68
98
  # [TODO] Add support for document.data['excerpt']
69
99
 
70
100
  next if not document.published?
71
101
  rowid_counter += 1
72
102
 
73
- rowid = rowid_counter
74
- title = document.data['title']
75
- body = Nokogiri::HTML(document.content).text.to_s.gsub(/\s+/, ' ')
76
- url = baseurl + document.url
77
- categories = document.data['categories'].join(' , ')
78
- tags = document.data['tags'].join(' , ')
103
+ contents = {
104
+ 'rowid' => rowid_counter,
105
+ 'title' => document.data['title'],
106
+ 'body' => Nokogiri::HTML(document.content).text.to_s.gsub(/\s+/, ' '),
107
+ 'url' => baseurl + document.url,
108
+ 'categories' => document.data['categories'].join(' , '),
109
+ 'tags' => document.data['tags'].join(' , '),
110
+ }.keep_if { |field, _| fields_config.has_key?(field) }
79
111
 
80
- # External content table
112
+ # pp contents
113
+ # pp contents.keys.map{ |_| '?' }.join(',')
114
+ # pp contents.keys.join(',')
115
+
116
+ # FTS5 virtual table
81
117
  db.execute <<-SQL,
82
- INSERT INTO blogsearch_ext_content
118
+ INSERT INTO blogsearch (
119
+ #{ contents.keys.join(',') }
120
+ )
83
121
  VALUES (
84
- ?,
85
- ?,
86
- ?,
87
- ?,
88
- ?,
89
- ?
122
+ #{ contents.keys.map { |_| '?' }.join(',') }
90
123
  );
91
124
  SQL
92
- [rowid, title, body, url, categories, tags]
93
-
94
- # FTS5 virtual table
125
+ contents.values
126
+
127
+ contents = contents.map { |field, value| [field, fields_config[field]['hasContent'] ? value : ''] }.to_h
128
+ # External content table
95
129
  db.execute <<-SQL,
96
- INSERT INTO blogsearch (
97
- rowid,
98
- title,
99
- body,
100
- url,
101
- categories,
102
- tags
103
- )
130
+ INSERT INTO blogsearch_ext_content
104
131
  VALUES (
105
- ?,
106
- ?,
107
- ?,
108
- ?,
109
- ?,
110
- ?
132
+ #{ contents.keys.map { |_| '?' }.join(',') }
111
133
  );
112
134
  SQL
113
- [rowid, title, body, url, categories, tags]
135
+ contents.values
114
136
  end
115
137
 
116
138
  rescue => e
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module BlogSearch
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-blogsearch
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
  - Bumsik Kim
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-23 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.10'
55
- description:
55
+ description:
56
56
  email: k.bumsik@gmail.com
57
57
  executables: []
58
58
  extensions: []
@@ -65,7 +65,7 @@ homepage: https://github.com/kbumsik/blogsearch
65
65
  licenses:
66
66
  - MIT
67
67
  metadata: {}
68
- post_install_message:
68
+ post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
71
71
  - lib
@@ -80,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.1.2
84
- signing_key:
83
+ rubygems_version: 3.1.3
84
+ signing_key:
85
85
  specification_version: 4
86
86
  summary: BlogSearch index building tool for Jekyll
87
87
  test_files: []