Skip to content

Support hidden posts#2866

Closed
GiovanH wants to merge 7 commits into
getpelican:masterfrom
GiovanH:hidden-posts
Closed

Support hidden posts#2866
GiovanH wants to merge 7 commits into
getpelican:masterfrom
GiovanH:hidden-posts

Conversation

@GiovanH
Copy link
Copy Markdown
Contributor

@GiovanH GiovanH commented Apr 17, 2021

Pull Request Checklist

Resolves: #1965

  • Ensured tests pass and (if applicable) updated functional test output
  • Conformed to code style guidelines by running appropriate linting tools
  • Added tests for changed code
  • Updated documentation for changed code

This adds hidden_articles and hidden_translations to the article generator, as described in #1965 and #2865. There are some very basic test cases, including test cases for drafts.

@GiovanH GiovanH marked this pull request as ready for review April 17, 2021 01:50
@justinmayer justinmayer requested review from avaris and oulenz April 19, 2021 05:55
Copy link
Copy Markdown
Member

@avaris avaris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Left some minor comments.

Comment thread docs/content.rst Outdated
Comment thread pelican/generators.py
Copy link
Copy Markdown
Contributor Author

@GiovanH GiovanH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avaris Updated the documentation so the file is outdated now but let me know which way you want to go on the wording.

I think "output" is technically acceptable here, but we can definitely change it to "outputted" for consistency. Up to you!

Comment thread docs/content.rst Outdated
Copy link
Copy Markdown
Member

@avaris avaris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Copy link
Copy Markdown
Contributor

@oulenz oulenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for implementing this!

@minchinweb
Copy link
Copy Markdown
Contributor

minchinweb commented May 3, 2021

This is cool; this is a feature I would see myself making use of.

Out of curiosity, what happens to a category page if all the entries in it are hidden? Would the category still be listed on the "Categories" page?

And the same question for labels, authors, archives, and period archive pages.


Also, when working on a theme/in the templating engine, is there a (easy) way to get a list of all articles, including the hidden ones? (something like dates). Here is the usecase I'm imagining:

  • I generate a near-daily hidden post of my travels (rendered by a separate, to-be-written plugin). Included is a map overview.
  • on the daily archive page, at the top, I include the map overview image, with a link to the (hidden) post with more details. So I need the daily archive page to be generated, even if all the posts on that day are hidden.
  • from my list of period archive pages, I want to be able to a link the sub-period archive pages, including ones that only have hidden posts on them.

For reference, this is the current code that I'm using to generate links to the period archive pages (with similar loops for monthly and daily links): https://github.com/MinchinWeb/seafoam/blob/archive-periods/seafoam/templates/period_archives.html#L71..L147

{# Top Row with links to Archives by Year #}
<div class="archives-quicklinks text-center col-xs-12">
    {% for article in dates %}
        {% if loop.index0 == 0 or (article.date.year != dates[loop.index0 - 1].date.year) %}
            {% if loop.index0 != 0 %} &bull; {% endif -%}
            {%- if article.date.year == period[0] and period | length == 1 -%}
                <span class="active">{{ article.date.year }}</span>
            {%- else -%}
                <a href=
                    {%- if YEAR_ARCHIVE_URL -%}
                        "{{ SITEURL -}} /
                            {{- article.date | merge_date_url (YEAR_ARCHIVE_URL) }}"
                    {%- else -%}
                        "{{ SITEURL -}} / {{- ARCHIVES_URL | default('archives.html') -}}
                            #{{ article.date.year }}"
                    {%- endif -%}
                >
                    {{- article.date.year -}}
                </a>
            {%- endif -%}
        {%- endif -%}
    {%- endfor %}
</div>

The above relies on dates, which will only include non-hidden posts, so I'd need to adjust that variable somehow.

Thanks for your help!

@GiovanH
Copy link
Copy Markdown
Contributor Author

GiovanH commented May 3, 2021

Out of curiosity, what happens to a category page if all the entries in it are hidden? Would the category still be listed on the "Categories" page?

And the same question for labels, authors, archives, and period archive pages.

The behavior here would be the the same as with draft posts: drafts and hidden posts are not automatically added to those indexes, so if the only posts that use a category/tag/author is a draft (or hidden), that category index page wouldn't be generated.

Also, when working on a theme/in the templating engine, is there a (easy) way to get a list of all articles, including the hidden ones? (something like dates).

There's not a built-in variable for "published articles and drafts by date" or "published articles and hidden articles by date", but it should be fairly easy to write the equivalent in pure jinja. If this is something your site does regularly it should be fairly easy for the user to write an extra list like dates_all that's just defined inline in pelicanconf.

Copy link
Copy Markdown
Member

@justinmayer justinmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made two minor reST-formatting suggestions. Other than that, I think this ready to go! 💫

Comment thread docs/content.rst
metadata to include ``Status: published``.

Hidden posts
=================
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps shorten this header underline to match the length of the header text above it?

Comment thread docs/content.rst
=================

Like pages, posts can also be marked as ``hidden`` with the ``Status: hidden``
attribute. Hidden posts will be output to `ARTICLE_SAVE_AS` as expected, but
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`ARTICLE_SAVE_AS` → ``ARTICLE_SAVE_AS``

@minchinweb
Copy link
Copy Markdown
Contributor

so if the only posts that use a category/tag/author is a draft (or hidden), that category index page wouldn't be generated.

Is there currently a way to generate these index pages? I suppose these pages (by default) would be empty, but in theory, they would also be hidden. In any case, this (generating these index pages) isn't something I think I can do from Jinja.

(If that's not something you want to tackle, that's fine, but any tips on how to implement it myself would be appreciated.)

There's not a built-in variable for "published articles and drafts by date" or "published articles and hidden articles by date", but it should be fairly easy to write the equivalent in pure jinja. If this is something your site does regularly it should be fairly easy for the user to write an extra list like dates_all that's just defined inline in pelicanconf.

A built in variable was what I was hoping for. I could probably put something together as a Jinja Filter if it came to that. The inline entry in pelicanconf.py is an interesting idea, one that I hasn't considered before; it does make packaging and installing my theme more involved, but perhaps it's worth the tradeoff.

Thanks for your explanation.

@justinmayer
Copy link
Copy Markdown
Member

Manually merged via add3628. Will issue a release soon containing this new feature. Many thanks to @GiovanH for the enhancement and to @oulenz, @avaris, and @minchinweb for reviewing. 🥇

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 this pull request may close these issues.

Hidden status for articles

5 participants