This commit is contained in:
20
app.js
20
app.js
@@ -479,33 +479,25 @@ window.addEventListener('keydown', (e)=>{
|
||||
// small helper to set initial focus - mobile browsers will not open keyboard for divs
|
||||
document.addEventListener('touchstart', ()=>{}, {passive:true})
|
||||
|
||||
// Load commit SHA into footer (robust: prefers window.COMMIT_SHA, then meta tag, then fetch plain file)
|
||||
// Load commit SHA into footer (simple: prefer window.COMMIT_SHA/meta, else fetch /version.sha which contains only the hash)
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const el = document.getElementById('commit-sha')
|
||||
if (!el) return
|
||||
// 1) prefer a global injected by CI: window.COMMIT_SHA
|
||||
let sha = (window.COMMIT_SHA || '').toString().trim()
|
||||
// 2) fallback to meta tag if CI injects that instead
|
||||
if (!sha) {
|
||||
const meta = document.querySelector('meta[name="commit-sha"]')
|
||||
if (meta && meta.content) sha = meta.content.trim()
|
||||
}
|
||||
// 3) finally try to fetch the external file (works if it's plain text or a tiny JS file)
|
||||
if (!sha) {
|
||||
try {
|
||||
const res = await fetch('/version.js', { cache: 'no-cache' })
|
||||
const res = await fetch('/version.sha', { cache: 'no-cache' })
|
||||
if (res.ok) {
|
||||
const txt = (await res.text()).trim()
|
||||
// try to extract a quoted/assigned sha like: window.COMMIT_SHA = "abc..." or COMMIT_SHA: "..."
|
||||
const m = txt.match(/COMMIT_SHA\s*(?:=|:)\s*["']?([0-9a-fA-F]{7,40})["']?/)
|
||||
if (m && m[1]) sha = m[1]
|
||||
else {
|
||||
const firstLine = txt.split(/\r?\n/).find(l => l.trim().length>0)
|
||||
if (firstLine) sha = firstLine.trim()
|
||||
}
|
||||
const txt = await res.text()
|
||||
const first = txt.split(/\r?\n/).find(l => l.trim().length > 0)
|
||||
if (first) sha = first.trim()
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore failures silently
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (sha) el.textContent = sha.slice(0,8)
|
||||
|
||||
Reference in New Issue
Block a user