Skip to content

Commit 93e0cbe

Browse files
authored
refactor: remove mustache (#361)
* refactor: remove mustache * chore: oops * chore: oops * fix: use replacer fn
1 parent 0b65acc commit 93e0cbe

File tree

4 files changed

+10
-22
lines changed

4 files changed

+10
-22
lines changed

package-lock.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"hastscript": "^9.0.1",
6161
"lightningcss": "^1.30.1",
6262
"mdast-util-slice-markdown": "^2.0.1",
63-
"mustache": "^4.2.0",
6463
"preact": "^10.26.9",
6564
"preact-render-to-string": "^6.5.13",
6665
"reading-time": "^1.5.0",

src/generators/web/template.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
</head>
1919

2020
<body>
21-
<div id="root">{{{dehydrated}}}</div>
22-
<script>{{{javascript}}}</script>
21+
<div id="root">{{dehydrated}}</div>
22+
<script>{{clientBundleJs}}</script>
2323
</body>
24-
25-
</html>
24+
</html>

src/generators/web/utils/processing.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import HTMLMinifier from '@minify-html/node';
22
import { toJs, jsx } from 'estree-util-to-js';
3-
import Mustache from 'mustache';
43

54
import bundleCode from './bundle.mjs';
65

@@ -72,12 +71,13 @@ export async function processJSXEntry(
7271
const clientCode = buildClientProgram(code);
7372
const clientBundle = await bundleCode(clientCode);
7473

75-
// TODO(@avivkeller): Don't depend on Mustache
76-
const renderedHtml = Mustache.render(template, {
77-
title: `${entry.data.heading.data.name} | Node.js v${version} Documentation`,
78-
dehydrated,
79-
javascript: clientBundle.js,
80-
});
74+
const title = `${entry.data.heading.data.name} | Node.js v${version} Documentation`;
75+
76+
// Replace template placeholders with actual content
77+
const renderedHtml = template
78+
.replace('{{title}}', title)
79+
.replace('{{dehydrated}}', dehydrated ?? '')
80+
.replace('{{clientBundleJs}}', () => clientBundle.js);
8181

8282
// The input to `minify` must be a Buffer.
8383
const finalHTMLBuffer = HTMLMinifier.minify(Buffer.from(renderedHtml), {});

0 commit comments

Comments
 (0)