Something like archive pages on WordPress blogs. I'm using this gulp script it can generate multiple pages but can show only once when it runs the server and open the page in the browser.
server: {
baseDir: "./output",
index: "test-template.html"
},
I want test-template.html should have links of
templateA.html templateB.html templateC.html
so in the browser instead remembering and typing URL of these files I can just open by clicking on the link on index.html page
Is there any plugin to do this?
There are two packages that may be helpfull. Please double check task configs, to target your paths.
https://www.npmjs.com/package/gulp-inject
Workflow looks pretty same as above.
<!-- inject:html -->
<!-- endinject -->
var inject = require('gulp-inject');
gulp.src('test-template.html')
.pipe(inject(
gulp.src(['templates/*.html'], { read: false }), {
transform: function (filepath) {
if (filepath.slice(-5) === '.html') {
return '<li><a href="' + filepath + '">' + filepath + '</a></li>';
}
// Use the default transform as fallback:
return inject.transform.apply(inject.transform, arguments);
}
}
))
.pipe(gulp.dest('./'));
https://www.npmjs.com/package/gulp-linker
Create gulp task and inside test-template.html insert defined html comments (between this comments the tmpl will be inserted).
<!--LINKS-->
<!--LINKS END-->
var linker = require('gulp-linker'),
// Read templates
gulp.src('test-template.html')
// Link the JavaScript
.pipe(linker({
scripts: [ "templates/*.html" ],
startTag: '<!--LINKS-->',
endTag: '<!--LINKS END-->',
fileTmpl: '<a href="%s">%s</a>',
appRoot: 'www/'
}))
// Write modified files to www/
.pipe(gulp.dest('www/'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With