Git Product home page Git Product logo

hexo-hide-posts's Introduction

hexo-hide-posts

npm-version hexo-version

中文文档

A plugin to hide specific posts from your Hexo blog and make them only accessible by links.

Hide means your posts will not come up in article lists (homepage, archive, category, tag, feed, sitemap, whatever), or search results either (by telling search engines not to index these pages with a "noindex" meta tag). Only those who know the link can view the post, and you can share the link with anyone.

This means that posts marked as hidden could still be seen by anyone, but only if they guess the link.

Installation

npm install hexo-hide-posts

Usage

Add hidden: true to the front-matter of posts which you want to hide.

e.g. Edit source/_posts/lorem-ipsum.md:

---
title: 'Lorem Ipsum'
date: '2019/8/10 11:45:14'
hidden: true
---

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

This post will not be shown anywhere, but you can still access it by https://hexo.test/lorem-ipsum/. (If you want to completely prevent a post from rendering, just set it as a draft.)

To get a list of hidden posts, you can run hexo hidden:list from command line.

For developers, all_posts and hidden_posts added to Local Variables may be useful.

Config

In your site's _config.yml:

hide_posts:
  # Should hexo-hide-posts be enabled.
  enable: true

  # The front-matter key for flagging hidden posts.
  # You can change the filter name if you like.
  filter: hidden

  # Add "noindex" meta tag to prevent hidden posts from being indexed by search engines.
  noindex: true

  # Generators in the allowlist will have access to the hidden posts.
  # Common generators in Hexo: 'index', 'tag', 'category', 'archive', 'sitemap', 'feed'
  # allowlist_generators: []

  # Generators in the blocklist can *not* access the hidden posts.
  # The allowlist has higher priority than the blocklist, if both set.
  # blocklist_generators: ['*']

e.g. Set filter to secret, so you can use secret: true in front-matter instead.

Advanced Config

For power users, they can have a more fine-grained control on access to hidden posts by configuring blocklist and allowlist. This feature is available in version 0.3.0 or later.

Config Example 1: Hide the flagged posts everywhere, but make them visible on archives page and sitemap.

hide_posts:
  enable: true
  # This property was previously called `public_generators` prior to v0.2.0, and was renamed in newer version.
  allowlist_generators: ['archive', 'sitemap']

Config Example 2: Hide the flagged posts only on homepage and RSS, and show them elsewhere.

hide_posts:
  enable: true
  # For advanced usage of allowlist/blocklist, check `lib/isGeneratorAllowed.test.js` for more test cases.
  allowlist_generators: ['*']
  blocklist_generators: ['index', 'feed']

Note: although most of generator plugins respect a naming convention that they register generator with the name in their package names, the generator name could be arbitrary. For example, hexo-generator-searchdb does not register generators with name searchdb, but xml and json. For accurate generator name, you should check their source code.

Tips: Run hexo g --debug command will show you all the generators installed with their names in the debug log.

Config Example 3: Pass a custom JavaScript function to determine which generator should be allowlisted.

This could be done by adding a plugin script to your Hexo blog.

// FILE: scripts/allowlist.js (filename does not matter, you name it)

hexo.config.hide_posts.allowlist_function = function (name) {
  return /archive|feed/.test(name);
}

Custom ACL Function

For even more fine-grained control over which posts should be visible in which place, meet the most powerful feature of the plugin: Custom ACL (Access Control List) Function.

In version 0.4.0 and later, a custom JavaScript function could be configured to determine wether a generator could access a post or not, giving you the full control and inspection. The function accepts two arguments, the post object and the current generatorName. The global variable hexo is also available in the context.

Here is an example. Use with caution!

// FILE: scripts/acl.js
const isGeneratorAllowed = require('hexo-hide-posts/lib/isGeneratorAllowed');

