Skip to content

Commit

Permalink
fix: segregate to getYearDisplay function
Browse files Browse the repository at this point in the history
  • Loading branch information
techwithanirudh committed Jan 21, 2025
1 parent ad956f0 commit 9ebef42
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/sections/footer/compact/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Link from '@/components/motion/link';
import { metadata as meta } from '@/app/config';

import { copyright, footer } from '@/components/sections/footer/config';
import { getYearDisplay } from '@/lib/utils';

function Footer() {
const { startYear } = copyright;
const currentYear = new Date().getFullYear()
const yearDisplay = startYear === currentYear ? startYear : `${startYear}-${currentYear}`
const yearDisplay = getYearDisplay(startYear);

return (
<footer className="flex w-full shrink-0 flex-col items-center gap-2 border-t border-border px-4 py-6 sm:flex-row md:px-6">
Expand Down
1 change: 1 addition & 0 deletions src/components/sections/footer/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const footer: FooterItem[] = [
];

export const copyright = {
// Hardcoded to 2024 as this represents the project's inception year
startYear: 2024
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/sections/footer/cozy/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Link from '@/components/motion/link';
import { metadata as meta } from '@/app/config';

import { copyright, footer } from '@/components/sections/footer/config';
import { getYearDisplay } from '@/lib/utils';

function Footer() {
const { startYear } = copyright;
const currentYear = new Date().getFullYear()
const yearDisplay = startYear === currentYear ? startYear : `${startYear}-${currentYear}`
const yearDisplay = getYearDisplay(startYear);

return (
<footer className="flex w-full shrink-0 flex-col items-center gap-2 border-t border-border px-4 py-6 sm:flex-row md:px-6">
Expand Down
6 changes: 3 additions & 3 deletions src/components/sections/footer/modern/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { metadata as meta } from '@/app/config';
import { copyright, footer } from '@/components/sections/footer/config';
import { links } from '@/components/sections/header/config';
import { contact } from '@/components/sections/contact/config';
import { getYearDisplay } from '@/lib/utils';

export default function Content() {
return (
Expand All @@ -17,9 +18,8 @@ export default function Content() {

const Copyright = () => {
const { startYear } = copyright;
const currentYear = new Date().getFullYear()
const yearDisplay = startYear === currentYear ? startYear : `${startYear}-${currentYear}`

const yearDisplay = getYearDisplay(startYear);

return (
<div className="flex flex-col items-start justify-between sm:flex-row sm:items-end">
<h1 className="mt-10 text-[18vw] leading-[0.8] md:text-[16vw] lg:text-[18vw] xl:text-[20vw] 2xl:text-[22vw]">
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export function trimString(len: number, str: string) {
}
return str;
}

export const getYearDisplay = (startYear: number) => {
const currentYear = new Date().getFullYear();
return startYear === currentYear ? startYear : `${startYear}-${currentYear}`;
};

0 comments on commit 9ebef42

Please sign in to comment.