Skip to content
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

[frontmatter] Add helpers to gather data from collections #66

Closed
ia3andy opened this issue Aug 28, 2024 · 1 comment · Fixed by #102
Closed

[frontmatter] Add helpers to gather data from collections #66

ia3andy opened this issue Aug 28, 2024 · 1 comment · Fixed by #102

Comments

@ia3andy
Copy link
Contributor

ia3andy commented Aug 28, 2024

For example to get the list of tags and their related posts.

The goal is to create a page similar to that Jekyll one:

---
layout: main
title: Tags
permalink: /tags/
---
{% capture site_tags %}{% for tag in site.tags %}{{ tag | first }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
{% assign tag_words = site_tags | split:',' | sort %}

<section class="blog-tags">
  <h1>Tags in Blog</h1>
  <ul class="tags">
<!--  cycles through tag list and creates header row of all tags used in site with accompanying per-tag counts...-->
  {% for this_word in tag_words %}
    <li ><a href="#{{ this_word | cgi_escape }}" class="tag">{{ this_word }} <span>({{ site.tags[this_word].size }})</span></a></li>
  {% endfor %}
  </ul>
<!--cycles through tag list and creates subheader for each tag name...-->
  {% for this_word in tag_words %}
  <h2 id="{{ this_word | cgi_escape }}">{{ this_word }}</h2>
<!--  lists all posts corresponding to specific tag...-->
    {% for post in site.tags[this_word] %}{% if post.title != null %}
    <div class="tag-list">
        <span><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></span>
        <small><span>| {{ post.date | date_to_string }}</span></small>
    </div>
    {% endif %}{% endfor %}
  {% endfor %}
</section>
@ia3andy ia3andy changed the title Add collection helpers to gather data [frontmatter] Add helpers to gather data from collections Sep 2, 2024
@ia3andy
Copy link
Contributor Author

ia3andy commented Sep 20, 2024

The idea for this one would be to add find/group methods in the RoqCollection and RoqCollections, this would allow to do:

{#for tag in collections.posts.by("tags")} <!-- this would look into each posts and look for tags string or array of string and create a grouping as a Map<String, List<Page>> -->
    {tag.key} <!-- the tag name -->
    {#for post in tag.value} <!-- all the post with that tag-->
    {post.title} <!-- the post title -->
    {post.url} <!-- the post url -->

ia3andy added a commit that referenced this issue Sep 25, 2024
Fix #66: RoqCollection by and group helpers
mcruzdev pushed a commit that referenced this issue Oct 9, 2024
Fix #66: RoqCollection by and group helpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant