curbengh / hexo-nofollow

Adds nofollow attribute to all external links in your hexo blog posts automatically.
MIT License
1 stars 0 forks source link

the problem when i hexo deploy #4

Closed jerryc127 closed 5 years ago

jerryc127 commented 5 years ago

image the gulpfile.js

    minifycss = require('gulp-clean-css');
    uglify = require('gulp-uglify');
    htmlmin = require('gulp-htmlmin');
    htmlclean = require('gulp-htmlclean');
    imagemin = require('gulp-imagemin');
    terser = require('gulp-terser');

// 压缩 public 目录内 css
gulp.task('minify-css', function() {
    return gulp.src('./public/**/*.css')
        .pipe(minifycss({
           advanced: true,//类型:Boolean 默认:true [是否开启高级优化(合并选择器等)]
           compatibility: 'ie7',//保留ie7及以下兼容写法 类型:String 默认:''or'*' [启用兼容模式; 'ie7':IE7兼容模式,'ie8':IE8兼容模式,'*':IE9+兼容模式]
           keepBreaks: false,//类型:Boolean 默认:false [是否保留换行]
           keepSpecialComments: '*'
           //保留所有特殊前缀 当你用autoprefixer生成的浏览器前缀,如果不加这个参数,有可能将会删除你的部分前缀
        }))
        .pipe(gulp.dest('./public'));
});

// 压缩 public 目录内 html
gulp.task('minify-html', function() {
  return gulp.src('./public/**/*.html')
    .pipe(htmlclean())
    .pipe(htmlmin({
        removeComments: true,//清除 HTML 注释
        collapseWhitespace: true,//压缩 HTML
        collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
        removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
        removeScriptTypeAttributes: true,//删除 <script> 的 type="text/javascript"
        removeStyleLinkTypeAttributes: true,//删除 <style> 和 <link> 的 type="text/css"
        minifyJS: true,//压缩页面 JS
        minifyCSS: true//压缩页面 CSS
    }))
    .pipe(gulp.dest('./public'))
});

// 压缩 public/js 目录内 js
// gulp.task('minify-js', function () {
//     return gulp.src(['./public/**/*.js', '!./public/**/*.min.js'])
//         .pipe(babel({ presets: ['es2015'] }))
//         .pipe(uglify())
//         .pipe(gulp.dest('./public'));
// });

gulp.task('es', function () {
    return gulp.src(['./public/**/*.js', '!./public/**/*.min.js'])
        .pipe(terser())
        .pipe(gulp.dest('./public'));
});

// 压缩 public/uploads 目录内图片
gulp.task('minify-images', function() {
    gulp.src('./public/img/**/*.*')
        .pipe(imagemin({
           optimizationLevel: 5, //类型:Number  默认:3  取值范围:0-7(优化等级)
           progressive: true, //类型:Boolean 默认:false 无损压缩jpg图片
           interlaced: false, //类型:Boolean 默认:false 隔行扫描gif进行渲染
           multipass: false, //类型:Boolean 默认:false 多次优化svg直到完全优化
        }))
        .pipe(gulp.dest('./public/img'));
});

// 执行 gulp 命令时执行的任务
gulp.task('default', [
    'minify-html','minify-css','minify-images','es'
]);

// var gulp = require('gulp');
// var minifycss = require('gulp-minify-css');
// var uglify = require('gulp-uglify');
// var htmlmin = require('gulp-htmlmin');
// var htmlclean = require('gulp-htmlclean');
// // 获取 gulp-imagemin 模块
// var imagemin = require('gulp-imagemin')
// // 压缩 public(hexo编译后存放静态网站的文件))目录 下的css 
// gulp.task('minify-css', function() {
//     return gulp.src('./public/**/*.css')
//         .pipe(minifycss())
//         .pipe(gulp.dest('./public'));
// });
// // 压缩 public 目录下的 html 资源
// gulp.task('minify-html', function() {
//     return gulp.src('./public/**/*.html')
//         .pipe(htmlclean())
//         .pipe(htmlmin({
//             removeComments: true,
//             minifyJS: true,
//             minifyCSS: true,
//             minifyURLs: true,
//         }))
//         .pipe(gulp.dest('./public'))
// });
// // 压缩 public/js 目录下 js 资源
// gulp.task('minify-js', function() {
//     return gulp.src('./public/**/*.js')
//         .pipe(uglify())
//         .pipe(gulp.dest('./public'));
// });
// // 压缩图片任务,在命令行输入 gulp images 启动此任务
// gulp.task('images', function () {
//     // 1. 找到图片
//     gulp.src('./images/*.*')
//     // 2. 压缩图片
//         .pipe(imagemin({
//             progressive: true
//         }))
//         // 3. 另存图片
//         .pipe(gulp.dest('./images/*.*'))
// });
// // 执行 gulp 命令时执行的任务
// gulp.task('default', [
//     'minify-html','minify-css','minify-js','images'
// ]);
// // 默认任务
// gulp.task("watch",function() {
//     gulp.watch("public/*",["default"]);
// });
curbengh commented 5 years ago

