From 4f8945412e04aade352129627ca7714bbe19ce62 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 28 Oct 2026 20:49:02 +0100 Subject: [PATCH] Substitute the copyright year at build time --- docusaurus.config.ts | 8 +++++++- src/theme/Footer/Copyright/index.tsx | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/theme/Footer/Copyright/index.tsx diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 2e09e6c..b480806 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -55,6 +55,10 @@ const config: Config = { onBrokenLinks: 'throw', + customFields: { + buildYear: new Date().getFullYear(), + }, + markdown: { hooks: { onBrokenMarkdownLinks: 'throw', @@ -147,7 +151,9 @@ const config: Config = { ], }, ], - copyright: `Copyright © ${new Date().getFullYear()} Ely.by. Built with Docusaurus.`, + // {year} is replaced with the build year by the swizzled Footer/Copyright component, so the translatable + // string doesn't change every year + copyright: 'Copyright © {year} Ely.by. Built with Docusaurus.', }, prism: { theme: prismThemes.github, diff --git a/src/theme/Footer/Copyright/index.tsx b/src/theme/Footer/Copyright/index.tsx new file mode 100644 index 0000000..d0329b3 --- /dev/null +++ b/src/theme/Footer/Copyright/index.tsx @@ -0,0 +1,19 @@ +import React, {type ReactNode} from 'react'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import type {Props} from '@theme/Footer/Copyright'; + +// Replaces the {year} placeholder in the copyright with the year of the build. +// The year is taken from the build time (not the client's clock) to avoid hydration mismatches +export default function FooterCopyright({copyright}: Props): ReactNode { + const {siteConfig} = useDocusaurusContext(); + const year = String(siteConfig.customFields?.buildYear ?? new Date().getFullYear()); + + return ( +
+ ); +}