From c3e99627a979352a8c2aa7ac893707f5b06b7729 Mon Sep 17 00:00:00 2001 From: Maddy Guthridge Date: Sat, 14 Sep 2024 17:54:59 +1000 Subject: [PATCH] Display git status on admin page --- src/routes/admin/+page.server.ts | 5 ++++- src/routes/admin/+page.svelte | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/routes/admin/+page.server.ts b/src/routes/admin/+page.server.ts index aeba15e8..ce35cdd3 100644 --- a/src/routes/admin/+page.server.ts +++ b/src/routes/admin/+page.server.ts @@ -1,8 +1,11 @@ import { getPortfolioGlobals } from '$lib/server'; import { redirectOnInvalidToken } from '$lib/server/auth.js'; +import { dataDirUsesGit } from '$lib/server/data/dataDir.js'; +import { getRepoStatus } from '$lib/server/git.js'; export async function load(req) { const globals = await getPortfolioGlobals(); await redirectOnInvalidToken(req, '/admin/login'); - return { globals }; + const repo = await dataDirUsesGit() ? await getRepoStatus() : null; + return { globals, repo }; } diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index 23e2d2e8..b02ba196 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -6,6 +6,9 @@ import consts from '$lib/consts'; export let data: import('./$types').PageData; + + // Git setup + let gitUrl = ''; @@ -28,6 +31,32 @@
+
+ {#if data.repo} +

Git status

+

Current branch: {data.repo.branch}

+

Current commit: {data.repo.commit}

+

+ {#if data.repo.behind} + {data.repo.behind} commits behind. + {/if} + {#if data.repo.ahead} + {data.repo.ahead} commits ahead. + {/if} +

+ + {:else} +

Git is currently not in use

+ + You can use a Git repository to back up your portfolio data. Enter the + clone URL for an empty Git repository and it will be set up for you. + +
+ + +
+ {/if} +

Reload data from disk

If you have edited your data manually, you can use this button to