New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ordering content by creation date. #68
Comments
Hey @bretmorris, Would you share the On an aside note, you can add Meta-data to your Content-Types and use that for ordering, for example, an Order numeric field, or a Featured Article boolean field are good ways to sort your entries if you need fine-grained specific ordering. Then including that in your |
Hey @dlitvakb my cda_query looked like this: f.cda_query = { content_type: 'xxxxxxxxxxx', order: 'sys.createdAt' } Ordering by createdAt, reverse createAt, publishedAt, etc. seems to have no effect on the output. Thanks!! PS, if I can't find a solution here I may do what you suggested and just add a field and attempt to order by that field. Thanks for that suggestion! |
Hey @bretmorris, Sorry it took a bit longer to answer this, but I was trying to understand what the problem was. In fact, all Add a CustomMapper that includes the After that, in your template, order like the following: <% entries = entries.to_a.sort_by{ |id, e| e['the_field_you_want_to_sort_by'] } %> Hope this helps. Please let me know if you need any further help |
@dlitvakb thank you I actually ended up coming upon a similar solution:
This seems like the sort of thing that a lot of people using contentful-middleman would need to know to build their app. I ended up getting this information from someone who had built a project with contentful-middleman before. Honestly I'm not sure how they figured it out. Do you think it's worth adding anything about this technique or a similar technique in the documentation? Thanks again for your help!!! |
Hey @bretmorris Glad it helped you. Closing the issue |
@dlitvakb Is there any scope to improve the way contentful_middleman handles this? I added an
is pretty longwinded when a sort attribute or field in the config would be really handy. |
Hey @tommotaylor, This is not possible sadly, it is a limitation of how Middleman handles data files and not related to the integration itself. While it would be possible to prepend an index to the data file name, and then middleman have it already sorted, it would remove the ability to do anything useful with the shorthand entry ID, and also would remove direct access to the entry if you don't also happen to know the index it happened to have landed with. Therefore, I consider this approach to be wrong, and much rather prefer a sort function over the collection you're trying to iterate. Cheers |
Sorry, maybe not the same question, but similar, and after spending all morning on it, this was the closest issue I could find. I'm trying to find out if employees are on a specific team, and if so, sort_by a new field I created called sort_order. Ruby is not my specialty, I muddle through due to the excellent community and documents around Middleman and Contentful. What I have so far is:
And this works. But if I want to sort by sort_order, it fails with a nil class, and the reason is that I don't have sort_order defined in every team content file. It's blank for the majority of them. I know that there is a way I can sort ONLY if they have a sort_order. @dlitvakb any ideas? |
I feel like I'm taking crazy pills here! I've looked all over the internet and cannot find a solution...
The problem:
I am using contentful to essentially create a blog. The content type I am interested in displaying and ordering is called "post". So far I have managed to pull all my posts into /data/blog/posts using the following configuration:
note: I intentionally left out the IDs and tokens
The problem is when I attempt to output those posts in my .erb file using the following:
This results in a list of post tiles (as expected) but there appears to be no order to the output. I would expect the output to be ordered by creation date by default. How can one go about adding this order or any other order for that matter?
PS, one of the problems seems to be that
data.blog.posts
is an object with post IDs as keys. That seems problematic. Thanks for your help! I'm just getting started with middleman so forgive my ignorance!The text was updated successfully, but these errors were encountered: