-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hexo 7.0 下失去部分隐藏效果 #34
Comments
「能看到隐藏文章对应的分类和标签」,那么在这些页面上能看到被隐藏的文章吗?还是只能看到分类和标签? 我之前在 v7.0.0 (RC2) 中测试过,功能应该是正常的,不知道是不是正式版有什么改动。 为了方便排查问题,请你提供以下信息:
谢谢。 |
不能看到被隐藏的文章,只能看到对应的分类和标签,如图。 Hexo
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Hexo
subtitle: ''
description: ''
keywords:
author: John Doe
language: en
timezone: ''
# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://example.com
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks
# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link:
enable: true # Open external links in new tab
field: site # Apply to the whole site
exclude: ''
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
syntax_highlighter: highlight.js
highlight:
line_number: true
auto_detect: false
tab_replace: ''
wrap: true
hljs: false
prismjs:
preprocess: true
line_number: true
tab_replace: ''
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'
# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page
# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: ''
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: ['*'] |
这个点进去是正常的,即什么也看不到。 比如 |
本地复现了,Hexo 6.3.0 是正常的,升级到 7.0.0 就有问题。 我后面看下怎么修复,感谢反馈! |
定位到问题了,Hexo 那边做了个性能优化,影响了这部分功能,不知道上游会不会修复。 Related Issue/PR: 可以用以下临时方法解决: // FILE: scripts/fix.js
hexo.extend.filter.register("before_generate", function () {
// Ignore categories with zero posts
this.locals.set("categories", () => {
return this.database
.model("Category")
.filter((category) => category.posts.length);
});
// Ignore tags with zero posts
this.locals.set("tags", () => {
return this.database.model("Tag").filter((tag) => {
// tag.length => 1
// tag.posts.length => 0
// See: https://github.com/hexojs/hexo/pull/5119
// console.log(tag.name, tag.length, tag.posts.length);
return tag.posts.length;
});
});
}); 然后再 |
感谢您的回复! 我觉得这个 issue 保持开启比较好——即使它是 Hexo 自身原因造成的——方便遇到同样问题的人找到您提出的解决方案。 |
嗯,我会保持开启的。 我已经在上游 issue 中提交了相关信息,看看 Hexo 那边会不会修复吧。如果不修复那就插件这边兼容一下。 |
hexo-site@0.0.0 /Users/raccoon/blogs # hexo-hide-posts
hide_posts:
filter: hidden
public_generators: []
noindex: true 这是_config.yml中的hidden配置 |
Hi @Raccoon-njuse , 试试这个新脚本: // FILE: scripts/fix.js
// This script will revert changes introduced in PR #5119
// See: https://github.com/hexojs/hexo/pull/5119/files
hexo.extend.filter.register('before_generate', function () {
// Retrieve internal database models
const Category = this.database.model('Category');
const Tag = this.database.model('Tag');
// Revert changes to lib/hexo/index.js
this.locals.set('categories', () => {
// Ignore categories with zero posts
return Category.filter((category) => category.length);
});
this.locals.set('tags', () => {
// Ignore tags with zero posts
return Tag.filter((tag) => tag.length);
});
// Revert changes to lib/models/category.js
Category.schema.virtual('length').get(function () {
return this.posts.length;
});
// Revert changes to lib/models/tag.js
Tag.schema.virtual('length').get(function() {
return this.posts.length;
});
}); |
@prinsss ,临时解决方案已生效!感谢您的回复!期待上游修复 |
先不等上游修复了, |
经测试,Hexo 7.0 下,在分类和标签页面能看到隐藏文章对应的分类和标签。
The text was updated successfully, but these errors were encountered: