Skip to content

Instantly share code, notes, and snippets.

@btjones
Created August 27, 2012 15:44
Show Gist options
  • Save btjones/3489667 to your computer and use it in GitHub Desktop.
Save btjones/3489667 to your computer and use it in GitHub Desktop.
This is a Jekyll plugin that uses the file path to set a page variable. Then, we can use that page variable as a key to access directory wide config variables in _config.yml. This example uses the file structure conferences/[CONFERENCE_KEY].
# conference config
conferences:
conference1: {
name: Conference 1 Wow!,
date: Jan 1-6 2013
}
conference2: {
name: Conference 2 Neato!!,
date: Dec 15-20 2013
}
<!doctype html>
<html>
<head>
<title>{{ site.conferences[page.conference].name }}</title>
</head>
<body>
<h1>{{ site.conferences[page.conference].name }}</h1>
<h2>{{ site.conferences[page.conference].date }}</h2>
# this plugin adds the variable page.conference to every page
# it does this by grabbing the conference directory from its path
module Jekyll
class Page
def to_liquid
# remove everything before and including 'conferences/' and remove everything after the conference directory name
self.data.deep_merge({
"conference" => File.join(@dir, self.url).sub(/.*conferences\//, '').slice(/[^\/]*/)
})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment