serve-index icon indicating copy to clipboard operation
serve-index copied to clipboard

The `directory.html` template should be added in `locals`

Open ghuser opened this issue 6 years ago • 3 comments

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).

ghuser avatar Oct 21 '19 11:10 ghuser

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?

dougwilson avatar Mar 15 '21 17:03 dougwilson

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());
} 

ghuser avatar Mar 18 '21 10:03 ghuser

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)); }

melissawood123 avatar Dec 04 '21 00:12 melissawood123