From 543ca6a02d75c50d30df48301189824839d30d52 Mon Sep 17 00:00:00 2001 From: KawaiiZapic Date: Thu, 7 Nov 2024 16:13:44 +0800 Subject: [PATCH] fix: Commit ID not injected to php file when build --- plugins/Matecho.ts | 21 ++++++++++----------- src/index.php | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/plugins/Matecho.ts b/plugins/Matecho.ts index c9b1c60..dd9b218 100644 --- a/plugins/Matecho.ts +++ b/plugins/Matecho.ts @@ -209,6 +209,16 @@ export default (config?: MatechoPluginConfig): Plugin => { if (id.endsWith("_actual_php.html")) { return (await readFile(id.replace("_actual_php.html", ".php"))) .toString() + .replaceAll("<%= CommitID %>", config.CommitID ?? "unknown") + .replaceAll( + "<%= CompatibilityUserAgentRegex %>", + JSON.stringify( + getUserAgentRegex({ + ignoreMinor: true, + allowHigherVersions: true + }).toString() + ).slice(1, -1) + ) .replace(/<\?(?:php|).+?(\?>|$)/gis, match => { const token = "PHPCode" + hash(match) + Date.now(); codeTokens[token] = match; @@ -218,17 +228,6 @@ export default (config?: MatechoPluginConfig): Plugin => { }, transformIndexHtml(html, ctx) { let r = html; - r = r - .replaceAll( - "<%= CompatibilityUserAgentRegex %>", - JSON.stringify( - getUserAgentRegex({ - ignoreMinor: true, - allowHigherVersions: true - }).toString() - ).slice(1, -1) - ) - .replaceAll("__COMMIT_ID__", config.CommitID ?? ""); ctx.filename = ctx.filename.replace("_actual_php.html", ".php"); if (env.command !== "serve") { Object.entries(codeTokens).forEach(([token, code]) => { diff --git a/src/index.php b/src/index.php index 36dc162..8d165cf 100644 --- a/src/index.php +++ b/src/index.php @@ -4,7 +4,7 @@ * * @package Matecho * @author KawaiiZapic - * @version __COMMIT_ID__ + * @version <%= CommitID %> * @link https://github.com/KawaiiZapic/Matecho */