are you using gulp v4? note gulp v4 uses gulp.series and gulp.parallel. see https://github.com/hexojs/site/pull/946 and https://fettblog.eu/gulp-4-parallel-and-series/ what is the installed version of gulp (npm ls --depth 0)? attach your package.json as well.

if you use gulp v4, update the syntax by replacing the following lines:

gulp.task('default', [
    'minify-html','minify-css','minify-images','es'
]);

to

gulp.task('default',
    gulp.parallel('minify-html','minify-css','minify-images','es'
));

btw, I wrote a minify assets plugin (hexo-yam). It also compresses them to gzip and brotli. But it doesn't support image compression though.

jerryc127 commented 5 years ago
{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.8.0"
  },
  "dependencies": {
    "gulp": "^3.9.1",
    "gulp-clean-css": "^3.10.0",
    "gulp-htmlclean": "^2.7.22",
    "gulp-htmlmin": "^4.0.0",
    "gulp-imagemin": "^5.0.3",
    "gulp-minify-css": "^1.2.4",
    "gulp-uglify": "^3.0.2",
    "hexo": "^3.2.0",
    "hexo-abbrlink": "^2.0.5",
    "hexo-algolia": "^1.3.1",
    "hexo-asset-image": "0.0.3",
    "hexo-deployer-git": "^1.0.0",
    "hexo-generator-archive": "^0.1.4",
    "hexo-generator-baidu-sitemap": "^0.1.2",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-feed": "^1.2.2",
    "hexo-generator-index-pin-top": "^0.2.2",
    "hexo-generator-search": "^2.2.5",
    "hexo-generator-sitemap": "^1.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-nofollow": "^1.0.6",
    "hexo-offline": "^1.0.0",
    "hexo-renderer-ejs": "^0.3.0",
    "hexo-renderer-jade": "^0.4.1",
    "hexo-renderer-less": "^1.0.0",
    "hexo-renderer-marked": "^0.3.0",
    "hexo-renderer-stylus": "^0.3.3",
    "hexo-server": "^0.2.0",
    "hexo-tag-aplayer": "^3.0.4",
    "hexo-wordcount": "^3.0.2"
  },
  "scripts": {
    "push": "hexo clean & hexo algolia && hexo g && gulp && hexo deploy",
    "show": "hexo clean && hexo g && hexo s",
    "update": "git init && git add . && git commit -m 'update' && git push -u origin master"
  },
  "devDependencies": {
    "gulp-terser": "^1.1.7"
  }
}

i use gulp v3

curbengh commented 5 years ago

do you know the source of the html code in your screenshot? run hexo g without gulp and look for anomaly in the generated html.

jerryc127 commented 5 years ago

the html code in the screensho: view-source:https://jerryc.me/posts/125d29fb/

