Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export const audioUrls: EnvironmentConfig<string> = {
development: "https://englitune-audio.silvioprog.dev", // We don't have an audio server for development
production: "https://englitune-audio.silvioprog.dev"
} as const;

export const cloudflareInsightsUrls: EnvironmentConfig<string> = {
development: "https://static.cloudflareinsights.com",
production: "https://static.cloudflareinsights.com"
} as const;
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
name="google-site-verification"
content="Ys_-H_ECtl1NzD6phA7tRa8x1IUgtMacH5crbKZw3GY"
/>
<link rel="preconnect" href="__CLOUDFLARE_INSIGHTS_URL__" />
<link rel="preconnect" href="__AUDIO_URL__" />
<title>__DISPLAY_NAME__</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script
defer
src="https://static.cloudflareinsights.com/beacon.min.js"
src="__CLOUDFLARE_INSIGHTS_URL__/beacon.min.js"
data-cf-beacon='{"token": "e51c6301a11946c3b28aa5187d08e640"}'
></script>
</body>
Expand Down
37 changes: 27 additions & 10 deletions vite-plugins/html.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import { type Plugin } from "vite";

import { displayName, description, homepage } from "../package.json";
import {
audioUrls,
cloudflareInsightsUrls,
type Environment
} from "../env.config";

const html = (): Plugin => ({
name: "html",
transformIndexHtml(html) {
return html
.replace(/__DISPLAY_NAME__/g, displayName)
.replace(/__DESCRIPTION__/g, description)
.replace(/__HOME_URL__/g, homepage)
.replace(/__SCREENSHOT_URL__/g, `${homepage}/screenshot.png`);
}
});
const html = (): Plugin => {
let mode: Environment = "development";

return {
name: "html",
config(_config, { mode: configMode }) {
mode = configMode as Environment;
},
transformIndexHtml(html) {
const audioUrl = audioUrls[mode];
const cloudflareInsightsUrl = cloudflareInsightsUrls[mode];

return html
.replace(/__DISPLAY_NAME__/g, displayName)
.replace(/__DESCRIPTION__/g, description)
.replace(/__HOME_URL__/g, homepage)
.replace(/__SCREENSHOT_URL__/g, `${homepage}/screenshot.png`)
.replace(/__AUDIO_URL__/g, audioUrl)
.replace(/__CLOUDFLARE_INSIGHTS_URL__/g, cloudflareInsightsUrl);
}
};
};

export default html;