https://github.com/allejo/jekyll-yamlify
:construction: A GitHub Pages compatible way of introducing pretty printing YAML in your Jekyll site
https://github.com/allejo/jekyll-yamlify
Last synced: 3 months ago
JSON representation
:construction: A GitHub Pages compatible way of introducing pretty printing YAML in your Jekyll site
- Host: GitHub
- URL: https://github.com/allejo/jekyll-yamlify
- Owner: allejo
- License: mit
- Created: 2023-06-23T00:45:03.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-23T23:04:10.000Z (almost 2 years ago)
- Last Synced: 2025-01-15T03:05:16.090Z (5 months ago)
- Language: Liquid
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Jekyll Pure Liquid YAMLify
[](/actions?query=workflow%3A%22Unit+Tests%22)
[](/releases/latest)
[](https://ko-fi.com/Q5Q4J7IX)
[](https://www.buymeacoffee.com/allejo)GitHub Pages can't run Jekyll plug-ins and Jekyll, nor Liquid, have built-in filters to pretty print YAML. For theme authors, if you want to share any YAML from your `_config.yaml`, to document theme settings, you are stuck with having to copy/paste the YAML. These changes do not stay in sync with your `_config.yml` for obvious reasons if you're copy and pasting.
As part of my Pure Liquid project, I wrote this solution entirely in Liquid to pretty print YAML via an `{% include %}` snippet.
## Usage
Alright, so how do you use it?
1. Download the `yamlify.html` file from [the latest release](/releases/latest) or [the main branch](_includes/yamlify.html)
2. Toss that file in your `_includes` folder
3. Now, whenever you want to pretty print an object as YAML, you can use this include like so,```liquid
{% include yamlify.html key="yaml_demo" value=site.yaml_demo %}
```and this will output something along the lines of,
```yaml
yaml_demo:
my-string: "Hello world"
my-boolean: true
my-date: "2020-03-14"
my-number: 12345
my-str-array:
- "apple"
- "orange"
- "pear"
my-colors:
red: "#f00"
green: "#0f0"
blue: "#00f"
```## Parameters
This snippet is highly customizable. Here are the available parameters to change the behavior of the snippet.
| Parameter | Type | Default | Description |
| -------------- | :----: | :-----: | ----------- |
| `value` | any | * | any YAML-compatible value that will be written out as prettified YAML |
| `key` | string | '' | a top-level YAML key to use when printing out the given value |
| `include_path` | string | 'yamilfy.html' | the relative path to this include; use this is you rename the include or put it subfolders |
| `indent_chars` | string | ' ' | the indentation that will be used for each line |
| `indent_count` | int | 1 | the amount of times a given value needs to be indented when written |* This is a required parameter
## Performance
The performance impact of this snippet on your site is pretty negligible. The stats below were gotten from Jekyll's `--profile` option.
```
Filename | Count | Bytes | Time
-------------------------------------------------+-------+----------+------```
## License
This snippet may be redistributed under the [MIT](LICENSE.md) license.