[Solved] Unlisted content


#1

Sometime I have pages or posts that I don’t want showing up in the frontend. So my way to fix this, is to keep them as drafts, run hugo localy with --buildDrafts and then scp it to the server.

Was just wondering if there is a better way of doing this that didn’t involve messing too much with the listings (since I have several of them in different places of the theme).


#2

At first glance it sounds like you are using drafts as intended. Could you rephrase your question? Is there something about keeping posts as drafts that is confusing or creating extra work for you?

Also, what is the “frontend” in your context? I ask, because for Hugo I imagine that is the public site generated, but you are using --buildDrafts, and that seems to counter what you are trying to do.


#3

You could add a frontmatter property to your pages such as exclude: true and then update your homepage template to exclude those pages.


#4

think of this as having the same feature as YouTube has for videos.

You can publish a video as unlisted, and only people with the direct link can see it. Same thing here.

I am going with @moorereason suggestion, using “unlisted: true” in the params. Works for the loop as so:

{{ $loop := (.Paginate (where (where .Data.Pages "Type" "!=" "page") ".Params.unlisted" "!=" "true" ) 1).Pages }}

{{ range $loop }}
    {{ .Render "li" }}
{{ end }} 

This however is not working in the json format:

{{- $.Scratch.Add "index" slice -}}
{{ range where (where .Site.Pages "Type" "not in"  (slice "page" "json")) ".Params.unlisted" "!=" "true"  }}
			{{- $.Scratch.Add "index" (dict "title" .Title "ref" .Permalink "tags" .Params.tags "content" .Plain "image" "https://brunoamaral.eu/images/fractal_thumb.png" ) -}}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}

#5

I was making this more complex than it had to be:

{{- range where .Site.Pages ".Params.unlisted" "!=" "true" -}}

Working now. Thanks guys :slight_smile: