Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/_plugins/jekyll-environment_variables.rb
1677 views
1
# frozen_string_literal: true
2
3
# Plugin to add environment variables to the `site` object in Liquid templates
4
require 'date'
5
require 'time'
6
require './_plugins/gtn/scholar'
7
require './_plugins/gtn/git'
8
9
module Jekyll
10
module Generators
11
# This module contains a generator for adding environment variables to the `site` object in Liquid templates
12
# TODO: definitely could be a hook instead of a generator
13
class EnvironmentVariablesGenerator < Generator
14
##
15
# Environment variables are added to the `site` object in Liquid templates.
16
# Here we add the following:
17
# - `site.config['git_revision']` - the current git revision
18
# - `site.config['git_tags']` - an array of all git tags
19
# - `site.config['git_tags_recent']` - an array of the 3 most recent git tags
20
# - `site.config['gtn_fork']` - the fork of the GTN repo
21
# - `site.config['age']` - the age of the site in years
22
def generate(site)
23
# Add other environment variables to `site.config` here...
24
Gtn::Scholar.load_bib(site)
25
site.config.update(Gtn::Git.discover)
26
27
site.data['build'] = {
28
'today' => Date.today,
29
'now' => Time.now,
30
'jekyll' => {
31
'version' => Jekyll::VERSION,
32
'environment' => Jekyll.env,
33
}
34
}
35
end
36
end
37
end
38
end
39
40