the hexo deploy is work when i run without gulp

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\Jerry\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'push' ]
2 info using npm@6.9.0
3 info using node@v10.15.1
4 verbose run-script [ 'prepush', 'push', 'postpush' ]
5 info lifecycle hexo-site@0.0.0~prepush: hexo-site@0.0.0
6 info lifecycle hexo-site@0.0.0~push: hexo-site@0.0.0
7 verbose lifecycle hexo-site@0.0.0~push: unsafe-perm in lifecycle true
8 verbose lifecycle hexo-site@0.0.0~push: PATH: C:\Users\Jerry\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\JerryBlog\node_modules\.bin;C:\Users\Jerry\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Jerry\bin;C:\Program Files\Java\jdk1.8.0_201\bin;C:\Program Files\Java\jdk1.8.0_201\jre\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;%SYSTEMROOT%\System32\OpenSSH;C:\Users\Jerry\AppData\Local\Microsoft\WindowsApps;C:\Users\Jerry\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Jerry\AppData\Roaming\npm;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle hexo-site@0.0.0~push: CWD: D:\JerryBlog
10 silly lifecycle hexo-site@0.0.0~push: Args: [ '/d /s /c',
10 silly lifecycle   'hexo clean & hexo algolia && hexo g && gulp && hexo deploy' ]
11 silly lifecycle hexo-site@0.0.0~push: Returned: code: 1  signal: null
12 info lifecycle hexo-site@0.0.0~push: Failed to exec push script
13 verbose stack Error: hexo-site@0.0.0 push: `hexo clean & hexo algolia && hexo g && gulp && hexo deploy`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\Jerry\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:189:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\Jerry\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:189:13)
13 verbose stack     at maybeClose (internal/child_process.js:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid hexo-site@0.0.0
15 verbose cwd D:\JerryBlog
16 verbose Windows_NT 10.0.18898
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Jerry\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "push"
18 verbose node v10.15.1
19 verbose npm  v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error hexo-site@0.0.0 push: `hexo clean & hexo algolia && hexo g && gulp && hexo deploy`
22 error Exit status 1
23 error Failed at the hexo-site@0.0.0 push script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
curbengh commented 5 years ago

Since the page contains xml, I think the issue could be similar to #3 and https://github.com/cheeriojs/cheerio/issues/1198 .

To better pinpoint the issue:

  1. Try hexo-autonofollow which uses older version of cheerio.

  2. Upgrade gulp to v4 and use gulp.series to find out which gulp task failed, Replace

    gulp.task('default', [
    'minify-html','minify-css','minify-images','es'
    ]);

    with

    gulp.task('default',
    gulp.series('minify-html','minify-css','minify-images','es'
    ));
  3. Try hexo-yam, you need to remove 'minify-html', 'minify-css' and 'es' gulp task.

  4. Attach the source .md file of https://jerryc.me/posts/125d29fb/ , and I'll try to replicate.

curbengh commented 5 years ago

From the screenshot, I just noticed there is an extra < in <<span class. This might be your typo or added by this plugin. Usually minifier would throw an error if there is any invalid syntax.

Can you check the generated index.html of that post? I don't find the typo in https://jerryc.me/posts/125d29fb/, but the html is already minified?

jerryc127 commented 5 years ago

the extra < in <<span class image

the error image image

image

i sure the html is already minified

jerryc127 commented 5 years ago

i try to use the https://github.com/liuzc/hexo-autonofollow it work for me.

this is the .md file of https://jerryc.me/posts/125d29fb/ https://drive.google.com/file/d/1e4moJWfINF0j1nhgv8gTNwqEi6yPRHf7/view?usp=sharing

curbengh commented 5 years ago

I meant I expected the html not to be minified if gulp is skipped. Anyway, I requested access from j***@gmail.com

Edit: I can reproduce with

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >

    <Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="button 1"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button 2"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button 3"
        />
curbengh commented 5 years ago

the bracket is supposed to be escaped (in the generated html),

&lt;<span class="name">LinearLayout</span>

I used this workaround https://github.com/cheeriojs/cheerio/issues/1198#issuecomment-481589878.

Edit: I just tested with hexo-yam, which includes html-minifier. It worked.

Edit: https://github.com/cheeriojs/dom-serializer/pull/80 looks promising.

jerryc127 commented 5 years ago

sorry,I'm not good at English. it mean? how i solve this problem?

curbengh commented 5 years ago

I'm trying to figure out should I default decodeEntities to true instead. When I use this fix (https://github.com/cheeriojs/dom-serializer/pull/80) and set decodeEntities to false:

&amp;amp;amp;lt;!-- some mandarin comment 取值范围 --&amp;amp;amp;gt;
&amp;amp;amp;lt;LinearLayout xmlns:android=&amp;amp;quot;http://schemas.android.com/apk/res/android&amp;amp;quot;
    android:layout_width=&amp;amp;quot;match_parent&amp;amp;quot;
    android:layout_height=&amp;amp;quot;match_parent&amp;amp;quot;
    android:orientation=&amp;amp;quot;horizontal&amp;amp;quot;
    &amp;amp;amp;gt;


If I set to true:

<!-- some mandarin comment 取值范围 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >
curbengh commented 5 years ago

I put together a small change so you can test https://github.com/cheeriojs/dom-serializer/pull/80 easily, replace the relevant line in package.json to:

    "hexo-nofollow": "weyusi/hexo-nofollow#decode-test",

@momocow can you help to test this too?

Edit: you might encounter this issue https://stackoverflow.com/q/27356915, just make sure the installed modules do not have '.git' folder.

jerryc127 commented 5 years ago

image

when hexo deploy, it work.

curbengh commented 5 years ago

no issue even with gulp? check for any unusual symbols in the generated html. I can release an alpha version in the meantime.

jerryc127 commented 5 years ago

no issue even with gulp? yes