HUGO

Don't show a post in the posts tab

Basically someone must be able to see a certain post only if they were given the full url of the post. The posts tab shouldn’t list this post (other posts must stay as-is).

Is there an intended way for this?

content/post/test.md

+++
title = 'Test'
date = 2021-09-28T13:17:26-07:00
draft = false
[_build]
  list = 'never'
+++

https://gohugo.io/content-management/build-options

1 Like

One more thing, I would like to put all the unlisted posted in someplace like content/posts/unlisted/. The pages still seem to be listed though. Is there a way to tell hugo to simply ignore (as in build, but not list) the whole unlisted directory?

Reason being that I frequently list and unlist the same posts. It is a hassle to change the metadata (front matter, I couldn’t recall the term before) for every single post and moving them is easier.

content/posts/unlisted/_index.md

+++
title = 'Unlisted'
date = 2021-09-28T21:52:31-07:00
draft = false
[_build]
  list = 'never'
  render = 'never'
[cascade._build]
  list = 'never'
+++

https://gohugo.io/content-management/front-matter#front-matter-cascade

If you want the URL pattern to be consistent across all posts, regardless of whether or not they are in the unlisted directory, add the following to your site configuration:

[permalinks]
  posts = '/posts/:slug/'
1 Like

The taxonomy doesn’t seem to be hidden by this. For example, it shows up under a category. The said categories also show up in the sitemap (assuming all the posts under those categories are unlisted).

Is it possible to hide that too?

I’m curious, are the posts hidden from the RSS feed too?

You are correct. The list = 'never' build option applies to page collections, but the page is still a member of the weighted pages collection for each taxonomy term. The same is true with the render = 'never’ build option; the page is never hidden from the taxonomy system. I’m not sure if this is an oversight, or by design. @bep?

Workarounds

  1. Comment the tags entry in the frontmatter of each post in content/posts/unlisted. Yes, I understand that you would prefer to leave the frontmatter unmolested, but this is the simplest solution that I can come up with.

  2. Create custom taxonomy term and RSS templates that exclude the pages where .Parent.Title is “Unlisted”.

2 Likes

After the discussion at hand and a little experimenting, I’ve thought a bit on what I really needed. Here’s what I went through in the process. I’m using this theme for the record.

Stage 1

Just leave draft = "true" for pages you don’t want others to see.

Stage 2 (this is when I sought this thread)

Well, I needed to see them, so -
A set of pages which are unlisted, which I later found out translates to _build.list = "never". RSS and sitemap didn’t show the unlisted pages, which was good.

Stage 3

I took your front page cascade advice and really liked what I saw. But the unlisted pages still showed up in the categories tab (the only taxonomy I was using at the moment, I didn’t really think about custom taxonomies).

Stage 4

Settled on a custom taxonomy called category-unlisted for unlisted pages. Didn’t really like what I saw though. category-unlisted started showing up in the sitemap and rss.

Stage 5

Just sat back and gave it a little thought about what I needed now. So I formulated a few things.

  1. A set of normal posts and their categories. Everyone has access to these pages at /posts and /categories.
  2. Unlisted pages which are only accessible with their url. No listing, no sitemap, no rss.
  3. I want to share an unlisted page with specific people without giving them access to any of the other unlisted pages.
    I just realized having any sort of taxonomy will be detrimental because that would give links to the unlisted pages belonging the same taxonomy.
    Even if I could override this by editing the layout html files or something else, it would be a burden later.
  4. I found it hard for myself to get to these pages using their urls everytime. A list page at /posts/<obfuscated>/ would be good. /<obfuscated>/ would be less guessable than a simple /unlisted/.

So after reading the documentation you linked, I decided to go with this at /content/posts/unlisted/_index.md.

+++
Title = "Unlisted"
url = "/posts/<obfuscated>"
[_build]
  list = 'always'
[cascade._build]
  list = 'local'
+++

I hope this is the right config. As suggested above, no more taxonomies for unlisted pages seems to be the way to go. Changing the variable cascade._build.list from always to local removed the page entries from the sitemap and rss.

Do you think this is the right way?

I think you want this instead:

+++
title = 'Unlisted'
date = 2021-09-28T21:52:31-07:00
draft = false
url = "/posts/xxx/"  # or whatever
[_build]
  list = 'never'     # If 'always' it will appear on /posts/ and in sitemap
[cascade._build]
  list = 'local'     # Nicely done!
+++

And as long as you omit or comment out the taxonomy terms in the “unlisted” posts’ frontmatter, I think you are in good shape.

1 Like

Strange, putting _build.list = 'always' still doesn’t show it in /posts/. Could be theme specific. I’ll go with your suggestion though.

Anyways, my issue is solved, so thank you once again.

1 Like

I would say it’s an oversight, but for my use cases I never imagined I would assign those pages to taxonomies, though.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.