How to make posts private in Hugo?
Asked Answered
T

4

8

I am looking for ways to make some of the posts on my blog visible only to myself but can't seem to this in Hugo.

Is there any way around this such as setting a password for certain posts?
Or is the feature supported but I just haven't found it?

Tollefson answered 31/7, 2016 at 0:17 Comment(0)
S
9

Since Hugo just generates the static HTML, the question can be widened to: how to password-protect any static content on the web server.

That's doable.

It depends what is your web server using: Apache or Nginx or something else.

In Apache case, set up password authentication via .htaccess. See tutorials like this.

In Nginx case, set up password on your server block section, see tutorials like this.

For other server (IIS?), google accordingly.


Some people will want to downgrade this question, but in my opinion it's very valid, for example, if you want to post portfolios, CV's and whatnot on your personal website and limit public access

Make a landing page on Hugo site, password-protect the URL and give visitors the password. Easy, fast and still static!

Sesqui answered 18/8, 2016 at 8:39 Comment(1)
Just add the .htaccess file to the static dir and it will work.Dowable
P
2

My way to keep posts private is to set the draft flag in the front matter:

TOML

draft: "true"

A good practise for me is to connect a local instance of Hugo with GitLab/GitHub. If you want to see your website or a specific post as a rendered version you can turn on and off the visibility of pages using the draft flag with true and false.

If you have finished your tests you can push the final version with or without the draft flag active to the repo and sync it with your server side installation of Hugo.

Peppy answered 5/3, 2021 at 7:16 Comment(0)
S
1

Posts are displayed in multiple places (RSS feeds, search results, sitemap etc.).

Here is an article with an updated checklist and a solution to publish hidden posts with Hugo

Installation

git clone --recurse-submodules [email protected]:RoneoOrg/hugo-offtherecord-demo.git
cd hugo-offtherecord-demo
hugo serve

Usage

Set offTheRecord to true in the Front Matter of the posts you want to hide. That’s all!

See the source for details

Schiro answered 1/4, 2022 at 2:51 Comment(3)
This works, however this is a custom theme for hugo (based on hugo-papermod). This does not apply to Hugo in general.Karsten
You're right, Hugo does not provide such feature out of the boxSchiro
I've recently found that In fact, hugo newer version support that out of the box. See here.Karsten
K
0

Finally found the answer. Just add this information to your page frontmatter:

_build:
  list: false

Note that this way, posts are only not shown in lists, sitemaps. However, this doesn't make your page protected by password.

Answer is taken from Hugo Discourse page.

Karsten answered 17/9, 2023 at 8:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.