# Post.data\['slug'\] is… not slugified?

**URL:** <https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767>\
**Category:** Help\
**Created:** [July 25, 2020, 7:05pm UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767 "2020-07-25T19:05:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BorisAnthony](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/borisanthony/32/2701_2.png) [@BorisAnthony](https://talk.jekyllrb.com/u/BorisAnthony)\
**Post date:** [July 25, 2020, 7:05pm UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/1 "2020-07-25T19:05:13Z")

</div>

Hi.  
I am trying to connect some stuff up in a template, hoping to match on a post’s slug. Tried so many things to no avail until I finally decided to dump the post.data and to my dismay…

```
"title": "A Second Note",
"permalink": "/notes/:year/:month/:day/:slug",
"slug": "A Second Note",

```

The permalink and all links all work and are slugified properly… but for some reason in the data it’s untouched. I was of course expecting:

`"slug": "a-second-note",`

Kinda scratching my head here… why would this be?  
And more importantly, how to fix it?

Thanks!

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [July 25, 2020, 8:11pm UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/2 "2020-07-25T20:11:41Z")

</div>

The `permalink` and `slug` are combined to form the `url` property. So `page.url` should contain something like: `/notes/2020/7/24/a-second-note`

---

<div class="post-metadata">

**Author:** ![BorisAnthony](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/borisanthony/32/2701_2.png) [@BorisAnthony](https://talk.jekyllrb.com/u/BorisAnthony)\
**Post date:** [July 25, 2020, 8:15pm UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/3 "2020-07-25T20:15:53Z")

</div>

Thanks @chuckhoupt  
Except, the `.slug` is not slugified, and the `.url` isn’t something I can match my string against.

I suppose I can write Liquid code to parse the `.url`, but `.slug` should be, you know, the slug. No? 🙂

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [July 25, 2020, 8:49pm UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/4 "2020-07-25T20:49:54Z")

</div>

Are you explicitly setting the slug in the post’s front-matter? When slug is explicitly set in the front-matter, Jekyll won’t overwrite it.

Normally, `.slug` is ~~generated by feeding the title thru the `sluggify` filter~~ [correction: it’s base on file name], but if a slug is found in the front-matter, then it will be used instead of the title (but still fed thru the `sluggify` filter, just in case it isn’t properly formatted).

Ideally, an explicitly set slug should be a correctly formatted URL component (i.e. “a-second-note”). However, to auto-correct errors, Jekyll applies the `sluggify` filter to ensure consistent URLs. So a slug like “A Second Note” will appear in the URL as “a-second-note”.

You might be able to use the `sluggify` filter to help with matching…

---

<div class="post-metadata">

**Author:** ![BorisAnthony](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/borisanthony/32/2701_2.png) [@BorisAnthony](https://talk.jekyllrb.com/u/BorisAnthony)\
**Post date:** [July 25, 2020, 8:52pm UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/5 "2020-07-25T20:52:10Z")

</div>

Thanks again @chuckhoupt

I am not setting the slug in the front matter.  
I was totally expecting the Jekyll-generated slug in the data struct to be slugified but it is not. Perhaps a config issue?  
(I am running latest Jekyll)

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [July 25, 2020, 9:12pm UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/6 "2020-07-25T21:12:16Z")

</div>

Odd, when I eval the slug in Liquid, I always get the generated slug. For example: `{{ site.posts[0].slug }}` or `{{ page.slug }}` will eval to “welcome-to-jekyll” in a freshly created Jekyll site (4.1.1).

You mention `Post.data['slug']`, but I don’t recognize that as Liquid. Maybe you’re writing a Ruby plugin? That might explain the confusion.

---

<div class="post-metadata">

**Author:** ![BorisAnthony](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/borisanthony/32/2701_2.png) [@BorisAnthony](https://talk.jekyllrb.com/u/BorisAnthony)\
**Post date:** [July 26, 2020, 7:21am UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/7 "2020-07-26T07:21:45Z")

</div>

Aha ok mystery.  
Definitely in a template.  
Right after `<body>` I insert  
`Page Slug: {{ page.slug }}`  
and I get:  
`Page Slug: A First Note`  
( at localhost/2020/07/26/a-first-note )

---

<div class="post-metadata">

**Author:** ![BorisAnthony](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/borisanthony/32/2701_2.png) [@BorisAnthony](https://talk.jekyllrb.com/u/BorisAnthony)\
**Post date:** [July 26, 2020, 7:30am UTC](https://talk.jekyllrb.com/t/post-data-slug-is-not-slugified/4767/8 "2020-07-26T07:30:16Z")

</div>

Ok so I installed a clean test site and here’s what I found.

`page.slug` is _not_ the title slugified. It is a straight copy of the source filename. (In the case of posts, it strips the date, which is ignored anyways if the front matter has a date… weird behavior as well.)

So, a source filename like  
`_posts/2020-07-20-A First Post.md`  
will give a slug of  
`A First Post`  
regardless of what is or isn’t in the front matter.

Only a source filename like  
`_posts/2020-07-20-a-first-post.md`  
will give a slug of  
`a-first-post`

Very surprising and disappointing. Users don’t write slugs, they write titles. But the system can use and rely on “automatically slugified” titles, and this behavior breaks that potential.

I wonder if this is a bug?

Guess I’ll be parsing page.url in Liquid:  
`{%- assign realslug = page.url | split:'/' | last -%}`  
`<pre>Post URL : {{ page.url }}</pre>`  
`<pre>Real Slug: {{ realslug }}</pre>`

Edit: So this doesn’t solve my particular problem as I am querying the `post` data which needs a real slug to be present there to work. Maybe I need to write a plugin to push that in.

Anyways, thank you @chuckhoupt for your help! 👍
