Skip to content

Conversation

tyxchen
Copy link

@tyxchen tyxchen commented Jul 25, 2017

In one of my projects, we found that if a page parsed by jekyll-asciidoc inside a collection has a category added to it, that category will not be picked up by liquid filters such as group_by. For example, given the following front-matter:

_test_collection/index.adoc

---
category: test
---

and the following Liquid code:

{% assign objects = site.test_collection | group_by: "category" %}

objects will have a nil value. This pull request fixes that by not deleting the category and tag properties when merging them into categories and tags, respectively.

@tyxchen tyxchen changed the title Don't delete category and tag properties when merging them into categories and tags, repsectively Don't delete category and tag properties when merging them into categories and tags, respectively Jul 28, 2017
@mojavelinux
Copy link
Member

The category property is being deleted because it's treated as deprecated. A page can have multiple categories, so the plugin fixes this for you by promoting it to the categories array.

However, I can see how this can be limiting if you want to use it for grouping the collection. In theory, it should be possible to use the first category from the categories array for this purpose:

{% assign objects = site.test_collection | group_by: "categories[0]" %}

However, there seems to be a bug in Jekyll that is preventing this expression from working.

Here's what I'd be willing to do. Instead of deleting the category property, I'll just synchronize it with the first entry in the categories collection (which would effectively leave it untouched if it's defined in your example).

I'll update the PR and also add a test.

mojavelinux added a commit to mojavelinux/jekyll-asciidoc that referenced this pull request Oct 2, 2017
- add singular property to from of array instead of end
- instead of deleting category and tag properties, sync them w/ first
  entry in matching property array
@mojavelinux mojavelinux added this to the v2.1.1 milestone Oct 2, 2017
@mojavelinux mojavelinux self-assigned this Oct 2, 2017
@mojavelinux
Copy link
Member

I also changed the code to prepend the singular entry instead of appending it.

Let me know if PR #168 works for you.

@tyxchen
Copy link
Author

tyxchen commented Oct 3, 2017

@mojavelinux The code looks like it should work. Thanks so much!

Regarding using the first entry in the categories array in group_by, I believe Jekyll only supports using a name for the property to group, so it wouldn't recognize array indices, etc. Hope that helps.

@mojavelinux
Copy link
Member

Regarding using the first entry in the categories array in group_by, I believe Jekyll only supports using a name for the property to group, so it wouldn't recognize array indices, etc.

Exactly my observation. I still consider this a bug in Jekyll because I think it should be possible. Liquid has a syntax for it. It's just that Jekyll is just not interpreting it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants