From c0a915b68f47b887cade30e2a53459a5d5281012 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Tue, 17 Jun 2025 00:25:18 -0400 Subject: [PATCH] cache busting: Import version, changelog (#1201) Import version, changelog statically using webpack for cache busting purposes. - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- resources/lang/en.json | 2 ++ src/client/Main.ts | 8 ++------ src/client/NewsModal.ts | 18 ++++++++++++++++++ src/global.d.ts | 4 ++++ webpack.config.js | 4 ++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/resources/lang/en.json b/resources/lang/en.json index c4b1a6d45..d92b71abd 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -24,6 +24,8 @@ "wiki": "Wiki" }, "news": { + "full_changelog": "See the complete change log", + "github_link": "on GitHub", "title": "Version 23 released!" }, "help_modal": { diff --git a/src/client/Main.ts b/src/client/Main.ts index ea0b203fd..9b98d76f3 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -1,5 +1,6 @@ import page from "page"; import favicon from "../../resources/images/Favicon.svg"; +import version from "../../resources/version.txt"; import { consolex } from "../core/Consolex"; import { GameRecord, GameStartInfo } from "../core/Schemas"; import { getServerConfigFromClient } from "../core/configuration/ConfigLoader"; @@ -84,9 +85,7 @@ class Client { if (!gameVersion) { console.warn("Game version element not found"); } - fetch("/version.txt") - .then((response) => (response.ok ? response.text() : "Failed to load")) - .then((version) => (gameVersion.innerText = version)); + gameVersion.innerText = version; const newsModal = document.querySelector("news-modal") as NewsModal; if (!newsModal) { @@ -101,9 +100,6 @@ class Client { } else { consolex.log("News button element found"); } - fetch("/changelog.md") - .then((response) => (response.ok ? response.text() : "Failed to load")) - .then((changelog) => (newsModal.markdown = changelog)); // Comment out to show news button. // newsButton.hidden = true; diff --git a/src/client/NewsModal.ts b/src/client/NewsModal.ts index 738481491..d3924e655 100644 --- a/src/client/NewsModal.ts +++ b/src/client/NewsModal.ts @@ -1,6 +1,7 @@ import { LitElement, css, html } from "lit"; import { resolveMarkdown } from "lit-markdown"; import { customElement, property, query } from "lit/decorators.js"; +import changelog from "../../resources/changelog.md"; import { translateText } from "../client/Utils"; import "./components/baseComponents/Button"; import "./components/baseComponents/Modal"; @@ -14,6 +15,8 @@ export class NewsModal extends LitElement { @property({ type: String }) markdown = "Loading..."; + private initialized: boolean = false; + static styles = css` :host { display: block; @@ -62,6 +65,15 @@ export class NewsModal extends LitElement { +
+ ${translateText("news.full_changelog")} + ${translateText("news.github_link")}. +
+ (response.ok ? response.text() : "Failed to load")) + .then((markdown) => (this.markdown = markdown)); + } this.requestUpdate(); this.modalEl?.open(); } diff --git a/src/global.d.ts b/src/global.d.ts index d0380a773..e100dde8e 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -24,6 +24,10 @@ declare module "*.bin" { const value: string; export default value; } +declare module "*.md" { + const value: string; + export default value; +} declare module "*.txt" { const value: string; export default value; diff --git a/webpack.config.js b/webpack.config.js index 3f6d28936..78721528f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -34,6 +34,10 @@ export default async (env, argv) => { }, { test: /\.txt$/, + type: "asset/source", + }, + { + test: /\.md$/, type: "asset/resource", // Changed from raw-loader generator: { filename: "text/[name].[contenthash][ext]", // Added content hash