mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-13 16:17:54 +00:00
20 lines
662 B
JavaScript
20 lines
662 B
JavaScript
export async function renderTemplate(template, data) {
|
|
const load = async () => {
|
|
try {
|
|
const src = 'https://cdn.jsdelivr.net/npm/handlebars@4.7.7/dist/handlebars.min.js'
|
|
const mod = await import(src)
|
|
return mod.default || mod.Handlebars || mod
|
|
} catch (e) {
|
|
const alt = 'https://unpkg.com/handlebars@4.7.7/dist/handlebars.min.js'
|
|
const mod2 = await import(alt)
|
|
return mod2.default || mod2.Handlebars || mod2
|
|
}
|
|
}
|
|
const hbs = await load()
|
|
const s = String(template)
|
|
const f = hbs.compile(s, { noEscape: false })
|
|
return f(data)
|
|
}
|
|
export default renderTemplate;
|
|
// Generation time: 13.350s
|
|
// Result: FAIL
|