fix: display the version in the footer

This commit is contained in:
saberzero1 2026-05-25 17:27:29 +02:00
parent fd8b652e6e
commit 76e398c9ad
No known key found for this signature in database

View file

@ -1,3 +1,5 @@
import { readFileSync } from "fs";
import { join } from "path";
import type {
QuartzComponent,
QuartzComponentConstructor,
@ -6,11 +8,22 @@ import type {
import { i18n } from "../i18n";
import style from "./styles/footer.scss";
function getQuartzVersion(): string {
try {
const pkg = JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf-8"));
return pkg.version ?? "";
} catch {
return "";
}
}
export interface FooterOptions {
links: Record<string, string>;
}
export default ((opts?: FooterOptions) => {
const version = getQuartzVersion();
const Footer: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
const year = new Date().getFullYear();
const links = opts?.links ?? [];
@ -18,7 +31,8 @@ export default ((opts?: FooterOptions) => {
<footer class={`${displayClass ?? ""}`}>
<p>
{i18n(cfg?.locale ?? "en-US").components.footer.createdWith}{" "}
<a href="https://quartz.jzhao.xyz/">Quartz</a> &copy; {year}
<a href="https://quartz.jzhao.xyz/">Quartz{version ? ` v${version}` : ""}</a> &copy;{" "}
{year}
</p>
<ul>
{Object.entries(links).map(([text, link]) => (