Created
August 27, 2012 15:44
-
-
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].
This file contains hidden or 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
# conference config | |
conferences: | |
conference1: { | |
name: Conference 1 Wow!, | |
date: Jan 1-6 2013 | |
} | |
conference2: { | |
name: Conference 2 Neato!!, | |
date: Dec 15-20 2013 | |
} |
This file contains hidden or 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
<!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 file contains hidden or 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
# 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