Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 具有Gulp数据的拼接路径_Json_Gulp_Yaml Front Matter_Gulp Data - Fatal编程技术网

Json 具有Gulp数据的拼接路径

Json 具有Gulp数据的拼接路径,json,gulp,yaml-front-matter,gulp-data,Json,Gulp,Yaml Front Matter,Gulp Data,如何使用gulp数据获取父文件夹的名称?目前我正在使用以下工具: 在我面前 从我的吞咽文件: 它将以下内容输出到new.json 我不知道如何只获取文件的父文件夹,使relative成为“relative”:“lesson01”和“relative”:“lesson02”这不是最有效的方法。如果这对任何人都有帮助,这就是我的结局 function fm2json() { return gulp.src('src/pages/**/*.html') .pipe(require('gul

如何使用gulp数据获取父文件夹的名称?目前我正在使用以下工具:

在我面前

从我的吞咽文件:

它将以下内容输出到new.json


我不知道如何只获取文件的父文件夹,使
relative
成为
“relative”:“lesson01”
“relative”:“lesson02”
这不是最有效的方法。如果这对任何人都有帮助,这就是我的结局

function fm2json() {
  return gulp.src('src/pages/**/*.html')
    .pipe(require('gulp-gray-matter')())
    .pipe($.data(function(file){

        // What I ended up with
        var relpath = file.relative;
        var path    = relpath.replace(/\\/g,"/"); //flip slashes
        var split   = path.split('/'); //split the path into an array
        var parent  = split[split.length - 2]; // find the array position

        file.data.parent = parent,
        file.data.file   = file.basename,
        file.data.path   = path,

    }))
    .pipe($.pluck('data', 'new.json'))
    .pipe($.data(function(file){
      file.contents = new Buffer(JSON.stringify(file.data))
    }))
    .pipe(require('gulp-json-format')(2))
    .pipe(gulp.dest('src/data'));
}
function fm2json() {
  return gulp.src('src/pages/**/*.html')
    .pipe(require('gulp-gray-matter')())
    .pipe($.data(function(file){
      file.data.relative = file.relative,
      file.data.basename = file.basename,
    }))
    .pipe($.pluck('data', 'new.json'))
    .pipe($.data(function(file){
      file.contents = new Buffer(JSON.stringify(file.data))
    }))
    .pipe(require('gulp-json-format')(2))
    .pipe(gulp.dest('src/data'));
}
[
  {
    "title":"some title" 
    "relative":"lesson01\\file.html" 
    "basename":"file.html" 
  },
  {
    "title":"some title 2" 
    "relative":"lesson02\\file2.html" 
    "basename":"file2.html" 
  }
]
function fm2json() {
  return gulp.src('src/pages/**/*.html')
    .pipe(require('gulp-gray-matter')())
    .pipe($.data(function(file){

        // What I ended up with
        var relpath = file.relative;
        var path    = relpath.replace(/\\/g,"/"); //flip slashes
        var split   = path.split('/'); //split the path into an array
        var parent  = split[split.length - 2]; // find the array position

        file.data.parent = parent,
        file.data.file   = file.basename,
        file.data.path   = path,

    }))
    .pipe($.pluck('data', 'new.json'))
    .pipe($.data(function(file){
      file.contents = new Buffer(JSON.stringify(file.data))
    }))
    .pipe(require('gulp-json-format')(2))
    .pipe(gulp.dest('src/data'));
}