# Unit testing to check if all markdown variables are set

**URL:** <https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523>\
**Category:** Help\
**Created:** [January 20, 2021, 9:57am UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523 "2021-01-20T09:57:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![giraffe](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@giraffe](https://talk.jekyllrb.com/u/giraffe)\
**Post date:** [January 20, 2021, 9:57am UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/1 "2021-01-20T09:57:56Z")

</div>

I’m looking for a way to do unit testing on a jekyll site. I want to check if the users are filling in all the variables in the markdown. For example title, category etc. If they have not included all info needed in the markdown I want to block the possibility to merge the content into production. Anyone who has done something similar or if there are any built in functionality that I can use?

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [January 20, 2021, 10:53am UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/2 "2021-01-20T10:53:54Z")

</div>

Jekyll already supports Liquid options to prevent invalid Liquid code that might otherwise be quietly deployed

```auto
liquid:
  error_mode: strict
  strict_variables: true
  strict_filters: true

```

> **[Liquid options](https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/jekyll/configuration/liquid-options.html)**
>
> A collection of code snippets and CLI guides for quick and easy reference while coding

---

<div class="post-metadata">

**Author:** ![AlfredoRamos](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/alfredoramos/32/3815_2.png) [@AlfredoRamos](https://talk.jekyllrb.com/u/AlfredoRamos)\
**Post date:** [January 20, 2021, 9:30pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/3 "2021-01-20T21:30:04Z")

</div>

Thanks for sharing @MichaelCurrin I didn’t know about those options, and I actually found some issues on my sites.

@giraffe You could also pass the flag `--strict_front_matter` when building your site:

```shell
bundle exec jekyll build --strict_front_matter --trace

```

From the docs:

> `--strict_front_matter` Fail if errors are present in front matter

More info:

```shell
bundle exec jekyll help build

```

> **[Configuration Options](https://jekyllrb.com/docs/configuration/options/#build-command-options)**
>
> The tables below list the available settings for Jekyll, and the various options (specified in the configuration file) and flags (specified on the command-line) that control them.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [January 20, 2021, 10:19pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/4 "2021-01-20T22:19:16Z")

</div>

Thanks. I’ve added to my notes and set strict\_front\_matter on one of my sites now.

---

<div class="post-metadata">

**Author:** ![mslinn](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mslinn/32/2813_2.png) [@mslinn](https://talk.jekyllrb.com/u/mslinn)\
**Post date:** [February 1, 2021, 3:07pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/5 "2021-02-01T15:07:37Z")

</div>

@MichaelCurrin I just tried `strict_variables: true` for the first time and discovered it does not know about the `default` filter. For example, it erroneously flags this as an error:

```auto
{% assign headerImage = layout.headerImage | default: page.headerImage | default: "/assets/images/arrowHead.webp" %}

```

Also, `strict_filters: true` erroneously reports the Jekyll `slugize` filter as missing when it is used properly.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [February 1, 2021, 3:26pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/6 "2021-02-01T15:26:05Z")

</div>

Yeah it is too strict.

If you use default then you can do without strict variable for those sections.  
Or you need to actually set the value even empty.

E.g. use defaults in config to set

```auto
headerImage: nil

```

Or maybe `''`. Then it is set as a variable but then default should see it as empty and replace it.

Do you mean `slugify` not `slugize` ? That sounds like strict filter is doing its job to alert you.

See bottom of string filters list

> **[All filters](https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/jekyll/liquid/all-filters.html)**
>
> A collection of code snippets and CLI guides for quick and easy reference while coding

---

<div class="post-metadata">

**Author:** ![mslinn](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mslinn/32/2813_2.png) [@mslinn](https://talk.jekyllrb.com/u/mslinn)\
**Post date:** [February 1, 2021, 3:29pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/7 "2021-02-01T15:29:26Z")

</div>

Yes, `slugize` is a valid Jekyll filter that is not well known. Seems there are various categories of filters, and the Jekyll filters don’t get as much publicity/documentation. See [How do I shuffle the order of an array in Jekyll?](https://www.xspdf.com/resolution/59833695.html)

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [February 1, 2021, 3:43pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/8 "2021-02-01T15:43:32Z")

</div>

Can you share where you found slugize and what it does?

It appears zero times on a code search in Jekyll repo but slugify is well covered

I also tried slugize locally on Jekyll 3.9 and it did nothing.

It does appear on some stackoverflow questions so maybe it’s deprecated

---

<div class="post-metadata">

**Author:** ![mslinn](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mslinn/32/2813_2.png) [@mslinn](https://talk.jekyllrb.com/u/mslinn)\
**Post date:** [February 1, 2021, 4:07pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/9 "2021-02-01T16:07:36Z")

</div>

The page I linked to says this:

## Jekyll slugize

**Liquid,** Jekyll uses the Liquid templating language to process templates. Generally in Liquid you output content using two curly braces e.g. {{ variable }} and perform Liquid Filters. All of the standard Liquid filters are supported (see below)… To make common tasks easier, Jekyll even adds a few handy filters of its own, all of which you can find on this page.

**Liquid Filters,** To make common tasks easier, Jekyll even adds a few handy filters of its own, all of which you can find on this page. You can also create your own filters using Liquid. Jekyll uses the Liquid templating language to process templates… Generally in Liquid you output content using two curly braces e.g. {{ variable }} and perform logic statements by surrounding them in a curly brace percentage sign e.g. {% if statement %}.

**Jekyll, show category for a single post,** already loop over the array: {% for category in page.categories %} {{ category }} {% endfor %}. Jekyll 4.0 started allowing themes to bundle a \_config.yml to simplify theme-onboarding for new users. In the unfortunate situation that importing a bundled theme configuration messes up the merged site-configuration, the user can configure Jekyll to not import the theme-config entirely. ignore\_theme\_config: BOOL. Exclude"

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [February 2, 2021, 1:34pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/10 "2021-02-02T13:34:31Z")

</div>

Please check your comment after posting.

> `{{ category }}`

The snippet you posted hides the crucial slugize bit as the forum formatted it.

Please use code ticks

````
```
Copied HTML code
```

````

This is what you meant I think

```auto
Jekyll, show category for a single post, already loop over the array: 
{% for category in page.categories %}
 <a href="/​blog/{{ category | slugize }}/">
 {{ category }} </a>

```

Again, I think that article may be outdated or a mistake for reasons in my previous comment. Slugize does nothing for me in standard Jekyll so rejecting it with strict rule sounds fair.

---

<div class="post-metadata">

**Author:** ![mslinn](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mslinn/32/2813_2.png) [@mslinn](https://talk.jekyllrb.com/u/mslinn)\
**Post date:** [February 2, 2021, 2:04pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/11 "2021-02-02T14:04:20Z")

</div>

Please just refer the article I linked to. Maybe someone else will have additional information. That is all I have at present.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [February 2, 2021, 2:12pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/12 "2021-02-02T14:12:42Z")

</div>

The article only uses slugize as in the snippet I copied from the article. It doesn’t explain it further besides using Slugize in a heading. Maybe they have it as a plugin they never mentioned.

So I would not trust the source. Trust the Liquid docs and Jekyll docs.

Can you use slugize locally or on a site to display that it does indeed work for you.

e.g. with a screenshot of output or link to a GH pages site where you use it

Otherwise just use `slugify` because that _does_ work by default and _is_ covered in the docs.

---

<div class="post-metadata">

**Author:** ![mslinn](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mslinn/32/2813_2.png) [@mslinn](https://talk.jekyllrb.com/u/mslinn)\
**Post date:** [February 9, 2021, 1:07pm UTC](https://talk.jekyllrb.com/t/unit-testing-to-check-if-all-markdown-variables-are-set/5523/13 "2021-02-09T13:07:14Z")

</div>

This page shows Jekyll-specific tags, including Slugify:

> **[Liquid Filters](https://jekyllrb.com/docs/liquid/filters/)**
>
> All of the standard Liquid filters are supported (see below).
