jekyll-blogsearch 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f0b40ac907c5b5dba89e66dcd21a40dd28fd6a3d4db9060205537828ee07ac5a
4
+ data.tar.gz: daff275e6b58d22d0f3fea2338beb077e48573c38f1aa2c29e53d4124e694042
5
+ SHA512:
6
+ metadata.gz: d642d53ef7d51942ad62c5677067cb6c72292ee3e3d0002084407e3456ff398e0adc40b438a0b8a979497a5ea130abd5eb7bb3c5d52917d8d33655f03dae9853
7
+ data.tar.gz: 0a95a6c803630be4f6a222c68f1c9ea2d8b7a004ae66d8d2bdfb4c5f4528c398aded065667278b9bea478f86d1b8a3a4f7c35438ff7e5bfe1143a9715f107f7d
data/README.adoc ADDED
@@ -0,0 +1,88 @@
1
+ # BlogSearch index building tool for Jekyll
2
+
3
+ // Asciidoc references
4
+ // Documentation: https://asciidoctor.org/docs/user-manual/
5
+ // Quick reference: https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/
6
+ // Asciidoc vs Markdown: https://asciidoctor.org/docs/user-manual/#comparison-by-example
7
+ // GitHub Flavored Asciidoc (GFA): https://gist.github.com/dcode/0cfbf2699a1fe9b46ff04c41721dda74
8
+
9
+ :project-version: 0.0.3
10
+ :rootdir: https://github.com/kbumsik/blogsearch
11
+
12
+ ifdef::env-github[]
13
+ // Emoji
14
+ :tip-caption: :bulb:
15
+ :note-caption: :information_source:
16
+ :important-caption: :heavy_exclamation_mark:
17
+ :caution-caption: :fire:
18
+ :warning-caption: :warning:
19
+ // URL
20
+ :imagesdir: https://gist.githubusercontent.com/path/to/gist/revision/dir/with/all/images
21
+ endif::[]
22
+
23
+ CAUTION: This is a part of link:{rootdir}[BlogSearch project]. If you would like to know the overall concept, go to link:{rootdir}[the parent directory].
24
+
25
+ ## 1. Building a search index file
26
+
27
+ ### Installation
28
+
29
+ .Gemfile
30
+ [source,ruby]
31
+ ----
32
+ group :jekyll_plugins do
33
+ gem 'jekyll-blogsearch'
34
+
35
+ ...
36
+ Other jekyll plugins
37
+ ...
38
+ end
39
+ ----
40
+
41
+ ### Configuration
42
+
43
+ CAUTION: Go to link:{rootdir}#whats-in-the-index[the "What's in the index file" section of the main project]. For more details on how to configure fields.
44
+
45
+ ._config.yml
46
+ [source,yml,options="nowrap",subs="verbatim,attributes"]
47
+ ----
48
+ titie: your-blog-website
49
+ email: your-email@example.com
50
+
51
+ url: "https://your-website"
52
+ baseurl: "/blog"
53
+
54
+ ...
55
+ Other jekyll config
56
+ ...
57
+
58
+ blogsearch:
59
+ output: your_website_index.db.wasm # Generated blogsearch database file.
60
+ fields: # See: {rootdir}#whats-in-the-index
61
+ title:
62
+ enabled: true
63
+ indexed: true
64
+ hasContent: true
65
+ body:
66
+ enabled: true
67
+ indexed: true
68
+ hasContent: true
69
+ url:
70
+ base: https://your-website/blog # url field has a special 'base' option to set the baseurl.
71
+ enabled: true
72
+ indexed: false
73
+ hasContent: true
74
+ categories:
75
+ enabled: true
76
+ indexed: true
77
+ hasContent: true
78
+ tags:
79
+ enabled: false
80
+ indexed: false
81
+ hasContent: false
82
+ ----
83
+
84
+ ## 2. Enabling the search engine in the webpage
85
+
86
+ You need to enable the search engine in the web page. Go to link:../blogsearch[blogsearch Engine].
87
+
88
+ Again, if you would like to understand the concept of BlogSearch, go to link:{rootdir}[the parent directory].
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module BlogSearch
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,118 @@
1
+ require 'jekyll/hooks'
2
+ require 'jekyll/plugin'
3
+ require 'jekyll/generator'
4
+ require 'sqlite3'
5
+ require 'jekyll/blogsearch/version'
6
+ require "nokogiri"
7
+
8
+ begin
9
+ fields_config = {}
10
+ db = {}
11
+ rowid_counter = 0
12
+ baseurl = ''
13
+
14
+ # Start
15
+ Jekyll::Hooks.register(:site, :post_read) do |site|
16
+ # https://www.rubydoc.info/github/jekyll/jekyll/Jekyll/Site
17
+ fields_config = site.config['blogsearch']['fields']
18
+
19
+ db_path = site.config['blogsearch']['output']
20
+ db_dir = File.dirname(db_path)
21
+ Dir.mkdir(db_dir) if not Dir.exist?(db_dir)
22
+ File.delete(db_path) if File.exist?(db_path)
23
+ db = SQLite3::Database.new db_path
24
+
25
+ if site.config['blogsearch']['fields']['url'].key?('base')
26
+ baseurl = site.config['blogsearch']['fields']['url']['base']
27
+ else
28
+ baseurl = site.config['url'] ? site.config['url'] : ''
29
+ baseurl += site.config['baseurl'] ? site.config['baseurl'] : ''
30
+ end
31
+
32
+ # External content table
33
+ db.execute <<-SQL
34
+ CREATE TABLE blogsearch_ext_content (
35
+ rowid INTEGER PRIMARY KEY,
36
+ title,
37
+ body,
38
+ url,
39
+ categories,
40
+ tags
41
+ );
42
+ SQL
43
+
44
+ # FTS5 virtual table
45
+ db.execute <<-SQL
46
+ CREATE VIRTUAL TABLE blogsearch
47
+ USING fts5 (
48
+ title,
49
+ body,
50
+ url,
51
+ categories,
52
+ tags,
53
+ tokenize = 'porter unicode61 remove_diacritics 1',
54
+ content=blogsearch_ext_content,
55
+ content_rowid=rowid
56
+ );
57
+ SQL
58
+ end
59
+
60
+ # End
61
+ Jekyll::Hooks.register :site, :post_render do |site|
62
+ db.close
63
+ end
64
+
65
+ # Post and etc.
66
+ Jekyll::Hooks.register :documents, :post_render do |document|
67
+ # https://www.rubydoc.info/github/jekyll/jekyll/Jekyll/Document
68
+ # [TODO] Add support for document.data['excerpt']
69
+
70
+ next if not document.published?
71
+ rowid_counter += 1
72
+
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(' , ')
79
+
80
+ # External content table
81
+ db.execute <<-SQL,
82
+ INSERT INTO blogsearch_ext_content
83
+ VALUES (
84
+ ?,
85
+ ?,
86
+ ?,
87
+ ?,
88
+ ?,
89
+ ?
90
+ );
91
+ SQL
92
+ [rowid, title, body, url, categories, tags]
93
+
94
+ # FTS5 virtual table
95
+ db.execute <<-SQL,
96
+ INSERT INTO blogsearch (
97
+ rowid,
98
+ title,
99
+ body,
100
+ url,
101
+ categories,
102
+ tags
103
+ )
104
+ VALUES (
105
+ ?,
106
+ ?,
107
+ ?,
108
+ ?,
109
+ ?,
110
+ ?
111
+ );
112
+ SQL
113
+ [rowid, title, body, url, categories, tags]
114
+ end
115
+
116
+ rescue => e
117
+ puts e.message
118
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-blogsearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bumsik Kim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ description:
56
+ email: k.bumsik@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - README.adoc
62
+ - lib/jekyll-blogsearch.rb
63
+ - lib/jekyll/blogsearch/version.rb
64
+ homepage: https://github.com/kbumsik/blogsearch
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.1.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: BlogSearch index building tool for Jekyll
87
+ test_files: []