hash test

This commit is contained in:
ClovertaTheTrilobita 2026-04-16 21:10:25 +03:00
parent 7ccdcad866
commit d76f371c72
3 changed files with 48 additions and 3 deletions

View file

@ -6,10 +6,10 @@
"node": ">=22.12.0" "node": ">=22.12.0"
}, },
"scripts": { "scripts": {
"dev": "astro dev", "dev": "PUBLIC_GIT_COMMIT=$(git rev-parse HEAD) astro dev",
"preview": "astro preview", "preview": "astro preview",
"astro": "astro", "astro": "astro",
"build": "astro build" "build": "PUBLIC_GIT_COMMIT=$(git rev-parse HEAD) astro build"
}, },
"dependencies": { "dependencies": {
"@astrojs/rss": "^4.0.17", "@astrojs/rss": "^4.0.17",

View file

@ -0,0 +1,42 @@
---
const rawHash = (import.meta.env.PUBLIC_GIT_COMMIT || "")
.replace(/[^a-fA-F0-9]/g, "")
.toLowerCase();
const safeHash = rawHash || "0000000000000000000000000000000000000000";
const blockCount = 6;
const hexPerBlock = 6;
const blocks: string[] = Array.from({ length: blockCount }, (_, i) => {
const start = i * hexPerBlock;
const part = safeHash.slice(start, start + hexPerBlock).padEnd(6, "0");
return `#${part}`;
});
---
<div
class="build-hash"
title={`Build ${safeHash}`}
aria-label={`Build ${safeHash}`}
>
{
blocks.map((color: string) => (
<span class="build-block" style={`background:${color}`} />
))
}
</div>
<style>
.build-hash {
display: inline-flex;
align-items: center;
vertical-align: middle;
}
.build-block {
width: 0.7rem;
height: 0.7rem;
display: inline-block;
}
</style>

View file

@ -1,6 +1,7 @@
--- ---
import { getLangFromUrl, getTranslations, type Lang } from "@/i18n"; import { getLangFromUrl, getTranslations, type Lang } from "@/i18n";
import BuildHashBlocks from "@/components/BuildHashBlocks.astro";
const commit = import.meta.env.PUBLIC_GIT_COMMIT || "unknown";
const lang = getLangFromUrl(Astro.url); const lang = getLangFromUrl(Astro.url);
const t = getTranslations(lang); const t = getTranslations(lang);
--- ---
@ -8,6 +9,8 @@ const t = getTranslations(lang);
<footer class="footer"> <footer class="footer">
<p set:html={t.footer.githubIntro} /> <p set:html={t.footer.githubIntro} />
<p set:html={t.footer.repoIntro} /> <p set:html={t.footer.repoIntro} />
<BuildHashBlocks />
<code class="build-commit">{commit.slice(0, 7)}</code>
</footer> </footer>
<style> <style>