jekyll-sqlite 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -2
- data/CHANGELOG.md +10 -0
- data/Gemfile +7 -0
- data/README.md +67 -71
- data/Rakefile +60 -0
- data/jekyll-sqlite.gemspec +33 -0
- data/lib/jekyll-sqlite/generator.rb +107 -53
- data/lib/jekyll-sqlite/version.rb +1 -1
- metadata +10 -11
- data/Gemfile.lock +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3a6e780155f548d59a54d75d24d15d3182c6dedd73345a542a23965585fa6f8
|
4
|
+
data.tar.gz: dbf85f8845cf5190859a4b7ce655ead714e8cdb8422fa605babdde610cd32728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '04964af581a1111c2218572442300402bea84e53350c5ae89204d9d3c4f9eea33b1a4a202d17fe4be61f41ff81421355430599fcdf1d6f3ed642f7f90ffbf048'
|
7
|
+
data.tar.gz: 71a1609f7c901723e205e96864d25f7c2c65bae0492f039ebd9066c1c4ae13ae9044a7ad50a1b636283beb3cd72aa4387e0774ad73fc36e5673dd67a721867cf
|
data/.rubocop.yml
CHANGED
@@ -2,7 +2,12 @@ require: rubocop-rake
|
|
2
2
|
AllCops:
|
3
3
|
TargetRubyVersion: 3.0
|
4
4
|
NewCops: enable
|
5
|
-
|
5
|
+
Exclude:
|
6
|
+
- "node_modules/**/*"
|
7
|
+
- "tmp/**/*"
|
8
|
+
- "vendor/**/*"
|
9
|
+
- ".git/**/*"
|
10
|
+
- "test/_plugins/jekyll_sqlite_generator.rb"
|
6
11
|
Style/StringLiterals:
|
7
12
|
Enabled: true
|
8
13
|
EnforcedStyle: double_quotes
|
@@ -15,4 +20,4 @@ Layout/LineLength:
|
|
15
20
|
Max: 120
|
16
21
|
|
17
22
|
Metrics/AbcSize:
|
18
|
-
Max:
|
23
|
+
Max: 15
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.4] - 2024-07-17
|
4
|
+
- Per-page queries are now supported via a `sqlite` config block in the front matter.
|
5
|
+
- Documents support for existing site data being used within queries.
|
6
|
+
- Code cleanup and refactoring.
|
7
|
+
- Don't disable journaling on the database.
|
8
|
+
|
9
|
+
## [0.1.3] - 2024-07-02
|
10
|
+
- First functional version
|
11
|
+
- Adds tests
|
12
|
+
|
3
13
|
## [0.1.0] - 2023-05-08
|
4
14
|
|
5
15
|
- Initial release
|
data/Gemfile
CHANGED
@@ -5,6 +5,13 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in jekyll-sqlite.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
+
# These are development dependencies
|
9
|
+
gem "jekyll", "~> 4.0"
|
8
10
|
gem "rake", "~> 13.0"
|
9
11
|
gem "rubocop", "~> 1.21"
|
10
12
|
gem "rubocop-rake", "~> 0.6.0"
|
13
|
+
|
14
|
+
# Ruby 3.4 preparedness
|
15
|
+
gem "base64", "~> 0.2.0"
|
16
|
+
gem "bigdecimal", "~> 3.1"
|
17
|
+
gem "csv", "~> 3.3"
|
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
A Jekyll generator plugin to lets you use SQLite database instead of data files as a data source. It lets you easily create APIs and websites from a SQLite database, by linking together a database file, your template, and the relevant queries.
|
4
4
|
|
5
|
-
It
|
5
|
+
It supports site-level queries, per-page queries, and prepared queries that can
|
6
|
+
use existing data (possibly generated via more queries) as parameters.
|
6
7
|
|
7
8
|
[![Continuous Integration](https://github.com/captn3m0/jekyll-sqlite/actions/workflows/main.yml/badge.svg)](https://github.com/captn3m0/jekyll-sqlite/actions/workflows/main.yml) [![Gem Version](https://badge.fury.io/rb/jekyll-sqlite.svg)](https://badge.fury.io/rb/jekyll-sqlite)
|
8
9
|
|
@@ -25,88 +26,44 @@ plugins:
|
|
25
26
|
|
26
27
|
## Usage
|
27
28
|
|
28
|
-
Update your `_config.yml` to define your data sources with your SQLite database.
|
29
|
+
Update your `_config.yml` to define your data sources with your SQLite database. Please see
|
30
|
+
the `test` directory for a functional example with the [Northwind database](https://github.com/jpwhite3/northwind-SQLite3).
|
29
31
|
|
30
32
|
```yml
|
31
33
|
...
|
32
|
-
# These are run in sequence, so any nested data can work well.
|
33
34
|
sqlite:
|
34
|
-
- data:
|
35
|
-
file:
|
36
|
-
query: SELECT *
|
37
|
-
# You can use `results_as_hash` to switch between array or hash results (default).
|
38
|
-
- data: verified
|
39
|
-
results_as_hash: false # default true
|
40
|
-
file: _db/users.db
|
41
|
-
query: SELECT username, email FROM members WHERE verified=1
|
42
|
-
- data: members.posts
|
43
|
-
file: _db/posts.db
|
44
|
-
query: SELECT * FROM posts WHERE user_id = :id
|
35
|
+
- data: customers
|
36
|
+
file: *db
|
37
|
+
query: SELECT * from Customers
|
45
38
|
```
|
46
39
|
|
47
40
|
Then, you can use the `site.data` attributes accordingly:
|
48
41
|
|
49
42
|
```liquid
|
50
|
-
{
|
51
|
-
- {{member.username}}
|
52
|
-
|
53
|
-
# Your Posts
|
54
|
-
{% for post in member.posts %}
|
55
|
-
{{post}}
|
56
|
-
{% endfor %}
|
57
|
-
{% endfor %}
|
58
|
-
|
59
|
-
# Result here is an array instead of a hash.
|
60
|
-
{% for user in site.data.verified %}
|
61
|
-
- :check: {{user[0]}} (Email: {{user[1]}})
|
62
|
-
{% endfor %}
|
43
|
+
{{ site.data.customers | jsonify }}
|
63
44
|
```
|
64
45
|
|
65
|
-
##
|
66
|
-
|
67
|
-
It works well with the `datapage_gen` plugin:
|
46
|
+
## Prepared Queries
|
68
47
|
|
69
|
-
|
48
|
+
This plugin supports prepared queries with parameter binding. This lets you
|
49
|
+
use existing data from a previous query, or some other source (such as
|
50
|
+
`site.data.*` or `page.*`) as a parameter in your query.
|
70
51
|
|
71
|
-
|
72
|
-
|
73
|
-
```yaml
|
74
|
-
# This will automatically generate a file for each restaurant
|
75
|
-
# restaurants/#{id}.html file
|
76
|
-
# with the layout `_layouts/restaurant.html`
|
77
|
-
# and page.id, page.name, page.active set
|
78
|
-
# and page.title set to restaurant name
|
79
|
-
sqlite:
|
80
|
-
restaurants:
|
81
|
-
file: _db/reviews.db
|
82
|
-
sql: SELECT id, name, last_review_date > 1672531200 as active, address FROM restaurants;
|
83
|
-
page_gen:
|
84
|
-
- data: restaurants
|
85
|
-
template: restaurant
|
86
|
-
name: id
|
87
|
-
title: name
|
88
|
-
filter: active
|
89
|
-
```
|
90
|
-
|
91
|
-
## Nested Queries
|
92
|
-
|
93
|
-
You can use the rows of `site.data.items` as bind_params for your nested query. For this to work against
|
94
|
-
data generated by the plugin, the configuration order must be correct, so you need `site.data.items` above `site.data.items.nested` in your configuration.
|
95
|
-
|
96
|
-
Say you have a YAML file defining your items (`data/items.yaml`):
|
52
|
+
Say you have a YAML file defining your items (`data/books.yaml`):
|
97
53
|
|
98
54
|
```yaml
|
99
55
|
- id: 31323952-2708-42dc-a995-6006a23cbf00
|
100
|
-
name:
|
56
|
+
name: Time Travel with a Rubber Band
|
101
57
|
- id: 5c8e67a0-d490-4743-b5b8-8e67bd1f95a2
|
102
|
-
name:
|
58
|
+
name: The Art of Cache Invalidation
|
103
59
|
```
|
104
60
|
and the prices for the items in your SQLite database, the following configuration will enrich the `items` array with the price:
|
105
61
|
|
106
62
|
```yaml
|
107
63
|
sql:
|
108
|
-
- data:
|
109
|
-
query: SELECT price,author FROM pricing WHERE id =:id
|
64
|
+
- data: items.books
|
65
|
+
query: SELECT price, author FROM pricing WHERE id =:id
|
66
|
+
db: books.db
|
110
67
|
```
|
111
68
|
This would allow the following Liquid loop to be written:
|
112
69
|
|
@@ -116,23 +73,62 @@ This would allow the following Liquid loop to be written:
|
|
116
73
|
{% endfor %}
|
117
74
|
```
|
118
75
|
|
119
|
-
|
76
|
+
## Per Page Queries
|
77
|
+
|
78
|
+
The exact same syntax can be used on a per-page basis to generate data within
|
79
|
+
each page. This is helpful for keeping page-specific queries within the page
|
80
|
+
itself. Here's an example:
|
120
81
|
|
121
82
|
```yaml
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
83
|
+
---
|
84
|
+
FeaturedSupplierID: 2
|
85
|
+
sqlite:
|
86
|
+
- data: suppliers
|
87
|
+
file: "_db/northwind.db"
|
88
|
+
query: "SELECT CompanyName, SupplierID FROM suppliers ORDER BY SupplierID"
|
89
|
+
- data: suppliers.products
|
90
|
+
# This is a prepared query, where SupplierID is coming from the previous query.
|
91
|
+
file: "_db/northwind.db"
|
92
|
+
query: "SELECT ProductName, CategoryID,UnitPrice FROM products WHERE SupplierID = :SupplierID"
|
93
|
+
# :FeaturedSupplierID is picked up automatically from the page frontmatter.
|
94
|
+
- data: FeaturedSupplier
|
95
|
+
file: "_db/northwind.db"
|
96
|
+
query: "SELECT * SupplierID = :FeaturedSupplierID"
|
97
|
+
---
|
98
|
+
{{page.suppliers|jsonify}}
|
126
99
|
```
|
127
100
|
|
128
|
-
|
101
|
+
This will generate a `page.suppliers` array with all the suppliers, and a `page.FeaturedSupplier` object with the details of the featured supplier.
|
129
102
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
103
|
+
Each supplier will have a `products` array with all the products for that supplier.
|
104
|
+
|
105
|
+
## Generating Pages
|
106
|
+
|
107
|
+
It works well with the `datapage_gen` plugin:
|
108
|
+
|
109
|
+
See the [datapage_gen](https://github.com/avillafiorita/jekyll-datapage_gen) docs for more details.
|
110
|
+
|
111
|
+
Here's a sample configuration:
|
112
|
+
|
113
|
+
```yaml
|
114
|
+
sqlite:
|
115
|
+
restaurants:
|
116
|
+
file: _db/reviews.db
|
117
|
+
sql: SELECT id, name, last_review_date > 1672531200 as active, address FROM restaurants;
|
118
|
+
page_gen:
|
119
|
+
- data: restaurants
|
120
|
+
template: restaurant
|
121
|
+
name: id
|
122
|
+
title: name
|
123
|
+
filter: active
|
134
124
|
```
|
135
125
|
|
126
|
+
This will automatically generate a file for each restaurant
|
127
|
+
restaurants/#{id}.html file with the layout `_layouts/restaurant.html` and page.id, page.name, page.active set and page.title set to restaurant name
|
128
|
+
|
129
|
+
Note that the `datapage_gen` plugin will run _after_ the `jekyll-sqlite` plugin,
|
130
|
+
if you generate any pages with per-page queries, these queries will not execute.
|
131
|
+
|
136
132
|
## Development
|
137
133
|
|
138
134
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -2,7 +2,67 @@
|
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rubocop/rake_task"
|
5
|
+
require "jekyll"
|
6
|
+
require "sqlite3"
|
5
7
|
|
6
8
|
RuboCop::RakeTask.new
|
7
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
|
+
# rubocop:disable Metrics/MethodLength
|
23
|
+
def validate_json
|
24
|
+
file = "_site/data.json"
|
25
|
+
data = JSON.parse(File.read(file))
|
26
|
+
assert data["orders"].size == 53, "Expected 53 orders, got #{data["orders"].size}"
|
27
|
+
assert data["customers"].size == 93, "Expected 93 customers, got #{data["customers"].size}"
|
28
|
+
assert data["categories"].size == 8, "Expected 93 categories, got #{data["categories"].size}"
|
29
|
+
assert data["orders"][0] == query_db("SELECT * FROM Orders LIMIT 1"), "Order Fetch Failed"
|
30
|
+
assert data["customers"][0] == query_db("SELECT * FROM Customers LIMIT 1"), "Customer Fetch Failed"
|
31
|
+
assert data["customers"][0] == query_db("SELECT * FROM Customers LIMIT 1"), "Customer Fetch Failed"
|
32
|
+
assert data["categories"][0]["products"].size == 12, "Products don't match"
|
33
|
+
data["categories"][0]["products"].each do |p|
|
34
|
+
assert p["CategoryID"] == 1, "CategoryID doesn't match"
|
35
|
+
end
|
36
|
+
assert data["delayedOrders"].size == 17
|
37
|
+
assert data["delayedOrders"][0]["OrderID"] == 10_249
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_page_json
|
41
|
+
file = "_site/suppliers.json"
|
42
|
+
read_data = JSON.parse(File.read(file))
|
43
|
+
data = read_data["allSuppliers"]
|
44
|
+
assert data.size == 29, "Expected 29 suppliers, got #{data.size}"
|
45
|
+
r = query_db("SELECT CompanyName, SupplierID FROM Suppliers ORDER BY SupplierID LIMIT 1")
|
46
|
+
assert r["CompanyName"] == data[0]["CompanyName"], "Company Name doesn't match"
|
47
|
+
assert r["SupplierID"] == data[0]["SupplierID"], "Supplier ID doesn't match"
|
48
|
+
assert data[0]["products"].size == 3, "Products don't match"
|
49
|
+
assert data[0]["products"][0]["ProductName"] == "Chai"
|
50
|
+
assert data[0]["products"][1]["ProductName"] == "Chang"
|
51
|
+
assert data[0]["products"][2]["ProductName"] == "Aniseed Syrup"
|
52
|
+
|
53
|
+
# Focus Supplier - this uses the data from the page front-matter to prepare a query
|
54
|
+
fs = query_db("SELECT * FROM Suppliers WHERE SupplierID = 6")
|
55
|
+
assert read_data["focusSupplier"][0] == fs, "Focus Supplier doesn't match"
|
56
|
+
end
|
57
|
+
# rubocop:enable Metrics/AbcSize
|
58
|
+
# rubocop:enable Metrics/MethodLength
|
59
|
+
|
8
60
|
task default: :rubocop
|
61
|
+
|
62
|
+
desc "Build Test Site"
|
63
|
+
task :test do
|
64
|
+
Dir.chdir("test")
|
65
|
+
Jekyll::Site.new(Jekyll.configuration).process
|
66
|
+
validate_json
|
67
|
+
validate_page_json
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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.0.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
|
+
|
31
|
+
spec.add_dependency "sqlite3", "~> 1.6"
|
32
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
33
|
+
end
|
@@ -1,86 +1,140 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require "sqlite3"
|
4
|
+
|
3
5
|
module JekyllSQlite
|
4
6
|
# Main generator class
|
5
7
|
class Generator < Jekyll::Generator
|
6
|
-
safe true
|
7
8
|
# Set to high to be higher than the Jekyll Datapages Plugin
|
8
9
|
priority :high
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
|
11
|
+
##
|
12
|
+
# Split the given key using dots and return the last part
|
13
|
+
# customers.order -> order
|
14
|
+
def get_tip(name)
|
15
|
+
name.split(".")[-1]
|
14
16
|
end
|
15
17
|
|
18
|
+
##
|
16
19
|
# Get the root of where we are generating the data
|
17
|
-
def get_root(root,
|
18
|
-
|
20
|
+
def get_root(root, db_name)
|
21
|
+
db_name.split(".")[0..-2].each do |p|
|
19
22
|
root = root[p]
|
23
|
+
rescue KeyError
|
24
|
+
raise "Jekyll SQLite: Invalid root. #{p} not found while iterating to #{db_name}"
|
20
25
|
end
|
21
26
|
root
|
22
27
|
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
##
|
30
|
+
# Prepare the query by binding the parameters
|
31
|
+
# Since we don't know if the query needs them
|
32
|
+
# we ignore all errors about "no such bind parameter"
|
33
|
+
def _prepare_query(stmt, params)
|
34
|
+
params.each do |key, value|
|
35
|
+
stmt.bind_param key, value
|
36
|
+
rescue StandardError => e
|
37
|
+
raise e unless e.message.include? "no such bind parameter"
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
|
-
|
32
|
-
|
41
|
+
##
|
42
|
+
# Internal function to generate data given
|
43
|
+
# root: a Hash-Like root object (site.data, site.data.*, page.data)
|
44
|
+
# key: string as the key to use to attach the data to the root
|
45
|
+
# db: SQLite3 Database object to execute the query on
|
46
|
+
# query: string containing the query to execute
|
47
|
+
# Sets root[db_name] = ResultSet of the query, as an array
|
48
|
+
# Returns the count of the result set
|
49
|
+
def _gen_data(root, key, db, query)
|
33
50
|
db.prepare(query) do |stmt|
|
34
|
-
|
35
|
-
|
36
|
-
# From a statement
|
37
|
-
item.each do |key, value|
|
38
|
-
stmt.bind_param key, value
|
39
|
-
rescue StandardError # rubocop:disable Lint/SuppressedException
|
40
|
-
end
|
41
|
-
stmt.execute.each { |d| item[name] << d }
|
51
|
+
_prepare_query stmt, get_bind_params(root)
|
52
|
+
root[key] = stmt.execute.to_a
|
42
53
|
end
|
43
|
-
|
54
|
+
root[key].count
|
44
55
|
end
|
45
56
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
57
|
+
##
|
58
|
+
# Calls _gen_data for the given root
|
59
|
+
# iterates through the array if root is an array
|
60
|
+
def gen_data(root, ...)
|
61
|
+
if root.is_a? Array
|
62
|
+
# call gen_data for each item in the array
|
63
|
+
# and return the sum of all the counts
|
64
|
+
root.map { |item| gen_data(item, ...) }.sum
|
65
|
+
else
|
66
|
+
_gen_data(root, ...)
|
55
67
|
end
|
56
|
-
count
|
57
68
|
end
|
58
69
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
70
|
+
##
|
71
|
+
# Validate given configuration object
|
72
|
+
def validate_config(config)
|
73
|
+
return false unless config.is_a? Hash
|
74
|
+
return false unless config.key?("query")
|
75
|
+
return false unless File.exist?(config["file"])
|
76
|
+
return false unless config.key?("data")
|
77
|
+
|
78
|
+
true
|
79
|
+
end
|
80
|
+
|
81
|
+
## pick bindable parameters
|
82
|
+
# from the root
|
83
|
+
# All primitive values are bound to the query
|
84
|
+
# Arrays and Hashes are ignored
|
85
|
+
def get_bind_params(dict)
|
86
|
+
dict.select { |_key, value| !value.is_a?(Array) && !value.is_a?(Hash) }
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Given a configuration, generate the data
|
91
|
+
# and attach it to the given data_root
|
92
|
+
def generate_data_from_config(root, config)
|
93
|
+
key = config["data"]
|
94
|
+
query = config["query"]
|
95
|
+
file = config["file"]
|
96
|
+
SQLite3::Database.new file, readonly: true do |db|
|
97
|
+
db.results_as_hash = config.fetch("results_as_hash", true)
|
98
|
+
|
99
|
+
branch = get_root(root, key)
|
100
|
+
tip = get_tip(config["data"])
|
101
|
+
|
102
|
+
count = gen_data(branch, tip, db, query)
|
103
|
+
Jekyll.logger.info "Jekyll SQLite:", "Loaded #{key}. Count=#{count}"
|
65
104
|
end
|
66
|
-
count
|
67
105
|
end
|
68
106
|
|
69
|
-
|
70
|
-
|
107
|
+
##
|
108
|
+
# Iterate through all the pages in the site
|
109
|
+
# and generate the data from the configuration
|
110
|
+
def gen_pages(site)
|
111
|
+
site.pages.each do |page|
|
112
|
+
gen(page.data, page)
|
113
|
+
end
|
71
114
|
end
|
72
115
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
116
|
+
##
|
117
|
+
# Generate the data from the configuration
|
118
|
+
# Takes as input the root where the data will be attached
|
119
|
+
# and a configuration holder, where the sqlite key can be found
|
120
|
+
# Root is either site.data or page.data
|
121
|
+
# and config_holder is either site.config or page itself.
|
122
|
+
def gen(root, config_holder)
|
123
|
+
sqlite_configs = config_holder["sqlite"] || []
|
124
|
+
sqlite_configs.each do |config|
|
125
|
+
unless validate_config(config)
|
126
|
+
Jekyll.logger.error "Jekyll SQLite:", "Invalid Configuration. Skipping"
|
127
|
+
next
|
82
128
|
end
|
129
|
+
generate_data_from_config(root, config)
|
83
130
|
end
|
84
131
|
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Entrpoint to the generator, called by Jekyll
|
135
|
+
def generate(site)
|
136
|
+
gen(site.data, site.config)
|
137
|
+
gen_pages(site)
|
138
|
+
end
|
85
139
|
end
|
86
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-sqlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nemo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -24,9 +24,9 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
|
-
- jekyll@captnemo.in
|
29
|
+
- jekyll-sqlite@captnemo.in
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
@@ -35,9 +35,9 @@ files:
|
|
35
35
|
- CHANGELOG.md
|
36
36
|
- CODE_OF_CONDUCT.md
|
37
37
|
- Gemfile
|
38
|
-
- Gemfile.lock
|
39
38
|
- README.md
|
40
39
|
- Rakefile
|
40
|
+
- jekyll-sqlite.gemspec
|
41
41
|
- lib/jekyll-sqlite/generator.rb
|
42
42
|
- lib/jekyll-sqlite/version.rb
|
43
43
|
- lib/jekyll_sqlite.rb
|
@@ -49,7 +49,7 @@ metadata:
|
|
49
49
|
source_code_uri: https://github.com/captn3m0/jekyll-sqlite
|
50
50
|
changelog_uri: https://github.com/captn3m0/jekyll-sqlite/blob/master/CHANGELOG.md
|
51
51
|
rubygems_mfa_required: 'true'
|
52
|
-
post_install_message:
|
52
|
+
post_install_message:
|
53
53
|
rdoc_options: []
|
54
54
|
require_paths:
|
55
55
|
- lib
|
@@ -64,9 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
68
|
-
signing_key:
|
67
|
+
rubygems_version: 3.5.11
|
68
|
+
signing_key:
|
69
69
|
specification_version: 4
|
70
|
-
summary: A Jekyll plugin
|
71
|
-
a data source.
|
70
|
+
summary: A Jekyll plugin to use SQLite databases as a data source.
|
72
71
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
jekyll-sqlite (0.1.1)
|
5
|
-
sqlite3 (~> 1.6)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ast (2.4.2)
|
11
|
-
json (2.6.3)
|
12
|
-
parallel (1.23.0)
|
13
|
-
parser (3.2.2.1)
|
14
|
-
ast (~> 2.4.1)
|
15
|
-
rainbow (3.1.1)
|
16
|
-
rake (13.0.6)
|
17
|
-
regexp_parser (2.8.0)
|
18
|
-
rexml (3.2.5)
|
19
|
-
rubocop (1.50.2)
|
20
|
-
json (~> 2.3)
|
21
|
-
parallel (~> 1.10)
|
22
|
-
parser (>= 3.2.0.0)
|
23
|
-
rainbow (>= 2.2.2, < 4.0)
|
24
|
-
regexp_parser (>= 1.8, < 3.0)
|
25
|
-
rexml (>= 3.2.5, < 4.0)
|
26
|
-
rubocop-ast (>= 1.28.0, < 2.0)
|
27
|
-
ruby-progressbar (~> 1.7)
|
28
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
29
|
-
rubocop-ast (1.28.1)
|
30
|
-
parser (>= 3.2.1.0)
|
31
|
-
rubocop-rake (0.6.0)
|
32
|
-
rubocop (~> 1.0)
|
33
|
-
ruby-progressbar (1.13.0)
|
34
|
-
sqlite3 (1.6.2-aarch64-linux)
|
35
|
-
sqlite3 (1.6.2-x86_64-linux)
|
36
|
-
unicode-display_width (2.4.2)
|
37
|
-
|
38
|
-
PLATFORMS
|
39
|
-
aarch64-linux
|
40
|
-
x86_64-linux
|
41
|
-
|
42
|
-
DEPENDENCIES
|
43
|
-
jekyll-sqlite!
|
44
|
-
rake (~> 13.0)
|
45
|
-
rubocop (~> 1.21)
|
46
|
-
rubocop-rake (~> 0.6.0)
|
47
|
-
|
48
|
-
BUNDLED WITH
|
49
|
-
2.4.1
|