Support snippets.html again

This commit is contained in:
Alex Gleason 2023-09-18 19:14:23 -05:00
parent 199d5d9f37
commit 95b7c62f67
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 17 additions and 1 deletions

View File

@ -8,6 +8,7 @@
<link href="/manifest.json" rel="manifest">
<!--server-generated-meta-->
<script type="module" src="./src/main.tsx"></script>
<%- snippets %>
</head>
<body class="theme-mode-light no-reduce-motion">
<div id="soapbox" class="h-full">

View File

@ -1,4 +1,5 @@
/// <reference types="vitest" />
import fs from 'node:fs';
import { fileURLToPath, URL } from 'node:url';
import react from '@vitejs/plugin-react';
@ -36,6 +37,11 @@ export default defineConfig({
collapseWhitespace: true,
removeComments: false,
},
inject: {
data: {
snippets: readFileContents('custom/snippets.html'),
},
},
}),
react({
// Use React plugin in all *.jsx and *.tsx files
@ -88,4 +94,13 @@ export default defineConfig({
environment: 'jsdom',
setupFiles: 'src/jest/test-setup.ts',
},
});
});
/** Return file as string, or return empty string if the file isn't found. */
function readFileContents(path: string) {
try {
return fs.readFileSync(path, 'utf8');
} catch {
return '';
}
}