mirror of
https://github.com/elyby/docs.git
synced 2026-11-29 19:03:23 +05:30
Substitute the copyright year at build time
This commit is contained in:
1 parent
930c7e63e2
commit
4f8945412e
2 files changed
+26
-1
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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)}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user