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

Avoid counting draft projects and essays when displaying totals #12

Closed
philipmjohnson opened this issue Sep 26, 2023 · 0 comments
Closed
Assignees

Comments

@philipmjohnson
Copy link
Contributor

@vjd3 sent me the following:

For the issue, it falls under Projects and Essays. I have resolved the issue to my satisfaction but wanted to identify and propose my solution to you for your consideration in case there are any aspects of your design for which I am not considering.

In your code (files essays.html and projects.html under _includes), you allow for the "draft" designation. This is a powerful feature, allowing us to create the pages before publishing them. However, in those HTML files, the premise under which the display limit is used does not take into account the draft status. While you do have the unless clause to prevent the draft page from being shown, it is still being counted, and therefore causes the displayed number of items and the total count to be incorrectly handled. By using the forloop.index and the essay_pages.size for the total counts, you are assuming that all pages in the folder will be displayed. For example, if I have 7 pages, of which 5 are draft and the drafts are the newer dated pages, the include loop may exit before it gets to the pages that can be displayed. Additionally, the link to see the full list of pages shows a count of 7 in this case, where it should be 2 with all displayed and no link necessary.

I propose (and have tested and used this on my pages vjd3.github.io adding a separate counter to be used to determine how many are to be shown and another counter for the total count of pages.

Sample resolution:

<div class="row g-3">
      {% assign essay_pages = site.pages | where: "type", "essay" | sort: "date" | reverse %}
      {% assign my_counter = 0 %}
      {% for page in essay_pages %}
        {% unless page.draft %}
          {% assign my_counter = my_counter | plus: 1 %}
          {% include essays/essay-card.html page=page %}
        {% endunless %}
        {% if my_counter == include.limit %}
          {% break %}
        {% endif %}
      {% endfor %}
    </div>

    {% assign not_draft = 0 %}
    {% for page in essay_pages %}
      {% unless page.draft %}
        {% assign not_draft = not_draft | plus: 1 %}
      {% endunless %}
    {% endfor %}

    {% if not_draft > include.limit %}
      <p class="text-center pt-4"><a href="{{ site.baseurl}}/essays/">See all {{ not_draft }} essays</a></p>
    {% endif %}
@philipmjohnson philipmjohnson self-assigned this Sep 26, 2023
philipmjohnson added a commit that referenced this issue Sep 26, 2023
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

No branches or pull requests

1 participant