Skip to content

Instantly share code, notes, and snippets.

@captn3m0
Created May 8, 2023 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captn3m0/567427844ce05ead7cc3b22887f72bb0 to your computer and use it in GitHub Desktop.
Save captn3m0/567427844ce05ead7cc3b22887f72bb0 to your computer and use it in GitHub Desktop.
Jekyll Sqlite Plugin
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