hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.17k stars 4.81k forks source link

jQuery plugin causing template render error #2522

Closed jchck closed 4 years ago

jchck commented 7 years ago

Environment Info

Node version(node -v): 7.7.4

Your site _config.yml (Optional):

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

# Site
title: Hexo
subtitle:
description:
author: John Doe
language:
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
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: true
  line_number: true
  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/
## dounts is our default theme name
theme: donuts

# Imagemin
## https://github.com/vseventer/hexo-imagemin
imagemin:
  enable: true
  interlaced: false
  multipass: false
  optimizationLevel: 2
  pngquant: false
  progressive: false

# Critical CSS
# enable/disable below
criticalcss:
  enable: false
  inline: true
  width: 320
  height: 480
  critical:
    minify: true

# To minify html
# Uses https://github.com/kangax/html-minifier
html_minifier:
  enable: true
  removeComments: true
  collapseWhitespace: false

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type:

Your theme _config.yml (Optional): is empty

Hexo and Plugin version(npm ls --depth 0):

starter@0.0.0 /Users/jchick/Documents/Code/tables
├── autoprefixer@6.7.7
├── css-mqpacker@5.0.1
├── cssnano@3.10.0
├── gulp@3.9.1
├── gulp-concat@2.6.1
├── gulp-jshint@2.0.4
├── gulp-postcss@6.4.0
├── gulp-size@2.1.0
├── gulp-sourcemaps@2.6.0
├── gulp-uglify@2.1.2
├── gulp-util@3.0.8
├── gulp-watch@4.3.11
├── hexo@3.3.1
├── hexo-browsersync@0.2.0
├── hexo-critical-css@1.0.6
├── hexo-deployer-git@0.2.0
├── hexo-generator-archive@0.1.4
├── hexo-generator-category@0.1.3
├── hexo-generator-index@0.2.1
├── hexo-generator-tag@0.2.0
├── hexo-html-minifier@0.0.1
├── hexo-imagemin@0.1.0
├── hexo-renderer-ejs@0.2.0
├── hexo-renderer-marked@0.2.11
├── hexo-server@0.2.0
├── jshint@2.9.4
├── normalize.css@5.0.0
├── postcss-calc@5.3.1
├── postcss-color-function@3.0.0
├── postcss-custom-media@5.0.1
├── postcss-custom-properties@5.0.2
├── postcss-discard-comments@2.0.4
├── postcss-import@9.1.0
├── pump@1.0.2
└── tachyons-custom@4.5.5

For BUG

A Template render error: (unknown path) [Line 1421, Column 13] error is getting thrown when this jQuery plugin is added to ./source/js directory.

The error appears to be related to this file as removing the file resolves the issue.

Here's the hexo generate --debug log:

