-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
User-agent: * | ||
Allow: / | ||
|
||
Sitemap: https://gil-hanan.com/sitemap.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { MetadataRoute } from "next"; | ||
import { projects } from "@data/projects"; | ||
import sitemap from "@app/sitemap"; | ||
|
||
jest.mock("./data/projects", () => ({ | ||
projects: [{ id: "project1" }, { id: "project2" }], | ||
})); | ||
|
||
describe("sitemap", () => { | ||
const host = "https://gil-hanan.com"; | ||
let lastModified: Date; | ||
let sitemapResult: MetadataRoute.Sitemap; | ||
|
||
beforeEach(() => { | ||
lastModified = new Date(); | ||
jest.useFakeTimers().setSystemTime(lastModified); | ||
sitemapResult = sitemap(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it("should include the required static URLs", () => { | ||
const staticUrls = [ | ||
host, | ||
`${host}/projects`, | ||
`${host}/about`, | ||
`${host}/contact`, | ||
]; | ||
|
||
staticUrls.forEach((url) => { | ||
expect(sitemapResult).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
url, | ||
}), | ||
]), | ||
); | ||
}); | ||
}); | ||
|
||
it("should include all projects with correct URLs", () => { | ||
projects.forEach(({ id }) => { | ||
expect(sitemapResult).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
url: `${host}/projects/${id}`, | ||
}), | ||
]), | ||
); | ||
}); | ||
}); | ||
|
||
it("should have lastModified date set for all entries", () => { | ||
sitemapResult.forEach((entry) => { | ||
expect(entry.lastModified).toEqual(lastModified); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { MetadataRoute } from "next"; | ||
import { projects } from "@data/projects"; | ||
|
||
export default function sitemap(): MetadataRoute.Sitemap { | ||
const host = "https://gil-hanan.com"; | ||
const lastModified = new Date(); | ||
|
||
return [ | ||
{ | ||
url: host, | ||
lastModified, | ||
}, | ||
{ | ||
url: `${host}/projects`, | ||
lastModified, | ||
}, | ||
{ | ||
url: `${host}/about`, | ||
lastModified, | ||
}, | ||
{ | ||
url: `${host}/contact`, | ||
lastModified, | ||
}, | ||
...projects.map(({ id }) => ({ | ||
url: `${host}/projects/${id}`, | ||
lastModified, | ||
})), | ||
]; | ||
} |