jekyll-sqlite 0.2.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b968c4b7df9bfd1fbe127a29743b8a9ddc823b7db6438975621b63e7307e26f7
4
- data.tar.gz: 8906f3acfec3fedf578755563953d2c5563f49cac45a4bb24b77d32ba2899d97
3
+ metadata.gz: fa7d86717dfe79612ee35243b63627985935dcabab7a6160462b78ef9a5fd171
4
+ data.tar.gz: 7209f11ebb87f143fb410f5944d503c879e6164bdefbb2e1b47bf94f41a0c833
5
5
  SHA512:
6
- metadata.gz: a9d02570d9db93418a10958a727917b2c37f56a5d4995185e9dfed857c7fabc2315c51229b59b9ec9c193de4dd5184bea067bbb16cfcb245096f167ec70af476
7
- data.tar.gz: 53599208a2c848d8ca4cce454184d2da3d434f20f952d7b882a5b68c852934746885d586ed98544e2db9428ff9d018fb597ae17dc1420384d69f449b811fddd4
6
+ metadata.gz: 3d98916c7419f2c47a68958f599ad359d7640746074b4b9f9dd80a5240d2449b269aec75d056a962e3ecc87c06f281c7c38d7952e076e3494debdf3d53c57a0d
7
+ data.tar.gz: 7d60022fa371cae213eb56e4e366106d5a6b5fe709c252e4503bfea73e46bee1997acf8259aa2bf5324af2bef9bbb1a04df5e98de872318a135a8dc508aa9abd
data/CHANGELOG.md CHANGED
@@ -10,6 +10,9 @@ 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
+
13
16
  ## [0.2.1] - 2026-01-03
14
17
  - Only passes named parameters in SQLite query. Requires sqlite3-ruby 2.9.0
15
18
 
@@ -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
@@ -59,12 +61,14 @@ module JekyllSQlite
59
61
  end
60
62
 
61
63
  ##
62
- # 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.
63
67
  def valid_config?(config)
64
68
  return false unless config.is_a? Hash
65
69
  return false unless config.key?("query")
66
- return false unless File.exist?(config["file"])
67
- 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")
68
72
 
69
73
  true
70
74
  end
@@ -101,14 +105,71 @@ module JekyllSQlite
101
105
  Jekyll.logger.error "Jekyll SQLite:", "Invalid Configuration. Skipping"
102
106
  next
103
107
  end
104
- generate_data_from_config(root, config)
108
+
109
+ if config["collection"]
110
+ generate_collection_from_config(config)
111
+ else
112
+ generate_data_from_config(root, config)
113
+ end
114
+ end
115
+ end
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
105
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
106
166
  end
107
167
 
108
168
  ##
109
169
  # Entrpoint to the generator, called by Jekyll
110
170
  def generate(site)
111
171
  @db = {}
172
+ @site = site
112
173
  gen(site.data, site.config)
113
174
  site.pages.each do |page|
114
175
  gen(page.data, page)
@@ -117,4 +178,5 @@ module JekyllSQlite
117
178
  close_all_databases
118
179
  end
119
180
  end
181
+ # rubocop:enable Metrics/ClassLength
120
182
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Sqlite
5
- VERSION = "0.2.1"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  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.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nemo
@@ -29,43 +29,20 @@ 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
- - CONTRIBUTING.md
36
33
  - Gemfile
37
34
  - LICENSE
38
35
  - README.md
39
- - Rakefile
40
- - docs/.gitignore
41
- - docs/404.html
42
- - docs/CHANGELOG.md
43
- - docs/CONTRIBUTING.md
44
- - docs/Gemfile
45
- - docs/_config.yml
46
- - docs/demo.md
47
- - docs/help.md
48
- - docs/img/northwind-1.jpg
49
- - docs/img/northwind-2.jpg
50
- - docs/index.md
51
- - docs/install.md
52
- - docs/usage/datapage.md
53
- - docs/usage/dynamic.md
54
- - docs/usage/index.md
55
- - docs/usage/nested.md
56
- - docs/usage/per-page.md
57
- - docs/usage/writing-queries.md
58
- - jekyll-sqlite.gemspec
59
36
  - lib/jekyll-sqlite/generator.rb
60
37
  - lib/jekyll-sqlite/version.rb
61
38
  - lib/jekyll_sqlite.rb
62
- homepage: https://github.com/captn3m0/jekyll-sqlite
39
+ homepage: https://captnemo.in/jekyll-sqlite/
63
40
  licenses:
64
41
  - MIT
65
42
  metadata:
66
- homepage_uri: https://github.com/captn3m0/jekyll-sqlite
67
- source_code_uri: https://github.com/captn3m0/jekyll-sqlite
68
- changelog_uri: https://github.com/captn3m0/jekyll-sqlite/blob/master/CHANGELOG.md
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
69
46
  rubygems_mfa_required: 'true'
70
47
  rdoc_options: []
71
48
  require_paths:
@@ -81,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
58
  - !ruby/object:Gem::Version
82
59
  version: '0'
83
60
  requirements: []
84
- rubygems_version: 3.6.9
61
+ rubygems_version: 4.0.6
85
62
  specification_version: 4
86
63
  summary: A Jekyll plugin to use SQLite databases as a data source.
