forked from gethomepage/homepage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters