From b9a379e21cc5ae2308f75b4f39eda50a98b74a25 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) ## Description: Import version, changelog statically using webpack for cache busting purposes. ## Please complete the following: - [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 38c3af1ee..92111a61b 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 f3e0598ac..4eb9c8c82 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -1,4 +1,5 @@ import favicon from "../../resources/images/Favicon.svg"; +import version from "../../resources/version.txt"; import { GameRecord, GameStartInfo, ID } from "../core/Schemas"; import { getServerConfigFromClient } from "../core/configuration/ConfigLoader"; import { GameType } from "../core/game/Game"; @@ -64,9 +65,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) { @@ -79,9 +78,6 @@ class Client { } else { console.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 4f08b2ee1..5469bf093 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; @@ -63,6 +66,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