mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-24 20:17:50 +02:00
refactor(v2): precompile ETA templates (#3238)
* compile ETA templates ahead of time * handle PR review
This commit is contained in:
parent
51f07608fa
commit
d17df954b5
3 changed files with 50 additions and 22 deletions
|
@ -11,6 +11,16 @@ const eta = require('eta');
|
|||
const {normalizeUrl} = require('@docusaurus/utils');
|
||||
const openSearchTemplate = require('./templates/opensearch');
|
||||
const {validateThemeConfig} = require('./validateThemeConfig');
|
||||
const {memoize} = require('lodash');
|
||||
|
||||
const getCompiledOpenSearchTemplate = memoize(() => {
|
||||
return eta.compile(openSearchTemplate.trim());
|
||||
});
|
||||
|
||||
function renderOpenSearchTemplate(data) {
|
||||
const compiled = getCompiledOpenSearchTemplate();
|
||||
return compiled(data, eta.defaultConfig);
|
||||
}
|
||||
|
||||
const OPEN_SEARCH_FILENAME = 'opensearch.xml';
|
||||
|
||||
|
@ -44,13 +54,14 @@ function theme(context) {
|
|||
try {
|
||||
fs.writeFileSync(
|
||||
path.join(outDir, OPEN_SEARCH_FILENAME),
|
||||
eta.render(openSearchTemplate.trim(), {
|
||||
renderOpenSearchTemplate({
|
||||
title,
|
||||
url,
|
||||
favicon: normalizeUrl([url, favicon]),
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
throw new Error(`Generating OpenSearch file failed: ${err}`);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue