nodejs实现hexo登录后才可查看
时间: 2024-01-31 13:04:32 浏览: 30
要实现Hexo登录后才能查看,需要进行以下步骤:
1. 安装 hexo-admin 插件:可以通过以下命令进行安装:
```
npm install hexo-admin --save
```
2. 配置 _config.yml 文件:在 _config.yml 文件中,添加以下代码:
```
admin:
username: your_username
password_hash: your_password_hash
```
其中,your_username 是你的用户名,your_password_hash 是你的密码哈希值。密码哈希值可以通过以下命令生成:
```
$ node
> require('crypto').createHash('sha256').update('your_password').digest('hex')
```
3. 设置文章权限:在需要设置权限的文章的 Front-matter 中,添加以下代码:
```
---
title: My Private Post
date: 2021-06-01 10:00:00
categories:
- Private
password: your_password
---
```
其中,your_password 是你设置的文章密码。
4. 配置主题:在主题的 config.yml 文件中,添加以下代码:
```
password:
enable: true
```
5. 重启 Hexo:在终端中,执行以下命令:
```
hexo clean && hexo g && hexo s
```
现在,访问设置了密码的文章时,会先要求输入密码才能查看。如果输入的密码与 Front-matter 中设置的密码相同,则可以查看文章。否则,无法查看文章。