mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-blog.git
synced 2026-07-03 15:41:26 +00:00
hash test
This commit is contained in:
parent
7ccdcad866
commit
d76f371c72
3 changed files with 48 additions and 3 deletions
|
|
@ -6,10 +6,10 @@
|
|||
"node": ">=22.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"dev": "PUBLIC_GIT_COMMIT=$(git rev-parse HEAD) astro dev",
|
||||
"preview": "astro preview",
|
||||
"astro": "astro",
|
||||
"build": "astro build"
|
||||
"build": "PUBLIC_GIT_COMMIT=$(git rev-parse HEAD) astro build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/rss": "^4.0.17",
|
||||
|
|
|
|||
42
src/components/BuildHashBlocks.astro
Normal file
42
src/components/BuildHashBlocks.astro
Normal 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>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
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 t = getTranslations(lang);
|
||||
---
|
||||
|
|
@ -8,6 +9,8 @@ const t = getTranslations(lang);
|
|||
<footer class="footer">
|
||||
<p set:html={t.footer.githubIntro} />
|
||||
<p set:html={t.footer.repoIntro} />
|
||||
<BuildHashBlocks />
|
||||
<code class="build-commit">{commit.slice(0, 7)}</code>
|
||||
</footer>
|
||||
|
||||
<style>
|
||||
|
|
|
|||
Loading…
Reference in a new issue