Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rcmdnk/jekyll-var-to-js
Plugin to transfer Octopress (Jekyll) configuration variables to JavaScript
https://github.com/rcmdnk/jekyll-var-to-js
Last synced: about 1 month ago
JSON representation
Plugin to transfer Octopress (Jekyll) configuration variables to JavaScript
- Host: GitHub
- URL: https://github.com/rcmdnk/jekyll-var-to-js
- Owner: rcmdnk
- License: mit
- Created: 2015-02-16T13:26:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-06-21T03:11:18.000Z (over 2 years ago)
- Last Synced: 2024-05-01T12:24:42.827Z (7 months ago)
- Language: Ruby
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.1. Add following line at the top of `` section in **source/_includes/head.html**.
```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:```yaml
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:
```html
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://example.com",title:"My Octopress Blog",author:"Your Name",};
jekyll_var["page"]={title:"hoge",};```
`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:
```javascript
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:```javascript
if(! "jekyll_var" in window){
var title = jekyll_var("title", "page")||"TITLE";
}
```