Skip to content

Plugin to transfer Octopress (Jekyll) configuration variables to JavaScript

License

Notifications You must be signed in to change notification settings

shua123/jekyll-var-to-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jekyll-var-to-js

Plugin to transfer Octopress (Jekyll) configuration variables to JavaScript

Installation at Octopress

  1. Copy plugins/footnote_inline to your plugins directory.

  2. Add following line at the top of <head> section in source/_includes/head.html.

{{if page.jekyll_var}}{{page.jekyll_var}}{{endif%}}

Configuration

If you don't have jekyll_var configuration in your _config.yml, this plugin transfers all configuration variables of site and page to JavaScript.

If you want to pass only selected variables, use jekyll_var: include/exclude, like:

jekyll_var:
  include:
    - title
    - url
    - author
    - lang
  exclude:
    - lang

If you have include, only listed variables are transfered. If you have exclude, the variable is not transfered.

How it works

The plugin produce a script like:

<script>
  jekyll_var = function(i,j=null){
    if(j!="page" && i in jekyll_var.site)return jekyll_var.site[i];
    else if(j!="site" && i in jekyll_var.page)return jekyll_var.page[i];
    else return null;
  };
  jekyll_var["site"]={url:"http://yoursite.com",title:"My Octopress Blog",author:"Your Name",};
  jekyll_var["page"]={title:"hoge",};
</script>

site related variables (defined in _config.yml) are stored in jekyll_var["site"], and page related variables (defined in such YAML block) are stored in jekyll_var["page"].

Note: Some variables, such page.url, can not be used as it seems these variables are stored after Generator plugins.

Usage

From your scripts, use like:

if(! "jekyll_var" in window){
  var author = jekyll_var("author")||"AUTHOR";
}

jekyll_var(arg) searches corresponding variables first from jekyll_var["site"], then from jekyll_var["page"]. If nothing is found, null is returned.

If you want the variable of page (such a title in above example), call with page as the second argument:

if(! "jekyll_var" in window){
  var title = jekyll_var("title", "page")||"TITLE";
}

About

Plugin to transfer Octopress (Jekyll) configuration variables to JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%