D0n9X1n / hexo-blog-encrypt

Yet, just another hexo plugin for security.
https://www.npmjs.com/package/hexo-blog-encrypt
MIT License
971 stars 101 forks source link

3-hexo主题hexo generate报错Template render error: (unknown path) Error: expected end of comment, got end of file #170

Closed ydam24 closed 3 years ago

ydam24 commented 3 years ago

Issue

疑似与 hexo-theme-3-hexo 主题冲突 执行hexo generate过程中报错Template render error: (unknown path) Error: expected end of comment, got end of file

Expected Behavior

正常生成

Actual Behavior

出现以下错误

$ hexo generate
INFO  Start processing
INFO  hexo-blog-encrypt: encrypting "Postgraduate Math II" based on Tag: "encrypted" with theme default.
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Template render error: (unknown path)
  Error: expected end of comment, got end of file
    at Object._prettifyError (/builds/blog/blog.ydam.dev/node_modules/nunjucks/src/lib.js:36:11)
    at Template.render (/builds/blog/blog.ydam.dev/node_modules/nunjucks/src/environment.js:536:21)
    at Environment.renderString (/builds/blog/blog.ydam.dev/node_modules/nunjucks/src/environment.js:378:17)
    at /builds/blog/blog.ydam.dev/node_modules/hexo/lib/extend/tag.js:123:48
    at tryCatcher (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.fromNode.Promise.fromCallback (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:209:30)
    at Tag.render (/builds/blog/blog.ydam.dev/node_modules/hexo/lib/extend/tag.js:123:18)
    at Object.onRenderEnd (/builds/blog/blog.ydam.dev/node_modules/hexo/lib/hexo/post.js:280:20)
    at /builds/blog/blog.ydam.dev/node_modules/hexo/lib/hexo/render.js:64:19
    at tryCatcher (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

Steps to Reproduce the Problem

npm install hexo-generator-topindex --save
hexo generate

Specifications

.gitlab-ci.yml

image: node:12.16.1

cache:
  paths:
    - node_modules/

before_script:
  - npm install hexo-cli -g
  - npm install hexo-generator-search -save
  # - npm install hexo-wordcount -save
  - npm install hexo-generator-topindex --save
  - npm install hexo-blog-encrypt --save
  - test -e package.json && npm install
  - hexo generate

pages:
  script:
    - hexo generate
  artifacts:
    paths:
      - public
    expire_in: 3 day
  only:
    - master
  tags:
    - main

完整的 log

Running with gitlab-runner 13.6.0 (8fa89735)
  on prod GRLLS6T9
Resolving secrets
00:00
Preparing the "docker" executor
00:08
Using Docker executor with image node:12.16.1 ...
Pulling docker image node:12.16.1 ...
Using docker image sha256:88c089733a3b980b3517e8e2e8afa46b338f69d7562550cb3c2e9fd852a2fbac for node:12.16.1 with digest node@sha256:46f4c17e1edbde36d60a9f6362db7912cfe301bac89afef7cc92421ab3e7ca18 ...
Preparing environment
00:02
Running on runner-grlls6t9-project-14-concurrent-0 via sd-118218...
Getting source from Git repository
00:07
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/blog/blog.ydam.dev/.git/
Checking out 47aa736d as master...
Removing db.json
Removing node_modules/
Skipping Git submodules setup
Restoring cache
00:11
Checking cache for default-3...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
01:48
$ npm install hexo-cli -g
/usr/local/bin/hexo -> /usr/local/lib/node_modules/hexo-cli/bin/hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules/hexo-cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ hexo-cli@4.2.0
added 65 packages from 339 contributors in 9.529s
$ npm install hexo-generator-search -save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/nunjucks/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ hexo-generator-search@2.4.1
removed 33 packages, updated 1 package and audited 688 packages in 19.61s
4 packages are looking for funding
  run `npm fund` for details
found 43 vulnerabilities (25 low, 7 moderate, 10 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
$ npm install hexo-generator-topindex --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/nunjucks/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ hexo-generator-topindex@0.3.0
added 1 package from 1 contributor and audited 689 packages in 18.345s
4 packages are looking for funding
  run `npm fund` for details
found 43 vulnerabilities (25 low, 7 moderate, 10 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
$ npm install hexo-blog-encrypt --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/nunjucks/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ hexo-blog-encrypt@3.1.5
added 1 package from 1 contributor and audited 690 packages in 17.55s
4 packages are looking for funding
  run `npm fund` for details
found 48 vulnerabilities (30 low, 7 moderate, 10 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
$ test -e package.json && npm install
npm WARN deprecated ejs@1.0.0: Critical security bugs fixed in 2.5.5
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/nunjucks/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 31 packages from 52 contributors and audited 721 packages in 20.574s
4 packages are looking for funding
  run `npm fund` for details
found 50 vulnerabilities (31 low, 8 moderate, 10 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
$ hexo generate
INFO  Start processing
INFO  hexo-blog-encrypt: encrypting "Postgraduate Math II" based on Tag: "encrypted" with theme default.
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Template render error: (unknown path)
  Error: expected end of comment, got end of file
    at Object._prettifyError (/builds/blog/blog.ydam.dev/node_modules/nunjucks/src/lib.js:36:11)
    at Template.render (/builds/blog/blog.ydam.dev/node_modules/nunjucks/src/environment.js:536:21)
    at Environment.renderString (/builds/blog/blog.ydam.dev/node_modules/nunjucks/src/environment.js:378:17)
    at /builds/blog/blog.ydam.dev/node_modules/hexo/lib/extend/tag.js:123:48
    at tryCatcher (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.fromNode.Promise.fromCallback (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:209:30)
    at Tag.render (/builds/blog/blog.ydam.dev/node_modules/hexo/lib/extend/tag.js:123:18)
    at Object.onRenderEnd (/builds/blog/blog.ydam.dev/node_modules/hexo/lib/hexo/post.js:280:20)
    at /builds/blog/blog.ydam.dev/node_modules/hexo/lib/hexo/render.js:64:19
    at tryCatcher (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues (/builds/blog/blog.ydam.dev/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)
D0n9X1n commented 3 years ago

博文里面有没有包含 {# 字符?

ydam24 commented 3 years ago

报错的这篇没有包含 只有这篇用了加密 内容如下

---
title: Postgraduate Math II
tags:
  - math
categories:
  - Summary
  - encrypted
date: 2020-09-19 21:35:29
---

test

_config.yml的内容

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Ydam
subtitle: Blog
description: Ydam's Blog
author: Ydam
language:
timezone: Asia/Shanghai

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: /
root: "/"
permalink: :year/:month/:day/:title/
permalink_defaults:

# 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: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: false
  line_number: false
  auto_detect: false
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# 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

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
# theme: landscape
theme: 3-hexo-new

search:
  path: search.xml
  field: post

# Security
encrypt: # hexo-blog-encrypt
  abstract: Here's something encrypted, password is required to continue reading.
  message: Hey, password is required here.
  tags:
  - {name: encrypted, password: 123456}
  wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
  wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type:
ydam24 commented 3 years ago

抱歉,不是主题和插件的问题😂 更新了node.jshexo到新的版本之后正常了

Anyone who faces errors like Template render error: (unknown path) Error: expected end of comment, got end of filetry to upgrade node.js and hexo to the latest version may fix it.

不过还是有点小问题😂,解密之后highlight.js的代码高亮的样式全没了,请问有解决方案吗。

ydam24 commented 3 years ago

抱歉,不是主题和插件的问题😂 更新了node.jshexo到新的版本之后正常了

Anyone who faces errors like Template render error: (unknown path) Error: expected end of comment, got end of filetry to upgrade node.js and hexo to the latest version may fix it.

不过还是有点小问题😂,解密之后highlight.js的代码高亮的样式全没了,请问有解决方案吗。

问题解决了,在加密的博文后面加上

<script>
  document.querySelectorAll('pre code').forEach((block) => {
    hljs.highlightBlock(block);
  });
</script>

可以解决问题

不过这样一个一个添加比较麻烦,能在_config.yml中提供一个统一的设置选项自动添加吗😂

D0n9X1n commented 3 years ago

会有的,已经在计划中了。那这个 issue 就先关了。