https://github.com/michaelcurrin/jekyll-keys-filter
A light copy-and-paste Jekyll plugin to get keys from a hash
https://github.com/michaelcurrin/jekyll-keys-filter
jekyll jekyll-plugin ruby static-site
Last synced: 8 months ago
JSON representation
A light copy-and-paste Jekyll plugin to get keys from a hash
- Host: GitHub
- URL: https://github.com/michaelcurrin/jekyll-keys-filter
- Owner: MichaelCurrin
- License: isc
- Created: 2020-03-31T09:28:43.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-11T14:42:12.000Z (about 5 years ago)
- Last Synced: 2025-02-01T17:11:13.250Z (over 1 year ago)
- Topics: jekyll, jekyll-plugin, ruby, static-site
- Language: Ruby
- Homepage:
- Size: 24.4 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jekyll Keys Filter
> A light copy-and-paste Jekyll plugin to get keys from a hash
[](https://ruby-lang.org)
[](#license)
This a great example of using Ruby code in just a single script to create a simple Jekyll plugin.
How to use gem like this:
- Package as a Ruby gem, with a gemspec file.
- Publish to RubyGems for installation using `gem` or `bundle` commands.
- Provide instructions for installing your gem using a GitHub URL instead, using the same install commands.
- Copy the Ruby script directly to your Jekyll plugins directory - `_plugins`. Then use in your Jekyll code, or run with:
```sh
$ bundle exec ruby _plugins/script.rb
```
Note that regardless of which flow you use, custom gems outside of the standard are considered unsafe and unsupported on GitHub Pages.
## Sample usage
Jekyll templating example using a hash variable.
```liquid
{% assign my_hash = {'foo': 'bar', 'baz': 'buzz'} %}
{{ my_hash | keys | join: ', ' }}
```
Rendered content:
```
foo, baz
```
## Installation
In your Jekyll project, create a file as `_plugins/keys-filter.rb`.
Copy the contents of [keys-filter.rb](/keys-filter.rb) to it.
That plugin uses standard Ruby functionality of getting keys from a hash - it makes that available as a Jekyll filter called `keys`, as below.
## Usage
```liquid
{{ my_hash | keys }}
```
The value will be the keys as an array of strings.
```json
[ "foo", "bar", "bazz" ]
```
## Resources
- [Jekyll filter](https://jekyllrb.com/docs/liquid/filters/) docs.
- [Jekyll plugin](https://jekyllrb.com/docs/plugins/) docs, including how to write your own.
## License
Released under [ISC](/LICENSE).
Copyright for [keys-filter.rb](/keys-filter.rb) is held by [@dalenys](https://github.com/dalenys). The early commits here are by [@nemenemsrouge](https://github.com/nemenemsrouge).
All other copyright is held by [@MichaelCurrin](https://github.com/MichaelCurrin).
I forked this project so I could keep a copy of the plugin and improve its docs. The original repo was taken off of GitHub.