Compute the footer copyright range from the earliest post's year

"© 2021-2026 andwati" — start year is the minimum date across all
published writings (src/lib/copyright-year.ts), not a hand-maintained
config value like the old zola.toml's copyright_start_year. Updates
itself automatically both as the year changes and if an older post is
ever added.
This commit is contained in:
2026-08-31 08:25:28 +03:00
parent cd3a9eac70
commit 5bd179631d
2 changed files with 20 additions and 1 deletions
+3 -1
View File
@@ -3,6 +3,7 @@ import "@fontsource-variable/fraunces";
import "@fontsource-variable/newsreader";
import "@fontsource/jetbrains-mono";
import "../styles/global.css";
import { copyrightYearRange } from "../lib/copyright-year";
import { siteConfig } from "../site.config";
interface Props {
@@ -14,6 +15,7 @@ interface Props {
const { title, description, wide = false } = Astro.props;
const metaDescription = description ?? siteConfig.description;
const currentPath = Astro.url.pathname;
const copyrightRange = await copyrightYearRange();
---
<html lang="en">
@@ -131,7 +133,7 @@ const currentPath = Astro.url.pathname;
<slot />
</main>
<footer>
<p class="meta">© {new Date().getFullYear()} {siteConfig.author}</p>
<p class="meta">© {copyrightRange} {siteConfig.author}</p>
<nav aria-label="Social">
<a href={siteConfig.social.github} class="meta" rel="me noopener" target="_blank">GitHub</a>
<a href={siteConfig.social.twitter} class="meta" rel="me noopener" target="_blank">Twitter</a>
+17
View File
@@ -0,0 +1,17 @@
import { getCollection } from "astro:content";
/** "2021–2026" (earliest published writing's year through now), or just
* "2026" if that's the same year — computed from real content, not a
* hand-maintained start-year config value. */
export async function copyrightYearRange(): Promise<string> {
const writings = await getCollection("writings", ({ data }) => !data.draft);
const currentYear = new Date().getFullYear();
if (writings.length === 0) return String(currentYear);
const startYear = Math.min(
...writings.map((entry) => entry.data.date.getFullYear()),
);
return startYear === currentYear
? String(currentYear)
: `${startYear}–${currentYear}`;
}