mirror of
https://github.com/andwati/andwati.com.git
synced 2026-10-18 09:22:53 +00:00
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:
@@ -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>
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user