Substitute the copyright year at build time

This commit is contained in:
ErickSkrauch committed 2026-10-28 20:49:02 +01:00
1 parent 930c7e63e2
commit 4f8945412e
2 files changed
+26 -1

No files matched your search

+7 -1
View File
@@ -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,
+19
View File
@@ -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 (
<div
className="footer__copyright"
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{__html: copyright.replaceAll('{year}', year)}}
/>
);
}