Created
May 8, 2023 07:23
-
-
Save captn3m0/567427844ce05ead7cc3b22887f72bb0 to your computer and use it in GitHub Desktop.
Jekyll Sqlite Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sqlite3' | |
module SQLiteGenerator | |
class Generator < Jekyll::Generator | |
priority :high | |
def generate(site) | |
site.config['sqlite'].each do |name, config| | |
require 'pp' | |
SQLite3::Database.new config['file'] do |db| | |
Jekyll.logger.info "Jekyll SQLite:", "Starting to load #{name}" | |
db.results_as_hash = config.fetch('results_as_hash', true) | |
db.execute('PRAGMA synchronous = OFF') | |
db.execute('PRAGMA journal_mode = OFF') | |
db.execute('PRAGMA query_only = ON') | |
site.data[name] = db.execute(config['query']) | |
Jekyll.logger.info "Jekyll SQLite:", "Loaded #{name}. Count=#{site.data[name].size}" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment