From 3de8df5ab51e007ef3220028442a16fd5c205f2e Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 1 Jun 2023 12:57:31 -0500 Subject: [PATCH] enhancements for footer version with prod support --- .env.sample | 3 --- components/footer.js | 5 ++++- components/footer.module.css | 7 +++++++ next.config.js | 16 ++++++++-------- styles/globals.scss | 6 ------ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.env.sample b/.env.sample index 1daf4749..725bd44d 100644 --- a/.env.sample +++ b/.env.sample @@ -43,9 +43,6 @@ LND_CONNECT_ADDRESS=03cc1d0932bb99b0697f5b5e5961b83ab7fd66f1efc4c9f5c7bad66c1bcb NEXTAUTH_SECRET=3_0W_PhDRZVanbeJsZZGIEljexkKoGbL6qGIqSwTjjI JWT_SIGNING_PRIVATE_KEY={"kty":"oct","kid":"FvD__hmeKoKHu2fKjUrWbRKfhjimIM4IKshyrJG4KSM","alg":"HS512","k":"3_0W_PhDRZVanbeJsZZGIEljexkKoGbL6qGIqSwTjjI"} -# git version -NEXT_PUBLIC_COMMIT_HASH=0de1343 - # prisma db url DATABASE_URL="postgresql://sn:password@db:5432/stackernews?schema=public" diff --git a/components/footer.js b/components/footer.js index cc7aa79f..20fb5277 100644 --- a/components/footer.js +++ b/components/footer.js @@ -320,7 +320,10 @@ export default function Footer ({ noLinks }) { -
version {version}
+ {version && +
+ running {version} +
} ) diff --git a/components/footer.module.css b/components/footer.module.css index fe657d57..21cda2fa 100644 --- a/components/footer.module.css +++ b/components/footer.module.css @@ -18,4 +18,11 @@ } .contrastLink svg { fill: var(--theme-color); +} + +.version { + margin: auto; + font-size: 75%; + margin-top: .15rem; + color: var(--theme-grey) !important; } \ No newline at end of file diff --git a/next.config.js b/next.config.js index 45577549..6267f731 100644 --- a/next.config.js +++ b/next.config.js @@ -13,24 +13,24 @@ const corsHeaders = [ } ] +const commitHash = isProd + ? require('fs').readFileSync('version.txt', 'utf8').slice(0, 7) + : require('child_process').execSync('git rev-parse HEAD').toString().slice(0, 7) + module.exports = withPWA({ dest: 'public', register: true, customWorkerDir: 'sw' })( withPlausibleProxy()({ + env: { + NEXT_PUBLIC_COMMIT_HASH: commitHash + }, compress: false, experimental: { scrollRestoration: true }, - generateBuildId: process.env.NODE_ENV === 'development' - ? undefined - : async () => { - // use the app version which eb doesn't otherwise give us - // as the build id - const { RuntimeSources } = require('/opt/elasticbeanstalk/deployment/app_version_manifest.json') // eslint-disable-line - return Object.keys(RuntimeSources['stacker.news'])[0] - }, + generateBuildId: isProd ? commitHash : undefined, // Use the CDN in production and localhost for development. assetPrefix: isProd ? 'https://a.stacker.news' : undefined, async headers () { diff --git a/styles/globals.scss b/styles/globals.scss index 95e43bc5..742a47f2 100644 --- a/styles/globals.scss +++ b/styles/globals.scss @@ -630,10 +630,4 @@ div[contenteditable]:focus, .popover-header { color: #212529; } -} - -.version { - margin: auto; - font-size: x-small; - color: var(--theme-grey) !important; } \ No newline at end of file