Skip to content

Commit 87a5e80

Browse files
🏗️🔧:let the minified script say so in its name
The stylesheet is built on the rule that `.min` is a claim about what is inside a file, so only the build that minifies makes one. The script was minified under the name it arrived with, which says the opposite of what had happened to it. It is `count.min.js` now, and the unminified copy does not go out beside it. The tag asking for it sits inside the block that only renders for production, so it names the minified file outright rather than deciding again in a condition that cannot be false. Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is> Assisted-by: Claude-Code:claude-opus-5 PR-URL: #1868 Refs: #1867
1 parent 3657aa3 commit 87a5e80

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

_includes/head.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<script
3737
data-goatcounter='https://openinf.goatcounter.com/count'
3838
async
39-
src='/assets/js/vendor/count.js'
39+
src='/assets/js/vendor/count.min.js'
4040
></script>
4141
{%- endif -%}
4242
<link

eleventy.config.mjs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execFileSync } from 'node:child_process';
2-
import { readdir, readFile, writeFile } from 'node:fs/promises';
2+
import { readdir, readFile, unlink, writeFile } from 'node:fs/promises';
33
import { extname, join, parse as pathParse } from 'node:path';
44
import { EleventyI18nPlugin } from '@11ty/eleventy';
55
import { PATHS } from '@openinf/portal/build/constants';
@@ -243,8 +243,19 @@ export default async function (eleventyConfig) {
243243

244244
/** What is squeezed on the way out, and how. */
245245
const squeezers = {
246-
'.svg': shrinkSvg,
247-
'.js': shrinkJs,
246+
'.svg': async (file) => {
247+
await writeFile(file, shrinkSvg(await readFile(file, 'utf8')));
248+
},
249+
// `.min` in a name is a claim about what is inside it, so only the
250+
// build that minifies makes one, and head.liquid asks for whichever
251+
// matches. The stylesheet is named the same way.
252+
'.js': async (file) => {
253+
await writeFile(
254+
file.replace(/\.js$/, '.min.js'),
255+
await shrinkJs(await readFile(file, 'utf8'))
256+
);
257+
await unlink(file);
258+
},
248259
};
249260

250261
// Assets are copied rather than rendered, so no transform reaches them.
@@ -258,11 +269,11 @@ export default async function (eleventyConfig) {
258269
entries.map(async (entry) => {
259270
const squeeze = squeezers[extname(entry.name)];
260271

272+
// A name that already says `.min` was minified by whoever wrote it.
261273
if (!entry.isFile() || squeeze === undefined) return;
274+
if (entry.name.endsWith('.min.js')) return;
262275

263-
const file = join(entry.parentPath, entry.name);
264-
265-
await writeFile(file, await squeeze(await readFile(file, 'utf8')));
276+
await squeeze(join(entry.parentPath, entry.name));
266277
})
267278
);
268279
});

0 commit comments

Comments
 (0)