Skip to content

Commit

Permalink
add version information
Browse files Browse the repository at this point in the history
  • Loading branch information
benphelps committed Sep 23, 2022
1 parent 08615fe commit ea6a668
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store pnpm i
FROM node:current-alpine AS builder
WORKDIR /app

ARG BUILDTIME
ARG VERSION
ARG REVISION

COPY --link --from=deps /app/node_modules ./node_modules/
COPY . .

RUN <<EOF
set -xe
yarn next telemetry disable
mkdir config && echo '-' > config/settings.yaml
npm run build
NEXT_PUBLIC_BUILDTIME=$BUILDTIME NEXT_PUBLIC_VERSION=$VERSION NEXT_PUBLIC_REVISION=$REVISION npm run build
EOF

# Production image, copy all the files and run next
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@headlessui/react": "^1.7.0",
"@tailwindcss/forms": "^0.5.3",
"classnames": "^2.3.1",
"compare-versions": "^5.0.1",
"dockerode": "^3.3.4",
"follow-redirects": "^1.15.2",
"i18next": "^21.9.1",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions src/components/version.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useTranslation } from "react-i18next";
import useSWR from "swr";
import { compareVersions } from "compare-versions";
import { MdNewReleases } from "react-icons/md";

export default function Version() {
const { t, i18n } = useTranslation();

const buildTime = process.env.NEXT_PUBLIC_BUILDTIME ?? new Date().toISOString();
const revision = process.env.NEXT_PUBLIC_REVISION ?? "dev";
const version = process.env.NEXT_PUBLIC_VERSION ?? "dev";

const { data: releaseData } = useSWR("https://api.github.com/repos/benphelps/homepage/releases");

// use Intl.DateTimeFormat to format the date
const formatDate = (date) => {
const options = {
year: "numeric",
month: "short",
day: "numeric",
};
return new Intl.DateTimeFormat(i18n.language, options).format(new Date(date));
};

const latestRelease = releaseData?.[0];

return (
<div className="flex flex-row items-center">
<span className="text-xs text-theme-500 opacity-50">
{version} ({revision.substring(0, 7)}, {formatDate(buildTime)})
</span>
{version === "main" || version === "dev"
? null
: releaseData &&
compareVersions(latestRelease.tag_name, version) > 0 && (
<a
href={latestRelease.html_url}
target="_blank"
rel="noopener noreferrer"
className="ml-2 text-xs text-theme-500 opacity-50 flex flex-row items-center"
>
<MdNewReleases className="mr-1" /> {t("Update Available")}
</a>
)}
</div>
);
}
16 changes: 13 additions & 3 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ const ColorToggle = dynamic(() => import("components/color-toggle"), {
ssr: false,
});

const Version = dynamic(() => import("components/version"), {
ssr: false,
});

const rightAlignedWidgets = ["weatherapi", "openweathermap", "weather", "search", "datetime"];

export function getStaticProps() {
let logger;
try {
logger = createLogger('index');
logger = createLogger("index");
const { providers, ...settings } = getSettings();

return {
Expand All @@ -38,7 +42,9 @@ export function getStaticProps() {
},
};
} catch (e) {
if (logger) { logger.error(e); }
if (logger) {
logger.error(e);
}
return {
props: {
initialSettings: {},
Expand Down Expand Up @@ -157,11 +163,15 @@ function Home({ initialSettings }) {
</div>
)}

<div className="rounded-full flex p-8 w-full justify-end">
<div className="flex p-8 pb-0 w-full justify-end">
{!settings?.color && <ColorToggle />}
<Revalidate />
{!settings?.theme && <ThemeToggle />}
</div>

<div className="flex p-8 pt-4 w-full justify-end">
<Version />
</div>
</div>
</>
);
Expand Down

0 comments on commit ea6a668

Please sign in to comment.