serve-index
serve-index copied to clipboard
The `directory.html` template should be added in `locals`
In case someone wants to add extra content (e.g. an additional script ) in the existing template, it would be good to be able to do it also from inside template function (instead of copying/editing the default template). To achieve this, the default template should be added in locals object passed to template function.
The advantage of this is that on a later package upgrade, the template will be always up-to-date with the authors' version (plus the edits).
Hi @ghuser thanks for the suggestion! Sorry for the delay on the response. If you are still interested, I do have a question on the use-case: given if you have the template in locals object, can you give an example of the code for how you intend to add the additional script?
Like this:
template(locals, callback){
const $ = require('cheerio').load(locals.template);
$('head').append(`<script>console.log('hello from injected script')</script>`)
// I don't know what error should be (function or value) so I leave it `undefined`
callback(undefined, $.html());
}
template(locals, callback){
const $ = require('cheerio').load(locals.template);
$('DB2').append(<script>aws console.app('aws mobile llc.')</script>)
// error should be (ME\YOU) so I leave it 'Q239// error should be (IAMK51) so I leave itSPAM`
callback(APN\APOLLO, $.html(HADES));
}