// Advanced usage: ACL (Access Control List) per post.
// The most powerful way to control which posts should be included in which generator.
// Return `true` to allow and `false` to block access. It's all up to you.
hexo.config.hide_posts.acl_function_per_post = function (post, generatorName) {
  // Mark the post with front-matter `acl: xxx` so we can recognize it here.
  // For the full definition of `post` and all available properties,
  // see: https://github.com/hexojs/hexo/blob/master/lib/models/post.js
  // console.log(post, post.slug, post.acl, post.tags, post.categories)

  // Posts marked as "no-rss" will not be included in the feed and sitemap
  if (post.acl === 'no-rss') {
    return generatorName !== 'atom' && generatorName !== 'sitemap';
  }

  // Posts marked as "archive-only" will only be included in the archive
  if (post.acl === 'archive-only') {
    return generatorName === 'archive';
  }

  // You can also filter posts with tags and categories
  // All posts in category "news" will NOT be hidden
  // if (post.tags.find({ name: 'news' }).length) {}
  if (post.categories.find({ name: 'news' }).length) {
    return true;
  }

  // Or even the creation date!
  // All posts created before 2020 will be hidden
  if (post.date.year() < 2020) {
    return false;
  }

  // For the rest of posts, apply the default rule (allowlist & blocklist)
  return isGeneratorAllowed(hexo.config.hide_posts, generatorName);
}

License

MIT

hexo-hide-posts's People

Contributors

h404bi avatar prinsss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hexo-hide-posts's Issues

Option to hide post completely

I suppose it's not to difficult to hide post completely and disallow direct access for private post.

Of cause, it will only be accessible via source file - but that's what we really mean by "private".

Otherwise, it will get into sitemap, search engines and etc. And will leak to public.

隐藏文章的分类

请问想弄一个隐藏文章的分类页面该如何实现?
就是像普通的分类那样但是里面都是隐藏的文章

Pages

Am I right that this does not work for a page? Can I change that somewhere so it does allow for pages to be hidden?

hexo g error

➜ hexo hexo g
INFO Start processing
INFO 2 posts are marked as hidden
WARN categories/index.html won't be rendered.
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError: Cannot read property 'bind' of undefined
at Hexo. (/home/haoyue/文档/Web/hexo/node_modules/hexo-hide-posts/index.js:59:30)
请问是哪里有错误呢???
我的hexo 版本是4.2的

输入Url后, 也不能查看?

能不能彻底隐藏某篇文章? 即当隐藏的文章,被知道URL后,在浏览器里访问时, 也会给一个恰当的反馈, 而不是像现在一样,可以正常查看?

隐藏文章的Toc也没有显示了

在使用过程中, 发现设置了隐藏后的文章, Toc也没有了。

隐藏掉Top,不知这是一个正常的功能, 还是一个被躺枪的牵连?

hexo-generator-feed 中没有隐藏文章

我的配置:

# hexo-hide-posts
## https://github.com/prinsss/hexo-hide-posts
hide_posts:
  enable: true
  # 可以改成其他你喜欢的名字
  filter: hidden
  # 指定你想要传递隐藏文章的 generator,比如让所有隐藏文章在存档页面可见
  # 常见的 generators 有:index, tag, category, archive, sitemap, feed, etc.
  # 不常见的还有 xml (butterfly 主题的 hexo-generator-search 搜索,hexo-generator-searchdb 也是这个)
  public_generators: [archive,category,tag,sitemap,baidusitemap,xml,feed]
  # 为隐藏的文章添加 noindex meta 标签,阻止搜索引擎收录
  noindex: false

Hexo 插件:

$ hexo -v
INFO  Validating config
INFO
  ===================================================================
      #####  #    # ##### ##### ###### #####  ###### #      #   #
      #    # #    #   #     #   #      #    # #      #       # #
      #####  #    #   #     #   #####  #    # #####  #        #
      #    # #    #   #     #   #      #####  #      #        #
      #    # #    #   #     #   #      #   #  #      #        #
      #####   ####    #     #   ###### #    # #      ######   #
                            4.6.0
  ===================================================================