tables git:(master) ✗ hexo generate --debug
01:40:04.930 DEBUG Hexo version: 3.3.1
01:40:04.932 DEBUG Working directory: ~/Documents/Code/tables/
01:40:04.997 DEBUG Config loaded: ~/Documents/Code/tables/_config.yml
01:40:05.048 DEBUG Plugin loaded: hexo-browsersync
01:40:05.853 DEBUG Plugin loaded: hexo-critical-css
01:40:05.854 DEBUG Plugin loaded: hexo-deployer-git
01:40:05.856 DEBUG Plugin loaded: hexo-generator-archive
01:40:05.857 DEBUG Plugin loaded: hexo-generator-category
01:40:05.857 DEBUG Plugin loaded: hexo-generator-index
01:40:05.858 DEBUG Plugin loaded: hexo-generator-tag
01:40:05.862 DEBUG Plugin loaded: hexo-html-minifier
01:40:06.017 DEBUG Plugin loaded: hexo-imagemin
01:40:06.019 DEBUG Plugin loaded: hexo-renderer-ejs
01:40:06.025 DEBUG Plugin loaded: hexo-renderer-marked
01:40:06.063 DEBUG Plugin loaded: hexo-server
01:40:06.067 DEBUG Loading database.
01:40:06.136 INFO  Start processing
01:40:06.179 DEBUG Processed: _posts/hello-world.md
01:40:06.179 DEBUG Processed: js/scripts.js
01:40:06.182 DEBUG Processed: css/styles.css
01:40:06.187 DEBUG Theme config loaded.
01:40:06.188 DEBUG Processed: _config.yml
01:40:06.189 DEBUG Processed: css/styles.css.map
01:40:06.192 DEBUG Processed: layout/archive.ejs
01:40:06.192 DEBUG Processed: layout/category.ejs
01:40:06.193 DEBUG Processed: layout/post.ejs
01:40:06.193 DEBUG Processed: layout/page.ejs
01:40:06.194 DEBUG Processed: layout/index.ejs
01:40:06.194 DEBUG Processed: layout/layout.ejs
01:40:06.195 DEBUG Processed: layout/_partials/footer.ejs
01:40:06.195 DEBUG Processed: layout/_partials/header.ejs
01:40:06.200 DEBUG Processed: layout/_partials/analytics.ejs
01:40:06.200 DEBUG Processed: layout/_partials/head.ejs
01:40:06.206 DEBUG Processed: js/footable.js
01:40:06.221 FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: (unknown path) [Line 818, Column 13]
  unexpected token: }}
    at Object.exports.prettifyError (/Users/jchick/Documents/Code/tables/node_modules/nunjucks/src/lib.js:34:15)
    at new_cls.render (/Users/jchick/Documents/Code/tables/node_modules/nunjucks/src/environment.js:469:27)
    at new_cls.renderString (/Users/jchick/Documents/Code/tables/node_modules/nunjucks/src/environment.js:327:21)
    at /Users/jchick/Documents/Code/tables/node_modules/hexo/lib/extend/tag.js:66:9
    at Promise._execute (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:79:10)
    at Tag.render (/Users/jchick/Documents/Code/tables/node_modules/hexo/lib/extend/tag.js:64:10)
    at Object.tagFilter [as onRenderEnd] (/Users/jchick/Documents/Code/tables/node_modules/hexo/lib/hexo/post.js:253:16)
    at /Users/jchick/Documents/Code/tables/node_modules/hexo/lib/hexo/render.js:65:19
    at tryCatcher (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)
01:40:06.231 DEBUG Database saved
01:40:06.231 FATAL (unknown path) [Line 818, Column 13]
  unexpected token: }}
Template render error: (unknown path) [Line 818, Column 13]
  unexpected token: }}
    at Object.exports.prettifyError (/Users/jchick/Documents/Code/tables/node_modules/nunjucks/src/lib.js:34:15)
    at new_cls.render (/Users/jchick/Documents/Code/tables/node_modules/nunjucks/src/environment.js:469:27)
    at new_cls.renderString (/Users/jchick/Documents/Code/tables/node_modules/nunjucks/src/environment.js:327:21)
    at /Users/jchick/Documents/Code/tables/node_modules/hexo/lib/extend/tag.js:66:9
    at Promise._execute (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:79:10)
    at Tag.render (/Users/jchick/Documents/Code/tables/node_modules/hexo/lib/extend/tag.js:64:10)
    at Object.tagFilter [as onRenderEnd] (/Users/jchick/Documents/Code/tables/node_modules/hexo/lib/hexo/post.js:253:16)
    at /Users/jchick/Documents/Code/tables/node_modules/hexo/lib/hexo/render.js:65:19
    at tryCatcher (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/jchick/Documents/Code/tables/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)

Thanks for all your hardwork!

NoahDragon commented 7 years ago

I think this is caused by the confliction with nunjucks syntax. Could you please check if }} used in any files?

jchck commented 7 years ago

I'm not sure if nunchucks is in use, but there are a bunch of {{ }} in use.

ie:

(function($, F){
    // add in console we use in case it's missing
    window.console = window.console || { log:function(){}, error:function(){} };
...
});

Is there anyway to supress the error? It's a plugin installed via Bower and I'm not a maintaner of the project.

Thanks.

NoahDragon commented 7 years ago

For js code, it should be okay. The nunjucks filter applies to the posts.

jchck commented 7 years ago

Is it possible that this is not related to the nunjucks filter?

This isn't a post, it's a js file located in ./source/js.

There's other js in the same ./source/js directory which gets's passed along fine via hexo generate.

The default hello world post is the only post that currently exists.

NoahDragon commented 7 years ago

Let me try to reproduce.

jchck commented 7 years ago

Cool, thanks!

stevenjoezhang commented 4 years ago

Hexo sometimes renders Javascript files incorrectly. It may be caused by the wrong filter used by Hexo plugins. In fact, Hexo will transform every file in source/ unless excluded with skip_render. There is a discussion about it: #1591 I'm closing this issue. Please join the discussion there :)