hexo icon indicating copy to clipboard operation
hexo copied to clipboard

Private posts with hexo

Open jehy opened this issue 3 years ago • 17 comments

Check List

Please check followings before submitting a new feature request.

  • [X] I have already read Docs page
  • [X] I have already searched existing issues

Feature Request

There is a plugin for hiding private posts - hexo-hide-posts - but it does't hide post if it is accessed directly, post is left in repo data and can be easily found and also I think that it should be a part of base hexo itself. It should be really simple - hexo should just skip reading this post if it has a private flag.

Of cause, it means that post will only be readable via source file, but I think that it's exactly what we need for private posts.

We would need to add a notice that private posts need private hexo repos, but this is also fine and clear.

Others

jehy avatar Jul 22 '20 08:07 jehy

You can use drafts: https://hexo.io/docs/writing#Drafts

stevenjoezhang avatar Jul 22 '20 11:07 stevenjoezhang

@stevenjoezhang Using drafts is pretty much indirect, messy and dangerous way. Real drafts will be in the same place as private posts, without any difference, and it is possible to accidentially publish them.

jehy avatar Jul 22 '20 12:07 jehy

Added a simple PR which implements this feature.

jehy avatar Jul 22 '20 21:07 jehy

Using drafts is pretty much indirect, messy and dangerous way.

I find the current approach of putting drafts in the _drafts/ folder to be more organised and much easier to identify (that a post/page is a draft).

That said, I'm ok with the proposal of setting a post/page as draft via front-matter. Instead of private: true, I suggest to use layout: draft to be more consistent with current approach.

curbengh avatar Aug 23 '20 11:08 curbengh

Drafts are a great and useful feature, but... Private posts are not drafts, that's completely another feature. And it is transparently supported on all major blog platforms. Implementing it with side effect via layout does not look really good.

jehy avatar Aug 23 '20 11:08 jehy

Private posts are not drafts, that's completely another feature.

I tested https://github.com/hexojs/hexo/pull/4435 and it is functionally similar to drafts? My understanding of a private post is that it is still processed/rendered, but a reader (pre-approved by the blogger) needs to login to view it.


btw, a post/page is skipped whenever it has an underscore prefix _foo.md, this is another way of setting an article as draft; except for _posts, any files inside a folder with an underscore prefix are also skipped.

curbengh avatar Aug 24 '20 01:08 curbengh

Hexo won't read outside the source folder file, you may be able to create a secret folder outside.

a post/page is skipped whenever it has an underscore prefix

Or underlined folders, the articles inside will also be ignored, e.g. _secret

jiangtj avatar Aug 24 '20 01:08 jiangtj

I still don't understand why the function of hiding is needed.

If you don’t need the article to be rendered and displayed, you can create a new private repo for storage.

jiangtj avatar Aug 24 '20 02:08 jiangtj

https://github.com/hexojs/hexo/issues/4433#issuecomment-678865598 If you don’t need the article to be rendered and displayed, you can create a new private repo for storage.

I believe that's what OP meant

https://github.com/hexojs/hexo/issues/4433#issue-663563013 We would need to add a notice that private posts need private hexo repos


One idea is to utilise to have a front-matter like:

---
title: a private post
redirect: https://github.com/user/private-repo/blob/source/source/_posts/a-private-post.md
---

The post still shows up on index page, but viewing it will be 302-redirect to the repo link. It's quite similar to hexo-generator-alias but the plugin mostly limited to internal redirect, redirecting a post to external link requires two aliases.

Edit: https://github.com/hexojs/hexo-generator-alias/pull/48


Currently it's possible to redirect a post/page using layout: false:

---
title: test one
date: 2019-11-05 00:00:01
layout: false
---

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Redirecting...</title>
  <meta http-equiv="refresh" content="0; url=https://github.com/hexojs/hexo">
</head>
</html>

curbengh avatar Aug 24 '20 03:08 curbengh

I still don't understand why the function of hiding is needed.

If you don’t need the article to be rendered and displayed, you can create a new private repo for storage.

Yup, I don't want article to be displayed. But I have already a public blog, and I don't want to make another one. With hexo workflow and my PR, it works great - I have a private repo which contains all posts, and some of them are marked as private. And I have a public repo on github.io which is automatically published from the private one via github actions, and it only contains public posts and assets.