hexo: 6.3.0
hexo-cli: 4.3.0
os: win32 10.0.22621
node: 18.13.0
v8: 10.2.154.23-node.21
uv: 1.44.2
zlib: 1.2.13
brotli: 1.0.9
ares: 1.18.1
modules: 108
nghttp2: 1.51.0
napi: 8
llhttp: 6.0.10
uvwasi: 0.0.13
openssl: 3.0.7+quic
cldr: 42.0
icu: 72.1
tz: 2022f
unicode: 15.0
ngtcp2: 0.8.1
nghttp3: 0.7.0

隐藏文章(NSFW):https://www.pil0txia.com/post/2022-12-09_chatgpt-teach-stable-diffusion-nsfw/

使用 hexo-generator-feed 生成的atom:https://www.pil0txia.com/atom.xml

期待您的回复,谢谢

是否有一个Hidden文章的列表?

现在使用Sage管理隐藏文章, 后面可能随着影藏文章的变多, 一些链接自己也记不住了。

这样, 针对这个问题, 是否考虑添加隐藏文章的列表, 方便查看已经隐藏的文章?

当然,现在想到一些方法是, 使用某些Linux命令来搜索sage的关键字。这个方法可以达到效果,但繁琐。
所以还是期望在Sage中能有这样一个功能。

Suggest better document

I thought that hidden posts would not be visible even locally (when you do hexo s), but actually they do, so I thought there was a bug with this plguin. But it seems that when I push my posts online, they do get hidden in a good way.

Example

So I suggest you write this clearly in the document, or more people might get confused. It's a feature, not a bug ;-)

能否仅对部分generator隐藏文章?

个人只想在首页隐藏一些杂乱的文章
但是按照目前插件的功能,只能手动把除了index以外的所有generator都添加到public_generators
包括但不限于:tag, category, archive, sitemap, feed, xml, json, wordcount………对于其他人来说可能会更多
能否添加一个反选功能?
还是挺需要这个的qwq

public_generators: []不生效

我这样填的配置:

hide_posts:
  filter: hide
  # 常见的 generators 有:index, tag, category, archive, sitemap, feed, etc.
  public_generators: [category]
  noindex: true

但指定隐藏的文章并没有生成在categories目录下

期望能够有办法避免对site.posts.length的影响的方法

想要显示完整的文章总数,但是似乎隐藏的文章不计入总数。
请问有什么方式可以优化,感谢!

当前配置:

# 隐藏文章
hide_posts:
  # 是否启用 hexo-hide-posts
  enable: true

  # 隐藏文章的 front-matter 标识,也可以改成其他你喜欢的名字
  filter: hidden

  # 为隐藏的文章添加 noindex meta 标签,阻止搜索引擎收录
  noindex: false

  # 设置白名单,白名单中的 generator 可以访问隐藏文章
  # 常见的 generators 有:index, tag, category, archive, sitemap, feed, etc.
  allowlist_generators: ['*']

  # 设置黑名单,黑名单中的 generator 不可以访问隐藏文章
  # 如果同时设置了黑名单和白名单,白名单的优先级更高
  blocklist_generators: ['index']

[Bug] 使用该插件后生成时报错

主题是hexo-theme-butterfly,报错如下,请问怎么解决?
截屏2022-12-17 12 23 19

配置:

hide_posts:
  enable: true
  filter: secret
  public_generators:
    - tag
    - category
    - archive
  noindex: true

报错

安装后hexo g时