87
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/CONTRIBUTING.md DELETED
@@ -1,46 +0,0 @@
1
- ---
2
- title: Contribution Guide
3
- ---
4
-
5
- # Contributing to jekyll-sqlite
6
-
7
- **This document is a work-in-progress.**
8
-
9
- This doc is a short introduction on how to modify and maintain the sqlite3-ruby gem.
10
-
11
- ## Making a Release
12
-
13
- 0. Update `version.rb`
14
- 0. Update CHANGELOG.md
15
- 1. Run `bundle exec rake rubocop` to lint
16
- 2. Commit + push
17
- 3. If build passes, tag and push the tag.
18
-
19
- Gem publication on rubygems automatically happens via GitHub Actions.
20
-
21
- ## Running Tests
22
-
23
- `bundle exec rake test`
24
-
25
- ## Test Infrastructure
26
-
27
- The tests are maintained in `test` directory as a separate jekyll website.
28
- The site is built inside `Rakefile`, and it uses JSON output files as templates.
29
-
30
- These JSON output files can then be used for testing the plugin.
31
-
32
- ## Rubocop
33
-
34
- Linting is mandatory to pass the CI.
35
-
36
- ## Docs
37
-
38
- Docs are maintained in docs/ directory as a separate Jekyll site that uses
39
- just-the-docs theme. A few markdown files are symlinked inside docs so that
40
- they get published to the website as well.
41
-
42
- ## Demo
43
-
44
- The demo is maintained separately on another repo, but the expectation is that
45
- all important features are used in the demo. If you contribute such a change
46
- that adds a new feature, please update the demo as well.
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
@@ -1,5 +0,0 @@
1
- _site
2
- .sass-cache
3
- .jekyll-cache
4
- .jekyll-metadata
5
- vendor
data/docs/404.html DELETED
@@ -1,8 +0,0 @@
1
- ---
2
- permalink: /404.html
3
- layout: page
4
- ---
5
- <h1>404</h1>
6
-
7
- <p><strong>Page not found :(</strong></p>
8
- <p>The requested page could not be found.</p>
data/docs/CHANGELOG.md DELETED
@@ -1 +0,0 @@
1
- ../CHANGELOG.md
data/docs/CONTRIBUTING.md DELETED
@@ -1 +0,0 @@
1
- ../CONTRIBUTING.md
data/docs/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
- gem "jekyll", "~> 4.4.1"
3
- gem "just-the-docs"
4
-
5
- gem "logger", "~> 1.7"
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,30 +0,0 @@
1
- ---
2
- title: Demo
3
- ---
4
-
5
- 🏁 A fully-functional demo website that uses this plugin is available at
6
- [northwind.captnemo.in](https://northwind.captnemo.in). The source code for
7
- the demo is available at [captn3m0/northwind](https://github.com/captn3m0/northwind).
8
- You can find more details at the demo page.
9
-
10
- Here is a screenshot:
11
-
12
- ![Screenshot of https://northwind.captnemo.in/products.html](img/northwind-1.jpg)
13
-
14
- It relies on all features of the plugin, along with using `jekyll-datapage_gen`
15
- plugin to generate individual pages for each data item.
16
-
17
- 1. A [per-page query](usage/#per-page-queries) is used on the restock page to generate list of
18
- products that need to be restocked. [source](https://github.com/captn3m0/northwind/blob/main/restock.md?plain=1)
19
- 2. Customers, Orders, Products, Categories are set as global data items
20
- in [config.yml](https://github.com/captn3m0/northwind/blob/main/_config.yml)
21
- 3. `site.data.categories[*].products` is filled using a parameterised query
22
- in [`config.yml`](https://github.com/captn3m0/northwind/blob/main/_config.yml#L47-L49)
23
- 4. Featured Product and Employee of the Month, shown on homepage are set by a query
24
- in `config.yml`, but the query parameters are set in [`_data`](https://github.com/captn3m0/northwind/tree/main/_data)
25
- directory as YML files.
26
- 5. The datapage plugin config generates a page for every product and customer.
27
- 6. A multi-level nested query is used to generate a list of employees. See [Nested Query]({% link usage/nested.md %}) in docs.
28
- 7. A permalink is set for all the customers by creating a permalink attribute in the select query: `SELECT ... as permalink`. Since we are setting a top-level attribute in the final page, it cannot be set alongside `page_data_prefix` in the datapage_gen configuration. See [this commit](https://github.com/captn3m0/northwind/commit/3d70d6a81be34af5f1ebbcfa5da09a170f2ee9ff) for the implementation. I'd suggest only using this when the `dir + name/name_expr` configuration in the `datapage` plugin fall short.
29
-
30
- The database is a trimmed-version of the northwind database from <https://github.com/jpwhite3/northwind-SQLite3>.
data/docs/help.md DELETED
@@ -1,14 +0,0 @@
1
- ---
2
- title: Help
3
- ---
4
-
5
- Need help? You can file a new issue on GitHub at
6
- <https://github.com/captn3m0/jekyll-sqlite/issues/new>.
7
-
8
- This project is intended to be a safe, welcoming space for collaboration, and
9
- contributors are expected to adhere to the [code of conduct][coc].
10
-
11
- Note that only maintained versions of [Jekyll](https://endoflife.date/jekyll)
12
- and [Ruby](https://endoflife.date/ruby) are supported.
13
-
14
- [coc]: https://github.com/captn3m0/jekyll-sqlite/blob/main/CODE_OF_CONDUCT.md
Binary file
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
- [![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://rubygems.org/gems/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.
@@ -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]({% link demo.md %}).
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
- ![Product Page](../img/northwind-2.jpg)
72
-
73
- See it in action at <https://northwind.captnemo.in/products/1.html>
@@ -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]({% link demo.md %}):
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.
@@ -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
- ```
@@ -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.9.0"
31
- spec.metadata["rubygems_mfa_required"] = "true"
32
- end