https://github.com/cityofsantamonica/jekyll-frontmatter-jsonify
Liquid filter to jsonify your collection's frontmatter
https://github.com/cityofsantamonica/jekyll-frontmatter-jsonify
jekyll-plugin json liquid
Last synced: over 1 year ago
JSON representation
Liquid filter to jsonify your collection's frontmatter
- Host: GitHub
- URL: https://github.com/cityofsantamonica/jekyll-frontmatter-jsonify
- Owner: CityofSantaMonica
- Created: 2016-05-18T20:53:58.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-23T17:47:07.000Z (about 10 years ago)
- Last Synced: 2024-05-02T06:16:38.848Z (about 2 years ago)
- Topics: jekyll-plugin, json, liquid
- Language: Ruby
- Homepage: https://rubygems.org/gems/jekyll-frontmatter-jsonify
- Size: 7.81 KB
- Stars: 4
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jekyll Frontmatter Jsonify
## Use it
Take a look at [Jekyll's instructions for loading plugins](https://jekyllrb.com/docs/plugins/#installing-a-plugin).
```
gem install jekyll-frontmatter-jsonify
```
## The problem
The `jsonify` filter when applied to a collection will convert only the body of the collection item into a JSON array, and not the frontmatter.
For example, we have a collection with two items:
**_sample_collection/item1.md**
```
---
food: bacon
---
Sample Content from 'item1.md'
```
**_sample_collection/item2.md**
```
---
food: toast
---
Awesome content from 'item2.md'
```
### The `jsonify` filter
```
{{ site.sample_collection | jsonify }}
```
**Returns**
```
[ "Sample Content from 'item1.md'", "Awesome content from 'item2.md'" ]
```
## The solution
This plug-in introduces the `collection_jsonify` Liquid filter which will convert each collection item's frontmatter into a JSON array.
```
{{ site.sample_collection | collection_jsonify }}
```
**Returns**
```
[
{
"food": "bacon",
// Jekyll default keys
"draft": false,
"categories": [],
"ext": ".md"
},
{
"food": "toast",
// Jekyll default keys
"draft": false,
"categories": [],
"ext": ".md"
}
]
```
This filter takes a single boolean as a parameter (defaults to `false`) that will ignore Jekyll's default keys in the frontmatter and only return the custom data a collection item has in its frontmatter. In the above example, only the "food" key would be outputted if the parameter was set to true (i.e. ` | collection_jsonify: true`)
## License
MIT