TypeError: Cannot read property 'includes' of null
    at Hexo.<anonymous> (D:\hexo\node_modules\hexo-hide-posts\index.js:125:13)
    at Hexo.tryCatcher (D:\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (D:\hexo\node_modules\bluebird\js\release\method.js:15:34)
    at D:\hexo\node_modules\hexo\lib\extend\filter.js:62:52
    at tryCatcher (D:\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Object.gotValue (D:\hexo\node_modules\bluebird\js\release\reduce.js:166:18)
    at Object.gotAccum (D:\hexo\node_modules\bluebird\js\release\reduce.js:155:25)
    at Object.tryCatcher (D:\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (D:\hexo\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (D:\hexo\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (D:\hexo\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (D:\hexo\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (D:\hexo\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (D:\hexo\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (D:\hexo\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (D:\hexo\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

会导致在打草稿时 hexo-server 不能热刷新文章

不知道你能否复现。

hexo new draft just-a-draft
hexo clean && hexo s --draft --debug

just-a-draft.md

---
title: just-a-draft
draft: true
hidden: true
comments: false
---

编辑 just-a-draft.md,hexo-server 热刷新后,文章会无法访问(还有一种情况是,文章一直是刚启动 hexo server 时的状态,编辑更新的内容不出现)。

如何設定兩種 public genterator?

我想要一部份文章套用 public_generators: ['xml', 'json']
另一些文章套用 public_generators: ['index', 'tag', 'category', 'archive', 'xml', 'json']

請問是否存在某種方式可以達到?

本插件后续更新计划

一系列 TODO,旨在使本插件更为通用。

  • hexo-sage-posts 更名为 hexo-hide-posts
    • 说实话我也不知道当初为什么选了这个名字,想想还是改一下好
    • 变更将包括 GitHub 仓库名与 npm 包名
  • 提供自定义隐藏文章的 filter 选项 #2
    • sage: true 或者 hide: true
  • 修复「上一篇」「下一篇」造成文章入口暴露的问题 #1
  • 允许指定对特定的某些 generator 隐藏文章
    • 如仅对 index 隐藏(即在首页隐藏指定文章)、仅对 feed 隐藏等

预计本周末开始着手开发(欢迎 PR)。

public_generators为archive时数据不对

配置public_generators: [archive]时虽然归档页面可以展示隐藏文章了,但归档页面的计数没有计上

image

这里的目前共计 13 篇日志应该是没计算上隐藏文章的, 但个人理解如果希望在archive里展示的话,计数器也应该计算上隐藏文章才合理?

似乎并不能隐藏

使用的版本是最新版
这是 hexo version 的输出

hexo: 4.2.0
hexo-cli: 3.1.0
os: Windows_NT 10.0.18363 win32 x64
node: 13.8.0
v8: 7.9.317.25-node.28
uv: 1.34.1
zlib: 1.2.11
brotli: 1.0.7
ares: 1.15.0
modules: 79
nghttp2: 1.40.0
napi: 5
llhttp: 2.0.4
openssl: 1.1.1d
cldr: 36.0
icu: 65.1
tz: 2019c
unicode: 12.1

这是 package.json

{
    "name": "hexo-site",
    "version": "0.0.0",
    "private": true,
    "scripts": {
        "build": "hexo generate",
        "clean": "hexo clean",
        "deploy": "hexo deploy",
        "server": "hexo server"
    },
    "hexo": {
        "version": "4.2.0"
    },
    "dependencies": {
        "aplayer": "^1.10.1",
        "hexo": "^4.2.0",
        "hexo-abbrlink": "^2.0.5",
        "hexo-auto-category": "^0.2.0",
        "hexo-baidu-url-submit": "0.0.6",
        "hexo-blog-encrypt": "^3.0.12",
        "hexo-cli": "^3.1.0",
        "hexo-deployer-git": "^2.1.0",
        "hexo-generator-archive": "^1.0.0",
        "hexo-generator-baidu-sitemap": "^0.1.6",
        "hexo-generator-category": "^1.0.0",
        "hexo-generator-feed": "^2.2.0",
        "hexo-generator-index": "^1.0.0",
        "hexo-generator-search": "^2.4.0",
        "hexo-generator-searchdb": "^1.2.0",
        "hexo-generator-sitemap": "^2.0.0",
        "hexo-generator-tag": "^1.0.0",
        "hexo-hide-posts": "^0.1.0",
        "hexo-offline": "^1.0.0",
        "hexo-renderer-ejs": "^1.0.0",
        "hexo-renderer-marked": "^2.0.0",
        "hexo-renderer-pug": "^1.0.0",
        "hexo-renderer-stylus": "^1.1.0",
        "hexo-server": "^1.0.0",
        "hexo-symbols-count-time": "^0.7.0",
        "hexo-tag-aplayer": "^3.0.4",
        "hexo-wordcount": "^6.0.1",
        "image-size": "^0.8.3"
    }
}

可以看看怎么回事吗

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.