bemyak
June 11, 2020, 11:21am
1
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?
keats
June 11, 2020, 11:24am
2
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
bemyak
June 11, 2020, 4:31pm
3
Indeed, that will cover 100% of what I need
Thank you!
bemyak
July 15, 2020, 1:04pm
4
@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?
keats
July 19, 2020, 3:02pm
5
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.
bemyak
July 19, 2020, 3:25pm
6
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?
keats
July 20, 2020, 9:44am
7
Try page.extra.hidden
if it’s in the extra
section
bemyak
July 20, 2020, 4:40pm
8
Thank you, I read that extra
is a HashMap, so I was trying to do something like
page.extra['hidden']
keats
July 20, 2020, 5:08pm
9
Well that should work in theory x) it should be equivalent to page.extra.hidden
bemyak
July 22, 2020, 6:36am
10
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!
3 Likes