Skip to content
Merged

PD-5670 #2852

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
20 changes: 10 additions & 10 deletions SUPPORTED_BROWSERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

> This file is auto-generated from `.browserslistrc` during the prebuild step. Do not edit manually.

| Browser | Minimum version |
| ---------------- | --------------- |
| Android WebView | 145 or newer |
| Apple Safari | 17.2 or newer |
| Google Chrome | 120 or newer |
| Microsoft Edge | 120 or newer |
| Mozilla Firefox | 120 or newer |
| Opera | 106 or newer |
| Opera Mobile | 80 or newer |
| Samsung Internet | 25 or newer |
| Browser | Minimum version |
|---------|-----------------|
| Android WebView | 145 or newer |
| Apple Safari | 17.2 or newer |
| Google Chrome | 120 or newer |
| Microsoft Edge | 120 or newer |
| Mozilla Firefox | 120 or newer |
| Opera | 106 or newer |
| Opera Mobile | 80 or newer |
| Samsung Internet | 25 or newer |
34 changes: 27 additions & 7 deletions scripts/print-view-localize.postbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* zh-CN→zh_CN, zh-TW→zh_TW) are handled via XLF_LOCALE_MAP.
*/

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

/**
* Returns an 8-character hash of the built print-view assets for a locale,
* used as a cache-busting query param: `?v=<hash>-<locale>`.
* Hashes the translated JS + the shared CSS so any change invalidates the cache.
*/
function printViewCacheKey(destDir: string, locale: string): string {
const hash = createHash('sha256')
for (const file of ['fetch-orcid.js', 'cv-style.css']) {
const filePath = `${destDir}/${file}`
if (existsSync(filePath)) {
hash.update(readFileSync(filePath))
}
}
return `${hash.digest('hex').slice(0, 8)}-${locale}`
}

function xlfFileForLocale(locale: string): string {
const suffix = XLF_LOCALE_MAP[locale] ?? locale
return `./src/locale/messages.${suffix}.xlf`
Expand Down Expand Up @@ -132,19 +149,22 @@ export function localizeAndWritePrintViewScript(): void {
writeFileSync(destFile, output, 'utf8')
console.log(`[print-view-localize] ✓ ${destFile}`)

// Fix the lang attribute in the copied print-view/index.html.
// The source file always has lang="en"; we rewrite it to the actual locale.
// Fix the lang attribute and cache-busting version in print-view/index.html.
// The source file always has lang="en" and a static ?v=...; we rewrite both.
const printViewIndexPath = `${destDir}/index.html`
if (existsSync(printViewIndexPath)) {
const htmlSource = readFileSync(printViewIndexPath, 'utf8')
const htmlLocalized = htmlSource.replace(
const cacheKey = printViewCacheKey(destDir, locale)
let html = readFileSync(printViewIndexPath, 'utf8')
const htmlOriginal = html
html = html.replace(
/<html([^>]*)lang="[^"]*"/,
`<html$1lang="${locale}"`
)
if (htmlLocalized !== htmlSource) {
writeFileSync(printViewIndexPath, htmlLocalized, 'utf8')
html = html.replace(/__PRINT_VIEW_VERSION__/g, cacheKey)
if (html !== htmlOriginal) {
writeFileSync(printViewIndexPath, html, 'utf8')
console.log(
`[print-view-localize] ✓ ${printViewIndexPath} (lang=${locale})`
`[print-view-localize] ✓ ${printViewIndexPath} (lang=${locale}, v=${cacheKey})`
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/assets/print-view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
name="description"
content="Printable ORCID profile loaded from the registry record JSON API."
/>
<link rel="stylesheet" href="/print-view/cv-style.css?v=20260330a" />
<link rel="stylesheet" href="/print-view/cv-style.css?v=__PRINT_VIEW_VERSION__" />
</head>
<body>
<header class="app-controls no-print">
Expand All @@ -37,6 +37,6 @@
<p class="loading">This page requires JavaScript to load ORCID data.</p>
</noscript>

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