Skip to content

Commit

Permalink
get commit info in Footer and recreate yarn.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjam committed May 14, 2024
1 parent ca87315 commit f84aa9f
Show file tree
Hide file tree
Showing 5 changed files with 347 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-gh-pages-astro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
path: ./
node-version: 20.12.2
package-manager: [email protected]
# package-manager: [email protected]

deploy:
needs: build-astro
Expand Down
6 changes: 2 additions & 4 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ const { title, description, image = '/images/favicons/og_image_small.jpg' } = As
<meta property="twitter:image" content={new URL(image, Astro.url)} />

{/* Analytics */}
{
/*
<!--
<link rel="preconnect" href="set-url-here" />
<script async data-goatcounter="set-url-here" src="set-url-here"></script>
<script src="set-url-here" crossorigin="anonymous"></script>
*/
}
-->

<ViewTransitions fallback="none" />
</head>
4 changes: 3 additions & 1 deletion src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { Icon } from 'astro-icon/components';
import { BackToTop } from '@/components/BackToTop';
import Button from '@/components/Button.astro';
import { CONFIG } from '@/config';
import { getLatestCommitInfo, getLatestCommitInfoAsString } from '@/utils/git';
import { trimHttpProtocol } from '@/utils/strings';
const { SITE_URL } = CONFIG;
const domain = trimHttpProtocol(SITE_URL);
const today = new Date();
const commitInfo = getLatestCommitInfoAsString();
---

<footer class="w-screen border-t border-base-300 bg-base-200 pt-8 transition-colors duration-500">
Expand All @@ -27,6 +28,7 @@ const today = new Date();
>https://github.com/nemanjam/nemanjam.github.io#references</a
>
</p>
<p>{commitInfo}</p>
</div>
<div class="flex grow flex-row justify-end">
<Button href="#top">
Expand Down
35 changes: 35 additions & 0 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { execSync } from 'child_process';

export interface GitResult {
time: string;
hash: string;
message: string;
}

export const getLatestCommitInfo = (): GitResult => {
const separator = '___';
const command = `git log -1 --pretty=format:"%ad${separator}%h${separator}%s" --date=format:'%Y-%m-%d %H:%M:%S'`;
const output = execSync(command).toString().trim().split(separator);

if (output.length !== 3) {
throw new Error('Could not parse the latest Git commit output.');
}

const result = {
time: output[0],
hash: output[1],
message: output[2],
};

return result;
};

export const getLatestCommitInfoAsString = (): string => {
const commitInfo = getLatestCommitInfo();

const commitInfoString = Object.entries(commitInfo)
.map(([key, value]) => `${key}: ${value}`)
.join(', ');

return commitInfoString;
};
Loading

0 comments on commit f84aa9f

Please sign in to comment.