[solved] Hidden posts

Feature proposal

Add a new property that allows post to be hidden from discovery by any means except the direct link

Use cases

Users might want to publish a post privately if:

  • Post contains personal or sensitive data
  • Post targets a small group of people and doesn’t make sense for the rest of the internet
  • Author wants to discuss post with someone before publishing, so now the link can easily be shared

Implementation

We can introduce a new post property:

+++
...
hidden = true
...
+++

If this option is set to true, then post will NOT be listed in:

  • List of posts
  • Pagination
  • previous and next properties of neighbor pages
  • RSS feed
  • taxonomies

So, the only option to access it would be a direct link.
Such links can be printed to stdout after site generation process.

What do you think? Do you find it useful?

Why not move it out of a paginated section if it’s not meant to be in there? Eg make a hidden section that is not linked anywhere and hidden in the sitemap.
The usecase for having that inside a public section is too niche to be worth it imo

Indeed, that will cover 100% of what I need :slight_smile:
Thank you!

@keats, sorry for bumping the solved post, but suggested solution does not prevent the post being added to a generated atom feed. Maybe you have an idea how to prevent that?

You can override the feed template (https://github.com/getzola/zola/blob/master/components/templates/src/builtins/atom.xml) and just add a check to not add hidden pages to it.

I tried that, unfortunately it looks like I can’t access custom header variables (hidden = true) from the template. Nor Feeds nor Sections and Pages doc sections give details on how to access it. There is an extra variable, but is also doesn’t seem to have custom fields. Maybe you have any example in mind?

Try page.extra.hidden if it’s in the extra section

Thank you, I read that extra is a HashMap, so I was trying to do something like

page.extra['hidden']

:man_facepalming:

Well that should work in theory x) it should be equivalent to page.extra.hidden

A followup for the history sake: I ended up putting “hidden” pages inside /content/hidden and creating /templates/feed.xml with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}">
	<title>{{ config.title }}
		{%- if term %} - {{ term.name }}
		{%- endif -%}
	</title>
	{%- if config.description %}
	<subtitle>{{ config.description }}</subtitle>
	{%- endif %}
	<link href="{{ feed_url | safe }}" rel="self" type="application/atom+xml"/>
	<link href="{{ config.base_url | safe }}"/>
	<generator uri="https://www.getzola.org/">Zola</generator>
	<updated>{{ last_updated | date(format="%+") }}</updated>
	<id>{{ feed_url | safe }}</id>
	{%- for page in pages %}
        {%- if page.components is not containing("hidden") %}
        <entry xml:lang="{{ page.lang }}">
            <title>{{ page.title }}</title>
            <published>{{ page.date | date(format="%+") }}</published>
            <updated>{{ page.updated | default(value=page.date) | date(format="%+") }}</updated>
            <link href="{{ page.permalink | safe }}" type="text/html"/>
            <id>{{ page.permalink | safe }}</id>
            <content type="html">{{ page.content }}</content>
        </entry>
        {%- endif %}
	{%- endfor %}
</feed>

The benefit here is that you don’t have to remember to put something in a page header, just keep it in the corresponding folder.

Thanks for you help again, @keats! You are doing such an amazing job here!

1 Like