From 03c5675b909d07561777d2a1e88a856cec5f6ff6 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Fri, 17 Mar 2023 20:44:47 +0800 Subject: refactor: retrieve Git revision from Lume --- .github/workflows/deploy.yaml | 10 ++++------ _config.ts | 25 +++++++++++++++++++++++-- src/_includes/layouts/base.njk | 2 +- src/_includes/layouts/index.njk | 28 ---------------------------- 4 files changed, 28 insertions(+), 37 deletions(-) delete mode 100644 src/_includes/layouts/index.njk diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 691cf6c..382cdbe 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -21,11 +21,9 @@ jobs: uses: denoland/setup-deno@v1 with: deno-version: v1.31.3 - + - name: build site - run: | - sed -i "s/commit:/commit: $GITHUB_SHA/" src/_includes/layouts/base.njk - deno task build + run: deno task build - name: setup pages uses: actions/configure-pages@v3 @@ -34,7 +32,7 @@ jobs: uses: actions/upload-pages-artifact@v1 with: path: '_site' - + - name: deploy id: deployment - uses: actions/deploy-pages@v1 \ No newline at end of file + uses: actions/deploy-pages@v1 diff --git a/_config.ts b/_config.ts index d457326..1a2f473 100644 --- a/_config.ts +++ b/_config.ts @@ -8,8 +8,8 @@ import sass from "lume/plugins/sass.ts"; import sitemap from "lume/plugins/sitemap.ts"; const site = lume({ - src: "./src", - location: new URL("https://getchoo.github.io"), + src: "./src", + location: new URL("https://getchoo.github.io"), }); site.use(attributes()); @@ -19,7 +19,28 @@ site.use(date()); site.use(remark()); site.use(sass()); site.use(sitemap()); + +const getGitRevision = async () => { + const p = Deno.run({ + cmd: ["git", "rev-parse", "HEAD"], + stdout: "piped", + }); + const [status, output] = await Promise.all([p.status(), p.output()]); + + if (status.success) { + return new TextDecoder().decode(output).trim(); + } + + return null; +}; + +site.data( + "gitRevision", + await getGitRevision(), +); + site.ignore("README.md", "LICENSE", ".gitignore", ".gitattributes"); + site.copy("imgs"); site.copy("files"); site.copy("js"); diff --git a/src/_includes/layouts/base.njk b/src/_includes/layouts/base.njk index 8688c95..b0fb268 100644 --- a/src/_includes/layouts/base.njk +++ b/src/_includes/layouts/base.njk @@ -14,7 +14,7 @@ {% block footer %} {% endblock %} diff --git a/src/_includes/layouts/index.njk b/src/_includes/layouts/index.njk deleted file mode 100644 index 858569a..0000000 --- a/src/_includes/layouts/index.njk +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "_includes/layouts/base.njk" %} -{% block body %} - {{ super () }} -
- - legalize now! - acab - powered by fedora - let's crush capitalism! -
best viewed with any browser - weezer fan - play with steam - made with vi - pride - imagination -
mozilla is cool - completely free software - graphics by gimp - marijuana mind explorer - javascript free - keep the web free! say no to web3! - tired - hey arnold! - powered by bob - counter-strike player - chris troll -
-{% endblock %} \ No newline at end of file -- cgit v1.2.3