hexo-hide-posts
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -20,2 +20,3 @@ /* global hexo */ | ||
acl_function_per_post: null, | ||
hexo_7_compatibility_patch: hexo.version.startsWith('7'), | ||
noindex: true, | ||
@@ -41,2 +42,5 @@ noindex_tag: '<meta name="robots" content="noindex">', | ||
// Apply patch for Hexo 7.0 | ||
hexo.extend.filter.register('before_generate', require('./lib/applyPatch'), 9); | ||
// Prepare hidden posts | ||
@@ -43,0 +47,0 @@ hexo.extend.filter.register('before_generate', require('./lib/prepareHiddenPosts')); |
@@ -23,4 +23,7 @@ 'use strict'; | ||
// assign the values again manually. Such a weird problem, damn it. | ||
this._bindLocals(); | ||
// Update: Since v0.4.1, we call `_bindLocals` in `lib/applyPatch.js` instead. | ||
// Maybe we don't need to call it anymore, but I'm not sure. So just keep it there. | ||
// this._bindLocals(); | ||
// Do the filter | ||
@@ -27,0 +30,0 @@ const all_posts = this.locals.get('posts'); |
{ | ||
"name": "hexo-hide-posts", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A plugin to hide specific posts from your Hexo blog and make them only accessible by links.", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "jest" | ||
}, | ||
"repository": { | ||
@@ -21,14 +25,10 @@ "type": "git", | ||
"devDependencies": { | ||
"eslint": "^8.47.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-hexo": "^5.0.0", | ||
"eslint-plugin-jest": "^27.2.3", | ||
"jest": "^29.6.3" | ||
"eslint-plugin-jest": "^27.9.0", | ||
"jest": "^29.7.0" | ||
}, | ||
"dependencies": { | ||
"chalk": "^4" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"test": "jest" | ||
} | ||
} | ||
} |
@@ -109,3 +109,3 @@ # hexo-hide-posts | ||
如果你需要更细粒度地控制某篇文章应该如何显示或隐藏,可以使用本插件的更高级功能:**自定义 ACL 函数**。 | ||
如果你需要更细粒度地控制某篇文章应该如何显示或隐藏,可以使用本插件的更高级功能:**自定义 ACL 函数**(需要 0.4.0 及以上版本)。 | ||
@@ -123,2 +123,3 @@ 插件支持传入自定义 JavaScript 函数作为 ACL (Access Control List,访问控制列表)。ACL 函数功能十分强大,可以完全控制某一篇文章是否应该被某一个 generator 渲染。函数接受两个参数:文章对象 `post`,以及当前 generator 的注册名称 `generatorName`。同时,也可以访问全局变量 `hexo`。 | ||
// FILE: scripts/acl.js | ||
const isGeneratorAllowed = require('hexo-hide-posts/lib/isGeneratorAllowed'); | ||
@@ -134,5 +135,2 @@ // Advanced usage: ACL (Access Control List) per post. | ||
// To filter posts by tag, use this instead: | ||
// if (post.tags.find({ name: 'no-rss' }).length) {} | ||
// Posts marked as "no-rss" will not be included in the feed and sitemap | ||
@@ -150,2 +148,3 @@ if (post.acl === 'no-rss') { | ||
// All posts in category "news" will NOT be hidden | ||
// if (post.tags.find({ name: 'news' }).length) {} | ||
if (post.categories.find({ name: 'news' }).length) { | ||
@@ -152,0 +151,0 @@ return true; |
@@ -116,3 +116,3 @@ # hexo-hide-posts | ||
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. | ||
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. | ||
@@ -123,2 +123,3 @@ Here is an example. Use with caution! | ||
// FILE: scripts/acl.js | ||
const isGeneratorAllowed = require('hexo-hide-posts/lib/isGeneratorAllowed'); | ||
@@ -134,5 +135,2 @@ // Advanced usage: ACL (Access Control List) per post. | ||
// To filter posts by tag, use this instead: | ||
// if (post.tags.find({ name: 'no-rss' }).length) {} | ||
// Posts marked as "no-rss" will not be included in the feed and sitemap | ||
@@ -150,2 +148,3 @@ if (post.acl === 'no-rss') { | ||
// All posts in category "news" will NOT be hidden | ||
// if (post.tags.find({ name: 'news' }).length) {} | ||
if (post.categories.find({ name: 'news' }).length) { | ||
@@ -152,0 +151,0 @@ return true; |
30826
13
390
164