Path: blob/main/_plugins/jekyll-environment_variables.rb
1677 views
# frozen_string_literal: true12# Plugin to add environment variables to the `site` object in Liquid templates3require 'date'4require 'time'5require './_plugins/gtn/scholar'6require './_plugins/gtn/git'78module Jekyll9module Generators10# This module contains a generator for adding environment variables to the `site` object in Liquid templates11# TODO: definitely could be a hook instead of a generator12class EnvironmentVariablesGenerator < Generator13##14# Environment variables are added to the `site` object in Liquid templates.15# Here we add the following:16# - `site.config['git_revision']` - the current git revision17# - `site.config['git_tags']` - an array of all git tags18# - `site.config['git_tags_recent']` - an array of the 3 most recent git tags19# - `site.config['gtn_fork']` - the fork of the GTN repo20# - `site.config['age']` - the age of the site in years21def generate(site)22# Add other environment variables to `site.config` here...23Gtn::Scholar.load_bib(site)24site.config.update(Gtn::Git.discover)2526site.data['build'] = {27'today' => Date.today,28'now' => Time.now,29'jekyll' => {30'version' => Jekyll::VERSION,31'environment' => Jekyll.env,32}33}34end35end36end37end383940