Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const CURRENT_YEAR = new Date().getFullYear();

export function Footer() {
const currentYear = new Date().getFullYear();

return (
<footer className="border-t py-6 md:py-0">
<div className="container mx-auto flex flex-col items-center justify-between gap-4 md:h-24 md:flex-row px-4">
<p className="text-center text-sm leading-loose text-muted-foreground md:text-left">
&copy; {CURRENT_YEAR} Cur8d. All rights reserved.
&copy; {currentYear} Cur8d. All rights reserved.
</p>
</div>
</footer>
Expand Down
5 changes: 2 additions & 3 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { MetadataRoute } from "next";

const LAST_MODIFIED = new Date();

export default function sitemap(): MetadataRoute.Sitemap {
const lastModified = new Date();
return [
{
url: "https://typescript.cur8d.dev",
lastModified: LAST_MODIFIED,
lastModified,
changeFrequency: "monthly",
priority: 1,
},
Expand Down
5 changes: 2 additions & 3 deletions docs/app/[[...mdxPath]]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ export const metadata: Metadata = {
description: 'Production-ready Next.js starter documentation',
}

const CURRENT_YEAR = new Date().getFullYear()

export default async function RootLayout({ children }: { children: ReactNode }) {
const pageMap = await getPageMap()
const currentYear = new Date().getFullYear()
return (
<html lang="en" suppressHydrationWarning className={`${geistSans.variable} ${geistMono.variable}`}>
<Head>
Expand Down Expand Up @@ -57,7 +56,7 @@ export default async function RootLayout({ children }: { children: ReactNode })
} />}
footer={<Footer>
<div className="flex flex-col gap-2">
<p>© {CURRENT_YEAR} Cur8d. Built with Nextra.</p>
<p>© {currentYear} Cur8d. Built with Nextra.</p>
</div>
</Footer>}
pageMap={pageMap}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/app/sitemap.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import sitemap from "@/sitemap";

describe("Sitemap", () => {
const mockDate = new Date("2024-01-01T00:00:00Z");
Expand All @@ -12,8 +13,7 @@ describe("Sitemap", () => {
vi.useRealTimers();
});

it("returns the correct sitemap structure", async () => {
const { default: sitemap } = await import("@/sitemap");
it("returns the correct sitemap structure", () => {
const result = sitemap();

expect(Array.isArray(result)).toBe(true);
Expand Down
10 changes: 3 additions & 7 deletions tests/unit/components/Footer/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import { render, screen } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { Footer } from "@/components/Footer";

describe("Footer", () => {
beforeEach(() => {
vi.useFakeTimers();
vi.resetModules();
});

afterEach(() => {
vi.useRealTimers();
});

it("renders the current year and copyright text", async () => {
it("renders the current year and copyright text", () => {
const date = new Date(2025, 0, 1);
vi.setSystemTime(date);

// Re-import the component after setting the system time so the module-level CURRENT_YEAR is re-evaluated.
const { Footer } = await import("@/components/Footer");
render(<Footer />);

const footerText = screen.getByText(/© 2025 Cur8d\. All rights reserved\./);
expect(footerText).toBeInTheDocument();
});

it("renders with the correct year if it is 2030", async () => {
it("renders with the correct year if it is 2030", () => {
const date = new Date(2030, 0, 1);
vi.setSystemTime(date);

// Re-import the component after setting the system time so the module-level CURRENT_YEAR is re-evaluated.
const { Footer } = await import("@/components/Footer");
render(<Footer />);

const footerText = screen.getByText(/© 2030 Cur8d\. All rights reserved\./);
Expand Down