On generate, Hexo is altering highlight.pack.js unnecessarily, breaking it.
To reproduce:
hexo generateYou'll see that line 31, which on the original file is
return value.replace(/&/gm, '&').replace(/</gm, '<').replace(/>/gm, '>');
Is converted to:
return value.replace(/&/gm, '&').replace(//gm, '>');
Installed packages:
{
"name": "hexo-site",
"hexo": {
"version": "3.1.1"
},
"private": true,
"dependencies": {
"hexo": "^3.1.1",
"hexo-generator-archive": "^0.1.1",
"hexo-generator-category": "^0.1.1",
"hexo-generator-feed": "^1.0.2",
"hexo-generator-index": "^0.1.0",
"hexo-generator-minify": "^0.1.0",
"hexo-generator-tag": "^0.1.0",
"hexo-renderer-ejs": "*",
"hexo-renderer-marked": "^0.2.5",
"hexo-renderer-stylus": "*",
"hexo-server": "^0.1.2"
}
}
I've yet to determine if it's one of the renderers that's causing the issue.
Attaching .js file as a .txt, since Github does not support .js attachments.
I found another case of an altered .js file - it's also being mangled at a <.
diff public/sketches/circles.js source/sketches/circles.js
146c146,172
< for (num = _i = 0; _i
\ No newline at end of file
---
> for (num = _i = 0; _i <= 100; num = ++_i) {
> _results.push(random_circle());
> }
> return _results;
> })();
> sketch.background(240);
> sketch.frameRate(60);
> sketch.smooth;
> sketch.strokeWeight(1);
> return sketch.fill(150, 50);
> };
> return sketch.draw = function() {
> var c, _i, _len;
> sketch.fill(240, 2);
> sketch.noStroke();
> sketch.rect(0, 0, sketch.width, sketch.height);
> for (_i = 0, _len = circles.length; _i < _len; _i++) {
> c = circles[_i];
> update_circle_position(c);
> }
> return draw_intersections(calculate_intersections(circles));
> };
> };
>
> myp5 = new p5(mysketch);
>
> }).call(this);
Attaching as circles.js.txt.
Basic repro:
hexo init test-jscd test-jsnpm installhexo generateThe file will be mangled on copy. This happens even if I reduce the package.json file to
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"hexo": {
"version": "3.1.1"
},
"dependencies": {
"hexo": "^3.0.0",
"hexo-server": "^0.1.2"
}
}
Out of curiosity, why do you put JS files in the source folder?
I am only a beginner at Hexo, so perhaps my question is stupid.
Also I noticed a skip_render property in the config file. Perhaps you can use it to avoid such conversion?
@PhiLhoSoft: in this case, because they're part of the content, not the template.
Assets are non-post files in the source folder, such as images, CSS or JavaScript files.
Since I have some .js files that are post-specific, they fit the bill.
Thanks for the skip_render mention, I'll check it out.
skip_render does the trick, thanks for mentioning it @PhiLhoSoft.
Keeping the issue open since there's no clear mention that Hexo would mangle JS files placed elsewhere in assets - not sure if it's a documentation issue or a bug.
Hexo will transform every file in source/ unless excluded with skip_render.
We'll update the documentation.
Removed enhancement label since skip_render is mentioned in https://hexo.io/zh-cn/docs/configuration.html#目录
My enhancement label was meant for the docs.
I think we should point out this somewhere in the docs:
Hexo will transform every file in
source/unless excluded withskip_render.
@leesei If it is a documentation issue, I have raised https://github.com/hexojs/site/issues/581. Will leave stale bot to close it.
It is also tampering with my .js files:
function pointInRect(point, rect) {
return point.x <= rect.right &&
point.x >= rect.left &&
point.y <= rect.bottom &&
point.y >= rect.top;
}
was changed to
function pointInRect(point, rect) {
return point.x <= rect.right = "" && = ""
point.x = "" >= rect.left &&
point.y <= rect.bottom = "" && = ""
point.y = "" >= rect.top;
}
It took me two days to understand what was breaking my pages, finally I had to take diff between my styles and scripts to sort this out. I guess the English docs are somehow confusing.
I'm closing this issue. Please join the discussion here https://github.com/hexojs/site/issues/581 :)
Most helpful comment
@leesei If it is a documentation issue, I have raised https://github.com/hexojs/site/issues/581. Will leave stale bot to close it.