gpt4 book ai didi

javascript - Jade to HTML > 以jade文件命名的目录中的index.html

转载 作者:行者123 更新时间:2023-11-28 18:55:15 26 4
gpt4 key购买 nike

我有一个简单的 gulp 任务,它将 .jade 文件编译为 .html 文件:

var gulp = require('gulp'),
jade = require('gulp-jade');

gulp.task('jade', function() {
return gulp.src('src/templates/**/*.jade')
.pipe(jade()) // pip to jade plugin
.pipe(gulp.dest('public')); // tell gulp our output folder
});

问题

/src/templates/page.jade 在目标位置编译为 HTML /public/page.html

我如何获取它,以便将 /src/templates/page.jade 编译为 /public/page/index.html

templates中的每个新的jade文件都会被编译为一个名为index.html的html文件,该文件位于与源jade文件同名的目录中?

示例

/src/templates/about.jade >> /public/about/index.html

/src/templates/contact.jade >> /public/contact/index.html

/src/templates/features.jade >> /public/features/index.html

最佳答案

如果您想包含子目录,可以使用:

    .pipe(rename(function(path){             
if(path.basename != 'index')
{
var crumbs = path.dirname.split('/')
crumbs.push(path.basename)

path.basename = 'index'
path.extname = '.html'

path.dirname = crumbs.join('/')
}

return path
}))

我已经在前端问题解决方案中成功地使用了它。不要忘记在 gulp.src 中的/*.filetype 之前包含/**

关于javascript - Jade to HTML > 以jade文件命名的目录中的index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33732924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com