srbdbrfdbfha
All checks were successful
Deploy to FTP / deploy (push) Successful in 4s

This commit is contained in:
Sebastian Molenda
2026-05-05 20:45:36 +02:00
parent 77d5af8fa0
commit 526e42a2af
2 changed files with 7 additions and 15 deletions

View File

@@ -17,7 +17,7 @@ jobs:
- name: Inject commit SHA
run: |
echo "const COMMIT_SHA = '${GITEA_SHA}';" > version.js
echo "${GITEA_SHA}" > version.sha
- name: Upload via FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.4

20
app.js
View File

@@ -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)