Of cause, there can be thousands of workarounds like drafts, redirects, layouts and so on. But why not have a simple and clear feature of private posts?

jehy avatar Aug 24 '20 10:08 jehy

https://github.com/hexojs/hexo-generator-alias/pull/48 seems to be quite close to what you want, unless you prefer not to have the private post's link (/2020/01/02/a-private-post) and its title show up in index page.

---
title: a private post
redirect: https://github.com/user/private-repo/blob/source/source/_posts/a-private-post.md
---

Of cause, there can be thousands of workarounds like drafts, redirects, layouts and so on. But why not have a simple and clear feature of private posts?

private: true as implemented in https://github.com/hexojs/hexo/pull/4435 is not accurate because Hexo wouldn't know whether the repo is private, using layout: 'draft' syntax is more accurate to its function. https://github.com/hexojs/hexo/pull/4435 is essentially setting an article as draft, so it is actually a workaround itself to emulate a private post.

curbengh avatar Aug 24 '20 12:08 curbengh

hexojs/hexo-generator-alias#48 seems to be quite close to what you want, unless you prefer not to have the private post's link (/2020/01/02/a-private-post) and its title show up in index page.

Private post with public title aren't much private :)

private: true as implemented in #4435 is not accurate because Hexo wouldn't know whether the repo is private,

Hexo does not need to know anything about it. Post will be private and excluded from everywhere if source repo is private. It seems obvious - how else can you expect any content to be private in public repo?

using layout: 'draft' syntax is more accurate to its function. #4435 is essentially setting an article as draft, so it is actually a workaround itself to emulate a private post.

#4435 does not set article as draft, is simply removes it from any index and doesn't mess with draft system. Drafts and private posts should be completely different entities.

jehy avatar Aug 24 '20 14:08 jehy

And it is transparently supported on all major blog platforms

A reminder that Hexo is a static site generator (SSG). I checked other SSGs (Next.js, Hugo, Jekyll, Nuxt.js & Pelican) and they don't support private post either. Gatsby supports it because it supports dynamic rendering. Without dynamic rendering, the concept of private post is out of scope for a static site generator.

Private post with public title aren't much private

Depends on one's need, some may prefer to keep only the content private.

Post will be private and excluded from everywhere if source repo is private.

Well, a post will only be private if the source repo is private.

Drafts and private posts should be completely different entities.

In https://github.com/hexojs/hexo/pull/4435, they are practically the same. They don't have to be different either, I never mention that hexo publish has to support layout: 'draft'. Even if a private post is processed as a draft, the database is git-ignored by default.

it is possible to accidentially publish them

Same possibility that a user could make a typo on the front-matter (e.g. privatr: true) and the private post then get published.


I suggest publish: false since it doesn't assume private repo nor conflict with draft.

curbengh avatar Aug 25 '20 03:08 curbengh

Same possibility that a user could make a typo on the front-matter (e.g. privatr: true) and the private post then get published.

Yup, but this way you can only accidentally publish one post. While when using drafts - you can accidentially publish all of them at once.

I suggest publish: false since it doesn't assume private repo nor conflict with draft.

Yeah, that looks fine too.

jehy avatar Aug 25 '20 06:08 jehy

@curbengh Oops, while I changed private:true to publish:false, I found out that we already have property published, and those will create a mess :(

jehy avatar Aug 26 '20 06:08 jehy

~Isn't hexo-hide-posts what you're looking for?~

EDIT: sorry, I've just went through the discussion without properly reading the issue.

darekkay avatar Oct 14 '20 16:10 darekkay

Isn't hexo-hide-posts what you're looking for?

No, I already described it in feature request.

jehy avatar Oct 14 '20 16:10 jehy

Regarding your initial requirement:

Of cause, it means that post will only be readable via source file, but I think that it's exactly what we need for private posts.

You can place the article outside of Hexo's source folder, and it won't be processed. For example, as mentioned in the previous discussion, you can create a _secret folder to store these articles. I will close this feature request.

stevenjoezhang avatar Jul 14 '23 02:07 stevenjoezhang