Skip to content

Commit 06f3ebe

Browse files
committed
PD-5670
1 parent 54d366c commit 06f3ebe

3 files changed

Lines changed: 39 additions & 19 deletions

File tree

SUPPORTED_BROWSERS.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
> This file is auto-generated from `.browserslistrc` during the prebuild step. Do not edit manually.
44
5-
| Browser | Minimum version |
6-
| ---------------- | --------------- |
7-
| Android WebView | 145 or newer |
8-
| Apple Safari | 17.2 or newer |
9-
| Google Chrome | 120 or newer |
10-
| Microsoft Edge | 120 or newer |
11-
| Mozilla Firefox | 120 or newer |
12-
| Opera | 106 or newer |
13-
| Opera Mobile | 80 or newer |
14-
| Samsung Internet | 25 or newer |
5+
| Browser | Minimum version |
6+
|---------|-----------------|
7+
| Android WebView | 145 or newer |
8+
| Apple Safari | 17.2 or newer |
9+
| Google Chrome | 120 or newer |
10+
| Microsoft Edge | 120 or newer |
11+
| Mozilla Firefox | 120 or newer |
12+
| Opera | 106 or newer |
13+
| Opera Mobile | 80 or newer |
14+
| Samsung Internet | 25 or newer |

scripts/print-view-localize.postbuild.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* zh-CN→zh_CN, zh-TW→zh_TW) are handled via XLF_LOCALE_MAP.
1313
*/
1414

15+
import { createHash } from 'crypto'
1516
import { existsSync, readFileSync, writeFileSync } from 'fs'
1617
import {
1718
makeEs2015TranslatePlugin,
@@ -36,6 +37,22 @@ const XLF_LOCALE_MAP: Record<string, string> = {
3637
/** Source file (pre-translation). */
3738
const PRINT_VIEW_SOURCE = './src/assets/print-view/fetch-orcid.js'
3839

40+
/**
41+
* Returns an 8-character hash of the built print-view assets for a locale,
42+
* used as a cache-busting query param: `?v=<hash>-<locale>`.
43+
* Hashes the translated JS + the shared CSS so any change invalidates the cache.
44+
*/
45+
function printViewCacheKey(destDir: string, locale: string): string {
46+
const hash = createHash('sha256')
47+
for (const file of ['fetch-orcid.js', 'cv-style.css']) {
48+
const filePath = `${destDir}/${file}`
49+
if (existsSync(filePath)) {
50+
hash.update(readFileSync(filePath))
51+
}
52+
}
53+
return `${hash.digest('hex').slice(0, 8)}-${locale}`
54+
}
55+
3956
function xlfFileForLocale(locale: string): string {
4057
const suffix = XLF_LOCALE_MAP[locale] ?? locale
4158
return `./src/locale/messages.${suffix}.xlf`
@@ -132,19 +149,22 @@ export function localizeAndWritePrintViewScript(): void {
132149
writeFileSync(destFile, output, 'utf8')
133150
console.log(`[print-view-localize] ✓ ${destFile}`)
134151

135-
// Fix the lang attribute in the copied print-view/index.html.
136-
// The source file always has lang="en"; we rewrite it to the actual locale.
152+
// Fix the lang attribute and cache-busting version in print-view/index.html.
153+
// The source file always has lang="en" and a static ?v=...; we rewrite both.
137154
const printViewIndexPath = `${destDir}/index.html`
138155
if (existsSync(printViewIndexPath)) {
139-
const htmlSource = readFileSync(printViewIndexPath, 'utf8')
140-
const htmlLocalized = htmlSource.replace(
156+
const cacheKey = printViewCacheKey(destDir, locale)
157+
let html = readFileSync(printViewIndexPath, 'utf8')
158+
const htmlOriginal = html
159+
html = html.replace(
141160
/<html([^>]*)lang="[^"]*"/,
142161
`<html$1lang="${locale}"`
143162
)
144-
if (htmlLocalized !== htmlSource) {
145-
writeFileSync(printViewIndexPath, htmlLocalized, 'utf8')
163+
html = html.replace(/__PRINT_VIEW_VERSION__/g, cacheKey)
164+
if (html !== htmlOriginal) {
165+
writeFileSync(printViewIndexPath, html, 'utf8')
146166
console.log(
147-
`[print-view-localize] ✓ ${printViewIndexPath} (lang=${locale})`
167+
`[print-view-localize] ✓ ${printViewIndexPath} (lang=${locale}, v=${cacheKey})`
148168
)
149169
}
150170
}

src/assets/print-view/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
name="description"
1111
content="Printable ORCID profile loaded from the registry record JSON API."
1212
/>
13-
<link rel="stylesheet" href="/print-view/cv-style.css?v=20260330a" />
13+
<link rel="stylesheet" href="/print-view/cv-style.css?v=__PRINT_VIEW_VERSION__" />
1414
</head>
1515
<body>
1616
<header class="app-controls no-print">
@@ -37,6 +37,6 @@
3737
<p class="loading">This page requires JavaScript to load ORCID data.</p>
3838
</noscript>
3939

40-
<script src="/print-view/fetch-orcid.js?v=20260330a"></script>
40+
<script src="/print-view/fetch-orcid.js?v=__PRINT_VIEW_VERSION__"></script>
4141
</body>
4242
</html>

0 commit comments

Comments
 (0)