jekyll-sqlite 0.2.0 → 0.4.0
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile +2 -2
- data/LICENSE +8 -0
- data/lib/jekyll-sqlite/generator.rb +72 -8
- data/lib/jekyll-sqlite/version.rb +1 -1
- metadata +9 -28
- data/.rubocop.yml +0 -26
- data/CODE_OF_CONDUCT.md +0 -84
- data/Rakefile +0 -84
- data/docs/.gitignore +0 -5
- data/docs/404.html +0 -8
- data/docs/CHANGELOG.md +0 -1
- data/docs/Gemfile +0 -5
- data/docs/_config.yml +0 -44
- data/docs/demo.md +0 -29
- data/docs/img/northwind-1.jpg +0 -0
- data/docs/img/northwind-2.jpg +0 -0
- data/docs/index.md +0 -26
- data/docs/install.md +0 -23
- data/docs/usage/datapage.md +0 -73
- data/docs/usage/dynamic.md +0 -54
- data/docs/usage/index.md +0 -20
- data/docs/usage/nested.md +0 -44
- data/docs/usage/per-page.md +0 -41
- data/docs/usage/writing-queries.md +0 -32
- data/jekyll-sqlite.gemspec +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa7d86717dfe79612ee35243b63627985935dcabab7a6160462b78ef9a5fd171
|
|
4
|
+
data.tar.gz: 7209f11ebb87f143fb410f5944d503c879e6164bdefbb2e1b47bf94f41a0c833
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d98916c7419f2c47a68958f599ad359d7640746074b4b9f9dd80a5240d2449b269aec75d056a962e3ecc87c06f281c7c38d7952e076e3494debdf3d53c57a0d
|
|
7
|
+
data.tar.gz: 7d60022fa371cae213eb56e4e366106d5a6b5fe709c252e4503bfea73e46bee1997acf8259aa2bf5324af2bef9bbb1a04df5e98de872318a135a8dc508aa9abd
|
data/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.4.0] - 2026-05-05
|
|
14
|
+
- Adds collection support
|
|
15
|
+
|
|
16
|
+
## [0.2.1] - 2026-01-03
|
|
17
|
+
- Only passes named parameters in SQLite query. Requires sqlite3-ruby 2.9.0
|
|
18
|
+
|
|
13
19
|
## [0.2.0] - 2025-08-23
|
|
14
20
|
- Multiple-levels of nesting is now supported
|
|
15
21
|
- Slight performance improvement by keeping database open for entire plugin run
|
|
@@ -33,4 +39,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
33
39
|
|
|
34
40
|
## [0.1.0] - 2023-05-08
|
|
35
41
|
|
|
36
|
-
- Initial release
|
|
42
|
+
- Initial release
|
data/Gemfile
CHANGED
|
@@ -6,9 +6,9 @@ source "https://rubygems.org"
|
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
8
|
# These are development dependencies
|
|
9
|
+
gem "erb", "~> 6.0"
|
|
9
10
|
gem "jekyll", "~> 4.4", ">= 4.4.1"
|
|
11
|
+
gem "logger", "~> 1.7"
|
|
10
12
|
gem "rake", "~> 13.3"
|
|
11
13
|
gem "rubocop", "~> 1.80"
|
|
12
14
|
gem "rubocop-rake", "~> 0.7"
|
|
13
|
-
|
|
14
|
-
gem "logger", "~> 1.7"
|
data/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) Nemo
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "sqlite3"
|
|
4
|
+
require "time"
|
|
4
5
|
|
|
5
6
|
module JekyllSQlite
|
|
6
7
|
# Main generator class
|
|
8
|
+
# rubocop:disable Metrics/ClassLength
|
|
7
9
|
class Generator < Jekyll::Generator
|
|
8
10
|
# Set to high to be higher than the Jekyll Datapages Plugin
|
|
9
11
|
priority :high
|
|
@@ -49,20 +51,24 @@ module JekyllSQlite
|
|
|
49
51
|
# Since we don't know if the query needs them
|
|
50
52
|
# we ignore all errors about "no such bind parameter"
|
|
51
53
|
def _prepare_query(stmt, params)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
stmt.named_params.each do |key|
|
|
55
|
+
val = params[key]
|
|
56
|
+
unless [Integer, String, Float, SQLite3::Blob, nil].include? val.class
|
|
57
|
+
Jekyll.logger.error "#{key} type is #{val.class} in query: #{stmt.get_sql}"
|
|
58
|
+
end
|
|
59
|
+
stmt.bind_param key, params[key]
|
|
56
60
|
end
|
|
57
61
|
end
|
|
58
62
|
|
|
59
63
|
##
|
|
60
|
-
# Validate given configuration object
|
|
64
|
+
# Validate given configuration object.
|
|
65
|
+
# A config is valid when it is a Hash with a query, a readable file,
|
|
66
|
+
# and either a data: or collection: target.
|
|
61
67
|
def valid_config?(config)
|
|
62
68
|
return false unless config.is_a? Hash
|
|
63
69
|
return false unless config.key?("query")
|
|
64
|
-
return false unless File.exist?(config["file"])
|
|
65
|
-
return false unless config.key?("data")
|
|
70
|
+
return false unless config["file"] && File.exist?(config["file"])
|
|
71
|
+
return false unless config.key?("data") || config.key?("collection")
|
|
66
72
|
|
|
67
73
|
true
|
|
68
74
|
end
|
|
@@ -99,14 +105,71 @@ module JekyllSQlite
|
|
|
99
105
|
Jekyll.logger.error "Jekyll SQLite:", "Invalid Configuration. Skipping"
|
|
100
106
|
next
|
|
101
107
|
end
|
|
102
|
-
|
|
108
|
+
|
|
109
|
+
if config["collection"]
|
|
110
|
+
generate_collection_from_config(config)
|
|
111
|
+
else
|
|
112
|
+
generate_data_from_config(root, config)
|
|
113
|
+
end
|
|
103
114
|
end
|
|
104
115
|
end
|
|
105
116
|
|
|
117
|
+
##
|
|
118
|
+
# Build documents from query rows and append them to the named site collection.
|
|
119
|
+
def generate_collection_from_config(config)
|
|
120
|
+
name = config["collection"]
|
|
121
|
+
collection = @site.collections[name]
|
|
122
|
+
unless collection
|
|
123
|
+
Jekyll.logger.error "Jekyll SQLite:", "Collection '#{name}' not declared in _config.yml"
|
|
124
|
+
return
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
db = get_database(config["file"])
|
|
128
|
+
db.results_as_hash = config.fetch("results_as_hash", true)
|
|
129
|
+
rows = db.execute(config["query"])
|
|
130
|
+
rows.each_with_index { |row, idx| collection.docs << build_collection_doc(collection, row, idx) }
|
|
131
|
+
Jekyll.logger.info "Jekyll SQLite:", "Loaded collection #{name}. Count=#{rows.size}"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Build a synthetic document path from optional `name` and `path` columns.
|
|
135
|
+
# Falls back to a 1-based row id (idx+1) when `name` is missing, and to
|
|
136
|
+
# no subdirectory when `path` is missing. The `name` and `path` SQL
|
|
137
|
+
# columns are what feed Jekyll's :name and :path permalink placeholders.
|
|
138
|
+
def synth_doc_path(collection, row, idx)
|
|
139
|
+
name = column_string(row, "name") || (idx + 1).to_s
|
|
140
|
+
subdir = column_string(row, "path")
|
|
141
|
+
parts = ["_#{collection.label}"]
|
|
142
|
+
parts << subdir if subdir
|
|
143
|
+
parts << "#{name}.md"
|
|
144
|
+
File.join(@site.source, *parts)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def build_collection_doc(collection, row, idx)
|
|
148
|
+
doc = Jekyll::Document.new(synth_doc_path(collection, row, idx),
|
|
149
|
+
site: @site, collection: collection)
|
|
150
|
+
row.each do |k, v|
|
|
151
|
+
next unless k.is_a?(String)
|
|
152
|
+
|
|
153
|
+
v = Time.parse(v) if k == "date" && v.is_a?(String)
|
|
154
|
+
doc.data[k] = v
|
|
155
|
+
end
|
|
156
|
+
# Jekyll's :title permalink placeholder reads data["slug"], not data["title"].
|
|
157
|
+
# Auto-populate slug from title so SQL-provided titles show up in URLs.
|
|
158
|
+
doc.data["slug"] ||= doc.data["title"]
|
|
159
|
+
doc.content = row.key?("content") ? row["content"].to_s : ""
|
|
160
|
+
doc
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def column_string(row, key)
|
|
164
|
+
v = row[key]
|
|
165
|
+
v.is_a?(String) && !v.empty? ? v : nil
|
|
166
|
+
end
|
|
167
|
+
|
|
106
168
|
##
|
|
107
169
|
# Entrpoint to the generator, called by Jekyll
|
|
108
170
|
def generate(site)
|
|
109
171
|
@db = {}
|
|
172
|
+
@site = site
|
|
110
173
|
gen(site.data, site.config)
|
|
111
174
|
site.pages.each do |page|
|
|
112
175
|
gen(page.data, page)
|
|
@@ -115,4 +178,5 @@ module JekyllSQlite
|
|
|
115
178
|
close_all_databases
|
|
116
179
|
end
|
|
117
180
|
end
|
|
181
|
+
# rubocop:enable Metrics/ClassLength
|
|
118
182
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll-sqlite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nemo
|
|
@@ -15,53 +15,34 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 2.
|
|
18
|
+
version: 2.9.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 2.
|
|
25
|
+
version: 2.9.0
|
|
26
26
|
email:
|
|
27
27
|
- jekyll-sqlite@captnemo.in
|
|
28
28
|
executables: []
|
|
29
29
|
extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
|
31
31
|
files:
|
|
32
|
-
- ".rubocop.yml"
|
|
33
32
|
- CHANGELOG.md
|
|
34
|
-
- CODE_OF_CONDUCT.md
|
|
35
33
|
- Gemfile
|
|
34
|
+
- LICENSE
|
|
36
35
|
- README.md
|
|
37
|
-
- Rakefile
|
|
38
|
-
- docs/.gitignore
|
|
39
|
-
- docs/404.html
|
|
40
|
-
- docs/CHANGELOG.md
|
|
41
|
-
- docs/Gemfile
|
|
42
|
-
- docs/_config.yml
|
|
43
|
-
- docs/demo.md
|
|
44
|
-
- docs/img/northwind-1.jpg
|
|
45
|
-
- docs/img/northwind-2.jpg
|
|
46
|
-
- docs/index.md
|
|
47
|
-
- docs/install.md
|
|
48
|
-
- docs/usage/datapage.md
|
|
49
|
-
- docs/usage/dynamic.md
|
|
50
|
-
- docs/usage/index.md
|
|
51
|
-
- docs/usage/nested.md
|
|
52
|
-
- docs/usage/per-page.md
|
|
53
|
-
- docs/usage/writing-queries.md
|
|
54
|
-
- jekyll-sqlite.gemspec
|
|
55
36
|
- lib/jekyll-sqlite/generator.rb
|
|
56
37
|
- lib/jekyll-sqlite/version.rb
|
|
57
38
|
- lib/jekyll_sqlite.rb
|
|
58
|
-
homepage: https://
|
|
39
|
+
homepage: https://captnemo.in/jekyll-sqlite/
|
|
59
40
|
licenses:
|
|
60
41
|
- MIT
|
|
61
42
|
metadata:
|
|
62
|
-
homepage_uri: https://
|
|
63
|
-
source_code_uri: https://github.com/captn3m0/jekyll-sqlite
|
|
64
|
-
changelog_uri: https://
|
|
43
|
+
homepage_uri: https://captnemo.in/jekyll-sqlite/
|
|
44
|
+
source_code_uri: https://github.com/captn3m0/jekyll-sqlite/
|
|
45
|
+
changelog_uri: https://captnemo.in/jekyll-sqlite/CHANGELOG.html
|
|
65
46
|
rubygems_mfa_required: 'true'
|
|
66
47
|
rdoc_options: []
|
|
67
48
|
require_paths:
|
|
@@ -77,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
77
58
|
- !ruby/object:Gem::Version
|
|
78
59
|
version: '0'
|
|
79
60
|
requirements: []
|
|
80
|
-
rubygems_version:
|
|
61
|
+
rubygems_version: 4.0.6
|
|
81
62
|
specification_version: 4
|
|
82
63
|
summary: A Jekyll plugin to use SQLite databases as a data source.
|
|
83
64
|
test_files: []
|
data/.rubocop.yml
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
plugins: rubocop-rake
|
|
2
|
-
AllCops:
|
|
3
|
-
TargetRubyVersion: 3.2
|
|
4
|
-
NewCops: enable
|
|
5
|
-
Exclude:
|
|
6
|
-
- "node_modules/**/*"
|
|
7
|
-
- "tmp/**/*"
|
|
8
|
-
- "vendor/**/*"
|
|
9
|
-
- ".git/**/*"
|
|
10
|
-
- "test/_plugins/jekyll_sqlite_generator.rb"
|
|
11
|
-
- "docs/**/*"
|
|
12
|
-
Style/StringLiterals:
|
|
13
|
-
Enabled: true
|
|
14
|
-
EnforcedStyle: double_quotes
|
|
15
|
-
|
|
16
|
-
Style/StringLiteralsInInterpolation:
|
|
17
|
-
Enabled: true
|
|
18
|
-
EnforcedStyle: double_quotes
|
|
19
|
-
|
|
20
|
-
Layout/LineLength:
|
|
21
|
-
Max: 120
|
|
22
|
-
|
|
23
|
-
Metrics/AbcSize:
|
|
24
|
-
Max: 20
|
|
25
|
-
Metrics/MethodLength:
|
|
26
|
-
Max: 100
|
data/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
6
|
-
|
|
7
|
-
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
8
|
-
|
|
9
|
-
## Our Standards
|
|
10
|
-
|
|
11
|
-
Examples of behavior that contributes to a positive environment for our community include:
|
|
12
|
-
|
|
13
|
-
* Demonstrating empathy and kindness toward other people
|
|
14
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
|
15
|
-
* Giving and gracefully accepting constructive feedback
|
|
16
|
-
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
|
17
|
-
* Focusing on what is best not just for us as individuals, but for the overall community
|
|
18
|
-
|
|
19
|
-
Examples of unacceptable behavior include:
|
|
20
|
-
|
|
21
|
-
* The use of sexualized language or imagery, and sexual attention or
|
|
22
|
-
advances of any kind
|
|
23
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
24
|
-
* Public or private harassment
|
|
25
|
-
* Publishing others' private information, such as a physical or email
|
|
26
|
-
address, without their explicit permission
|
|
27
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
28
|
-
professional setting
|
|
29
|
-
|
|
30
|
-
## Enforcement Responsibilities
|
|
31
|
-
|
|
32
|
-
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
33
|
-
|
|
34
|
-
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
|
35
|
-
|
|
36
|
-
## Scope
|
|
37
|
-
|
|
38
|
-
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
39
|
-
|
|
40
|
-
## Enforcement
|
|
41
|
-
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at coc@captnemo.in. All complaints will be reviewed and investigated promptly and fairly.
|
|
43
|
-
|
|
44
|
-
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
45
|
-
|
|
46
|
-
## Enforcement Guidelines
|
|
47
|
-
|
|
48
|
-
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
|
49
|
-
|
|
50
|
-
### 1. Correction
|
|
51
|
-
|
|
52
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
|
53
|
-
|
|
54
|
-
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
|
55
|
-
|
|
56
|
-
### 2. Warning
|
|
57
|
-
|
|
58
|
-
**Community Impact**: A violation through a single incident or series of actions.
|
|
59
|
-
|
|
60
|
-
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
|
61
|
-
|
|
62
|
-
### 3. Temporary Ban
|
|
63
|
-
|
|
64
|
-
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
|
65
|
-
|
|
66
|
-
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
|
67
|
-
|
|
68
|
-
### 4. Permanent Ban
|
|
69
|
-
|
|
70
|
-
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
71
|
-
|
|
72
|
-
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
|
73
|
-
|
|
74
|
-
## Attribution
|
|
75
|
-
|
|
76
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
|
77
|
-
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
78
|
-
|
|
79
|
-
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
|
80
|
-
|
|
81
|
-
[homepage]: https://www.contributor-covenant.org
|
|
82
|
-
|
|
83
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
84
|
-
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Rakefile
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/gem_tasks"
|
|
4
|
-
require "rubocop/rake_task"
|
|
5
|
-
require "jekyll"
|
|
6
|
-
require "sqlite3"
|
|
7
|
-
|
|
8
|
-
RuboCop::RakeTask.new
|
|
9
|
-
|
|
10
|
-
def assert(cond, msg = "Assertion Failed")
|
|
11
|
-
raise msg unless cond
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def query_db(query)
|
|
15
|
-
db = SQLite3::Database.new "_db/northwind.db"
|
|
16
|
-
db.results_as_hash = true
|
|
17
|
-
results = db.execute query
|
|
18
|
-
results[0]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# rubocop:disable Metrics/AbcSize
|
|
22
|
-
def validate_json
|
|
23
|
-
file = "_site/data.json"
|
|
24
|
-
data = JSON.parse(File.read(file))
|
|
25
|
-
assert data["orders"].size == 53, "Expected 53 orders, got #{data["orders"].size}"
|
|
26
|
-
assert data["customers"].size == 93, "Expected 93 customers, got #{data["customers"].size}"
|
|
27
|
-
assert data["categories"].size == 8, "Expected 93 categories, got #{data["categories"].size}"
|
|
28
|
-
assert data["orders"][0] == query_db("SELECT * FROM Orders LIMIT 1"), "Order Fetch Failed"
|
|
29
|
-
assert data["customers"][0] == query_db("SELECT * FROM Customers LIMIT 1"), "Customer Fetch Failed"
|
|
30
|
-
assert data["customers"][0] == query_db("SELECT * FROM Customers LIMIT 1"), "Customer Fetch Failed"
|
|
31
|
-
assert data["categories"][0]["products"].size == 12, "Products don't match"
|
|
32
|
-
data["categories"][0]["products"].each do |p|
|
|
33
|
-
assert p["CategoryID"] == 1, "CategoryID doesn't match"
|
|
34
|
-
end
|
|
35
|
-
assert data["delayedOrders"].size == 17
|
|
36
|
-
assert data["delayedOrders"][0]["OrderID"] == 10_249
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def validate_page_json
|
|
40
|
-
file = "_site/suppliers.json"
|
|
41
|
-
read_data = JSON.parse(File.read(file))
|
|
42
|
-
data = read_data["allSuppliers"]
|
|
43
|
-
assert data.size == 29, "Expected 29 suppliers, got #{data.size}"
|
|
44
|
-
r = query_db("SELECT CompanyName, SupplierID FROM Suppliers ORDER BY SupplierID LIMIT 1")
|
|
45
|
-
assert r["CompanyName"] == data[0]["CompanyName"], "Company Name doesn't match"
|
|
46
|
-
assert r["SupplierID"] == data[0]["SupplierID"], "Supplier ID doesn't match"
|
|
47
|
-
assert data[0]["products"].size == 3, "Products don't match"
|
|
48
|
-
assert data[0]["products"][0]["ProductName"] == "Chai"
|
|
49
|
-
assert data[0]["products"][1]["ProductName"] == "Chang"
|
|
50
|
-
assert data[0]["products"][2]["ProductName"] == "Aniseed Syrup"
|
|
51
|
-
|
|
52
|
-
# Focus Supplier - this uses the data from the page front-matter to prepare a query
|
|
53
|
-
fs = query_db("SELECT * FROM Suppliers WHERE SupplierID = 6")
|
|
54
|
-
assert read_data["focusSupplier"][0] == fs, "Focus Supplier doesn't match"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def validate_employees_json
|
|
58
|
-
file = "_site/employees.json"
|
|
59
|
-
regions = JSON.parse(File.read(file))
|
|
60
|
-
assert regions.size == 4
|
|
61
|
-
assert regions[0]["RegionID"] == 1, "First RegionID should be 1"
|
|
62
|
-
assert regions[0]["RegionDescription"] == "Eastern", "First Region is Eastern"
|
|
63
|
-
assert regions[-1]["RegionID"] == 4, "Four zotal Regions"
|
|
64
|
-
assert regions[0]["territories"].size == 19, "There should be 19 territories in Eastern"
|
|
65
|
-
assert regions[0]["territories"][0]["TerritoryID"] == "01730", "First TerritoryID should be 1"
|
|
66
|
-
assert regions[0]["territories"][0]["TerritoryDescription"] == "Bedford", "First TerritoryID should be Bedford"
|
|
67
|
-
bedford = regions[0]["territories"][0]
|
|
68
|
-
assert bedford == {
|
|
69
|
-
"TerritoryID" => "01730",
|
|
70
|
-
"TerritoryDescription" => "Bedford",
|
|
71
|
-
"EmployeeIDs" => [{ "EmployeeID" => 2, "FirstName" => "Andrew", "LastName" => "Fuller" }]
|
|
72
|
-
}, "Bedford should have Andrew Fuller"
|
|
73
|
-
end
|
|
74
|
-
# rubocop:enable Metrics/AbcSize
|
|
75
|
-
task default: :rubocop
|
|
76
|
-
|
|
77
|
-
desc "Build Test Site"
|
|
78
|
-
task :test do
|
|
79
|
-
Dir.chdir("test")
|
|
80
|
-
Jekyll::Site.new(Jekyll.configuration).process
|
|
81
|
-
validate_json
|
|
82
|
-
validate_page_json
|
|
83
|
-
validate_employees_json
|
|
84
|
-
end
|
data/docs/.gitignore
DELETED
data/docs/404.html
DELETED
data/docs/CHANGELOG.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
../CHANGELOG.md
|
data/docs/Gemfile
DELETED
data/docs/_config.yml
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
theme: just-the-docs
|
|
2
|
-
title: Jekyll SQLite
|
|
3
|
-
description: >-
|
|
4
|
-
generator plugin to lets you use SQLite database instead of data files as a
|
|
5
|
-
data source. It lets you easily create APIs and websites from a SQLite
|
|
6
|
-
database, by linking together a database file, your template, and the relevant
|
|
7
|
-
queries.
|
|
8
|
-
baseurl: "/jekyll-sqlite"
|
|
9
|
-
url: "https://captnemo.in"
|
|
10
|
-
github_username: captn3m0
|
|
11
|
-
# https://just-the-docs.com/docs/configuration/
|
|
12
|
-
favicon_ico: https://jekyllrb.com/favicon.ico
|
|
13
|
-
aux_links:
|
|
14
|
-
GitHub:
|
|
15
|
-
- "https://github.com/captn3m0/jekyll-sqlite/"
|
|
16
|
-
RubyGems:
|
|
17
|
-
- "https://rubygems.org/gems/jekyll-sqlite"
|
|
18
|
-
gh_edit_link: true
|
|
19
|
-
gh_edit_link_text: "Edit this page on GitHub."
|
|
20
|
-
gh_edit_repository: "https://github.com/captn3m0/jekyll-sqlite" # the github URL for your repo
|
|
21
|
-
gh_edit_branch: "main"
|
|
22
|
-
gh_edit_source: docs
|
|
23
|
-
gh_edit_view_mode: "edit"
|
|
24
|
-
|
|
25
|
-
callouts:
|
|
26
|
-
demo:
|
|
27
|
-
color: green
|
|
28
|
-
opacity: 0.5
|
|
29
|
-
note:
|
|
30
|
-
color: yellow
|
|
31
|
-
opacity: 0.3
|
|
32
|
-
# https://jekyllrb.com/docs/configuration/front-matter-defaults/
|
|
33
|
-
defaults:
|
|
34
|
-
- scope:
|
|
35
|
-
path: ""
|
|
36
|
-
values:
|
|
37
|
-
layout: default
|
|
38
|
-
encoding: utf-8
|
|
39
|
-
markdown: kramdown
|
|
40
|
-
strict_front_matter: true
|
|
41
|
-
# Silence Saas deprecation warnings, to be removed after this is fixed in just-the-docs
|
|
42
|
-
sass:
|
|
43
|
-
quiet_deps: true # https://github.com/just-the-docs/just-the-docs/issues/1541
|
|
44
|
-
silence_deprecations: ['import']
|
data/docs/demo.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Demo
|
|
3
|
-
permalink: /demo.html
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
🏁 A fully-functional demo website that uses this plugin is available at
|
|
7
|
-
[northwind.captnemo.in](https://northwind.captnemo.in). The source code for
|
|
8
|
-
the demo is available at [captn3m0/northwind](https://github.com/captn3m0/northwind).
|
|
9
|
-
You can find more details at the demo page.
|
|
10
|
-
|
|
11
|
-
Here is a screenshot:
|
|
12
|
-
|
|
13
|
-

|
|
14
|
-
|
|
15
|
-
It relies on all features of the plugin, along with using `jekyll-datapage_gen`
|
|
16
|
-
plugin to generate individual pages for each data item.
|
|
17
|
-
|
|
18
|
-
1. A [per-page query](usage/#per-page-queries) is used on the restock page to generate list of
|
|
19
|
-
products that need to be restocked. [source](https://github.com/captn3m0/northwind/blob/main/restock.md?plain=1)
|
|
20
|
-
2. Customers, Orders, Products, Categories are set as global data items
|
|
21
|
-
in [config.yml](https://github.com/captn3m0/northwind/blob/main/_config.yml)
|
|
22
|
-
3. `site.data.categories[*].products` is filled using a parameterised query
|
|
23
|
-
in [`config.yml`](https://github.com/captn3m0/northwind/blob/main/_config.yml#L47-L49)
|
|
24
|
-
4. Featured Product and Employee of the Month, shown on homepage are set by a query
|
|
25
|
-
in `config.yml`, but the query parameters are set in [`_data`](https://github.com/captn3m0/northwind/tree/main/_data)
|
|
26
|
-
directory as YML files.
|
|
27
|
-
5. The datapage plugin config generates a page for every product and customer.
|
|
28
|
-
|
|
29
|
-
The database is a trimmed-version of the northwind database from https://github.com/jpwhite3/northwind-SQLite3.
|
data/docs/img/northwind-1.jpg
DELETED
|
Binary file
|
data/docs/img/northwind-2.jpg
DELETED
|
Binary file
|
data/docs/index.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Home
|
|
3
|
-
nav_order: 0
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
A Jekyll generator plugin to lets you use SQLite databases instead of [Data Files][df] as a
|
|
7
|
-
data source. It lets you easily create APIs and websites from a SQLite
|
|
8
|
-
database, by linking together a database file, your template, and the relevant
|
|
9
|
-
queries.
|
|
10
|
-
|
|
11
|
-
Jekyll's Data Files are great, but they are limited to YAML/JSON/TSV/CSV file
|
|
12
|
-
formats - this plugin gives you another option: SQLite databases.
|
|
13
|
-
|
|
14
|
-
It supports site-level queries, per-page queries, and prepared queries that can
|
|
15
|
-
use existing data (possibly generated via more queries) as parameters.
|
|
16
|
-
|
|
17
|
-
The primary usecase is to **avoid Liquid Hell**, wherein you're left mangling
|
|
18
|
-
multiple data sources from CSV/JSON/YAML files using liquid templating by
|
|
19
|
-
saving temporary variables, creating maps, and so on. SQL is a decent language
|
|
20
|
-
for reshaping datasets - supporting joins, filters, and aggregations. So this
|
|
21
|
-
allows you to use SQL for reshaping your data, and then use liquid
|
|
22
|
-
for what it was meant for - presentation and templating.
|
|
23
|
-
|
|
24
|
-
[](https://github.com/captn3m0/jekyll-sqlite/actions/workflows/main.yml) [](https://badge.fury.io/rb/jekyll-sqlite)
|
|
25
|
-
|
|
26
|
-
[df]: https://jekyllrb.com/docs/datafiles/ "Data Files at Jekyll Docs site"
|
data/docs/install.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Installation
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Add this line to your site's `Gemfile`:
|
|
6
|
-
|
|
7
|
-
```ruby
|
|
8
|
-
gem 'jekyll-sqlite'
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
And then add this line to your site's `_config.yml`:
|
|
12
|
-
|
|
13
|
-
```yml
|
|
14
|
-
plugins:
|
|
15
|
-
- jekyll_sqlite
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
See [Usage](/jekyll-sqlite/usage/) for next steps.
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
Note that only supported versions of [Ruby](https://endoflife.date/ruby)
|
|
23
|
-
and [Jekyll](https://endoflife.date/ruby) are supported.
|
data/docs/usage/datapage.md
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Using with Datapage Plugin
|
|
3
|
-
parent: Usage
|
|
4
|
-
nav_order: 2
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
The Jekyll [Datapage Generator](https://github.com/avillafiorita/jekyll-datapage_gen)
|
|
8
|
-
plugin allows you to specify data files for which we want to
|
|
9
|
-
generate one page per record.
|
|
10
|
-
|
|
11
|
-
You can use it alongside this plugin to generate data from a SQLite database,
|
|
12
|
-
and generate a page per row of your resultset.
|
|
13
|
-
|
|
14
|
-
This is how a simple configuration would look:
|
|
15
|
-
|
|
16
|
-
```yaml
|
|
17
|
-
# for the sqlite plugin
|
|
18
|
-
sqlite:
|
|
19
|
-
- data: restaurants
|
|
20
|
-
file: _db/reviews.db
|
|
21
|
-
query: SELECT id, name, last_review_date > 1672531200 as active, address FROM restaurants;
|
|
22
|
-
|
|
23
|
-
# for the datapage_gen plugin
|
|
24
|
-
page_gen:
|
|
25
|
-
- data: restaurants
|
|
26
|
-
# The layout used for each generated page _layouts/restaurant.html
|
|
27
|
-
template: restaurant
|
|
28
|
-
page_data_prefix: restaurants
|
|
29
|
-
name: id
|
|
30
|
-
title: name
|
|
31
|
-
filter: active
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
This will automatically generate a file for each restaurant `restaurants/#
|
|
35
|
-
{id}.html` file with the layout `_layouts/restaurant.html` and page.id,
|
|
36
|
-
page.name, page.active set and page.title set to restaurant name. Query data is
|
|
37
|
-
accessed in the page template via `{%raw%}{{ page.restaurants.address }}{%endraw%}` - the
|
|
38
|
-
namespace set in `page_data_prefix`.
|
|
39
|
-
|
|
40
|
-
Note that the `datapage_gen` plugin will run _after_ the `jekyll-sqlite` plugin, if you generate any pages with per-page queries, these queries will not execute.
|
|
41
|
-
|
|
42
|
-
## Demo Example
|
|
43
|
-
|
|
44
|
-
The following example comes from the [Demo](../demo/).
|
|
45
|
-
|
|
46
|
-
The following datapage configuration in `_config.yml`:
|
|
47
|
-
|
|
48
|
-
```yml
|
|
49
|
-
page_gen:
|
|
50
|
-
- data: products
|
|
51
|
-
template: product # _layouts/product.html
|
|
52
|
-
page_data_prefix: product
|
|
53
|
-
title: ProductName
|
|
54
|
-
name: ProductID
|
|
55
|
-
extension: html
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
will generate a page for each product in the `site.data.products` array.
|
|
59
|
-
|
|
60
|
-
In order to get data into the array, we can use:
|
|
61
|
-
|
|
62
|
-
```yml
|
|
63
|
-
sqlite:
|
|
64
|
-
- data: products
|
|
65
|
-
file: _db/northwind.db
|
|
66
|
-
query: SELECT * from Products
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Here's a screenshot of how it looks:
|
|
70
|
-
|
|
71
|
-

|
|
72
|
-
|
|
73
|
-
See it in action at <https://northwind.captnemo.in/products/1.html>
|
data/docs/usage/dynamic.md
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Dynamic DB File
|
|
3
|
-
parent: Usage
|
|
4
|
-
nav_order: 3
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
If you want to select the database filename via an environment variable,
|
|
8
|
-
you can use the following options as a workaround:
|
|
9
|
-
|
|
10
|
-
## Using `envsubst` from GNU gettext
|
|
11
|
-
|
|
12
|
-
You can install it via [brew](https://formulae.brew.sh/formula/gettext)
|
|
13
|
-
or [on linux](https://repology.org/project/gettext/versions).
|
|
14
|
-
|
|
15
|
-
First, define your database filename,
|
|
16
|
-
and create a new configuration template file.
|
|
17
|
-
|
|
18
|
-
```sh
|
|
19
|
-
export JEKYLL_DB=events-blr.db
|
|
20
|
-
cp _config.yml _config.txt
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Then, use the database name in your new ocnfig file
|
|
24
|
-
|
|
25
|
-
```yaml
|
|
26
|
-
sqlite:
|
|
27
|
-
data: events
|
|
28
|
-
file: $JEKYLL_DB
|
|
29
|
-
query: SELECT * FROM events
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Then, use `envsubst` to generate the `_config.yml`
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
envsubst < "_config.txt" > "_config.yml"
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Using multiple configuration files
|
|
39
|
-
|
|
40
|
-
You can define your `sqlite` parameter multiple times
|
|
41
|
-
across multiple files, using different database filenames
|
|
42
|
-
|
|
43
|
-
For eg, `_config-blr.yml` could only include:
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
sqlite:
|
|
47
|
-
data: events
|
|
48
|
-
file: events-blr.db
|
|
49
|
-
query: SELECT * FROM events
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
And you can run jekyll using `jekyll --config _config.yml,_config-blr.yml`
|
|
53
|
-
|
|
54
|
-
However, this requires duplicating your query across multiple files.
|
data/docs/usage/index.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Usage
|
|
3
|
-
has_toc: false
|
|
4
|
-
permalink: /usage/
|
|
5
|
-
---
|
|
6
|
-
Update your `_config.yml` to define your data sources with your SQLite database.
|
|
7
|
-
|
|
8
|
-
```yml
|
|
9
|
-
...
|
|
10
|
-
sqlite:
|
|
11
|
-
- data: customers
|
|
12
|
-
file: *db
|
|
13
|
-
query: SELECT * from Customers
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Then, you can use the `site.data` attributes accordingly:
|
|
17
|
-
|
|
18
|
-
```liquid{%raw%}
|
|
19
|
-
{{ site.data.customers | jsonify }}{%endraw%}
|
|
20
|
-
```
|
data/docs/usage/nested.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Nested Queries
|
|
3
|
-
parent: Usage
|
|
4
|
-
nav_order: 4
|
|
5
|
-
---
|
|
6
|
-
Starting from `0.2.0`, queries can be nested infinitely.
|
|
7
|
-
|
|
8
|
-
The following configuration is used in the [demo](../demo/):
|
|
9
|
-
|
|
10
|
-
```yaml
|
|
11
|
-
sqlite:
|
|
12
|
-
- data: regions
|
|
13
|
-
file: *db
|
|
14
|
-
query: |
|
|
15
|
-
SELECT RegionID, RegionDescription FROM Regions
|
|
16
|
-
ORDER BY RegionID
|
|
17
|
-
|
|
18
|
-
- data: regions.territories
|
|
19
|
-
file: *db
|
|
20
|
-
query: |
|
|
21
|
-
SELECT TerritoryID, TerritoryDescription FROM Territories
|
|
22
|
-
WHERE RegionID = :RegionID
|
|
23
|
-
ORDER BY TerritoryDescription
|
|
24
|
-
|
|
25
|
-
- data: regions.territories.EmployeeIDs
|
|
26
|
-
file: *db
|
|
27
|
-
query: |
|
|
28
|
-
SELECT T.EmployeeID as EmployeeID, FirstName,LastName
|
|
29
|
-
FROM EmployeeTerritories T,Employees
|
|
30
|
-
WHERE T.TerritoryID = :TerritoryID
|
|
31
|
-
AND T.EmployeeID = Employees.EmployeeID
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
The first query generates `site.data.regions` as a list. The second query
|
|
35
|
-
sets territories inside each of the regions, and the third query
|
|
36
|
-
sets the list of employees inside each territory.
|
|
37
|
-
|
|
38
|
-
{: .note }
|
|
39
|
-
> Per Page Query
|
|
40
|
-
>
|
|
41
|
-
> On the Demo website, you can see the result at
|
|
42
|
-
> [the regions page](https://northwind.captnemo.in/regions.html)
|
|
43
|
-
> where each region is broken into territories, with the name
|
|
44
|
-
> of the employee under each region.
|
data/docs/usage/per-page.md
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Per-page Queries
|
|
3
|
-
nav_order: 0
|
|
4
|
-
parent: Usage
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
The exact same syntax can be used on a per-page basis to generate data within
|
|
8
|
-
each page. This is helpful for keeping page-specific queries within the page
|
|
9
|
-
itself. Here's an example:
|
|
10
|
-
|
|
11
|
-
```yaml
|
|
12
|
-
---
|
|
13
|
-
FeaturedSupplierID: 2
|
|
14
|
-
sqlite:
|
|
15
|
-
- data: suppliers
|
|
16
|
-
file: "_db/northwind.db"
|
|
17
|
-
query: "SELECT CompanyName, SupplierID FROM suppliers ORDER BY SupplierID"
|
|
18
|
-
- data: suppliers.products
|
|
19
|
-
# This is a prepared query, where SupplierID is coming from the previous query.
|
|
20
|
-
file: "_db/northwind.db"
|
|
21
|
-
query: "SELECT ProductName, CategoryID,UnitPrice FROM products WHERE SupplierID = :SupplierID"
|
|
22
|
-
# :FeaturedSupplierID is picked up automatically from the page frontmatter.
|
|
23
|
-
- data: FeaturedSupplier
|
|
24
|
-
file: "_db/northwind.db"
|
|
25
|
-
query: "SELECT * SupplierID = :FeaturedSupplierID"
|
|
26
|
-
---
|
|
27
|
-
{%raw%}{{page.suppliers|jsonify}}{%endraw%}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
This will generate a `page.suppliers` array with all the suppliers, and a `page.FeaturedSupplier` object with the details of the featured supplier.
|
|
31
|
-
|
|
32
|
-
Each supplier will have a `products` array with all the products for that supplier.
|
|
33
|
-
|
|
34
|
-
{: .note }
|
|
35
|
-
> Per Page Query
|
|
36
|
-
>
|
|
37
|
-
> On the Demo website, a per-page query
|
|
38
|
-
> is used on the restock page to generate
|
|
39
|
-
> list of products that need to be restocked. You can see the
|
|
40
|
-
> [source](https://github.com/captn3m0/northwind/blob/main/restock.md?plain=1)
|
|
41
|
-
> and the [resulting page](https://northwind.captnemo.in/restock.html)
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Parametrized Queries
|
|
3
|
-
parent: Usage
|
|
4
|
-
nav_order: 1
|
|
5
|
-
---
|
|
6
|
-
This plugin supports prepared queries with parameter binding. This lets you
|
|
7
|
-
use existing data from a previous query, or some other source (such as
|
|
8
|
-
`site.data.*` or `page.*`) as a parameter in your query.
|
|
9
|
-
|
|
10
|
-
Say you have a YAML file defining your items (`data/books.yaml`):
|
|
11
|
-
|
|
12
|
-
```yaml
|
|
13
|
-
- id: 31323952-2708-42dc-a995-6006a23cbf00
|
|
14
|
-
name: Time Travel with a Rubber Band
|
|
15
|
-
- id: 5c8e67a0-d490-4743-b5b8-8e67bd1f95a2
|
|
16
|
-
name: The Art of Cache Invalidation
|
|
17
|
-
```
|
|
18
|
-
and the prices for the items in your SQLite database, the following configuration will enrich the `items` array with the price:
|
|
19
|
-
|
|
20
|
-
```yaml
|
|
21
|
-
sql:
|
|
22
|
-
- data: items.books
|
|
23
|
-
file: books.db
|
|
24
|
-
query: SELECT price, author FROM pricing WHERE id =:id
|
|
25
|
-
```
|
|
26
|
-
This would allow the following Liquid loop to be written:
|
|
27
|
-
|
|
28
|
-
```liquid{%raw%}
|
|
29
|
-
{% for item in site.data.items %}
|
|
30
|
-
{{item.meta.price}}, {{item.meta.author}}
|
|
31
|
-
{% endfor %}{%endraw%}
|
|
32
|
-
```
|
data/jekyll-sqlite.gemspec
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/jekyll-sqlite/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "jekyll-sqlite"
|
|
7
|
-
spec.license = "MIT"
|
|
8
|
-
spec.version = Jekyll::Sqlite::VERSION
|
|
9
|
-
spec.authors = ["Nemo"]
|
|
10
|
-
spec.email = ["jekyll-sqlite@captnemo.in"]
|
|
11
|
-
|
|
12
|
-
spec.summary = "A Jekyll plugin to use SQLite databases as a data source."
|
|
13
|
-
spec.homepage = "https://github.com/captn3m0/jekyll-sqlite"
|
|
14
|
-
spec.required_ruby_version = ">= 3.2.0"
|
|
15
|
-
|
|
16
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
17
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
|
18
|
-
spec.metadata["changelog_uri"] = "https://github.com/captn3m0/jekyll-sqlite/blob/master/CHANGELOG.md"
|
|
19
|
-
|
|
20
|
-
# Specify which files should be added to the gem when it is released.
|
|
21
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
22
|
-
spec.files = Dir.chdir(__dir__) do
|
|
23
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
|
24
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
spec.bindir = "exe"
|
|
28
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
29
|
-
spec.require_paths = ["lib"]
|
|
30
|
-
spec.add_dependency "sqlite3", "~> 2.7.3"
|
|
31
|
-
spec.metadata["rubygems_mfa_required"] = "true"
|
|
32
|
-
end
|