This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
forked from HHS/simpler-grants-gov
-
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.
Browse files
Browse the repository at this point in the history
## Summary Fixes #73 ### Time to review: 5 min ## Changes proposed - Generate dynamic sitemap with `/app/sitemap.ts` (next convention) - Split pa11y config into `pa11y-desktop` and `pa11y-mobile`
- Loading branch information
Showing
10 changed files
with
187 additions
and
109 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
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,16 @@ | ||
{ | ||
"defaults": { | ||
"timeout": 240000, | ||
"runners": ["axe"], | ||
"ignore": ["color-contrast"], | ||
"concurrency": 1, | ||
"chromeLaunchConfig": { | ||
"ignoreHTTPSErrors": true, | ||
"args": ["--disable-dev-shm-usage", "--no-sandbox"] | ||
}, | ||
"actions": [ | ||
"wait for element #main-content to be visible", | ||
"screen capture screenshots-output/desktop-main-view.png" | ||
] | ||
} | ||
} |
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,23 @@ | ||
{ | ||
"defaults": { | ||
"timeout": 240000, | ||
"runners": ["axe"], | ||
"ignore": ["color-contrast"], | ||
"concurrency": 1, | ||
"chromeLaunchConfig": { | ||
"ignoreHTTPSErrors": true, | ||
"args": ["--disable-dev-shm-usage", "--no-sandbox"] | ||
}, | ||
"viewport": { | ||
"width": 390, | ||
"height": 844, | ||
"mobile": true | ||
}, | ||
"actions": [ | ||
"wait for element #main-content to be visible", | ||
"screen capture screenshots-output/mobile-main-view.png", | ||
"click element .usa-navbar button", | ||
"screen capture screenshots-output/mobile-expand-menu.png" | ||
] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
export default function Health() { | ||
return <>healthy</>; | ||
return ( | ||
<> | ||
<head> | ||
<title>Health Check</title> | ||
</head> | ||
<div>healthy</div> | ||
</> | ||
); | ||
} |
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,16 @@ | ||
import { MetadataRoute } from "next"; | ||
import { getNextRoutes } from "../utils/getRoutes"; | ||
|
||
export default function sitemap(): MetadataRoute.Sitemap { | ||
const routes = getNextRoutes("./src/app"); | ||
|
||
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000"; | ||
const sitemap: MetadataRoute.Sitemap = routes.map((route) => ({ | ||
url: `${baseUrl}${route || ""}`, | ||
lastModified: new Date().toISOString(), | ||
changeFrequency: "weekly", | ||
priority: 0.5, | ||
})); | ||
|
||
return sitemap; | ||
} |
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
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,40 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
// Helper function to list all paths recursively | ||
export function listPaths(dir: string): string[] { | ||
let fileList: string[] = []; | ||
const files = fs.readdirSync(dir); | ||
files.forEach((file) => { | ||
const filePath = path.join(dir, file); | ||
if (fs.statSync(filePath).isDirectory()) { | ||
fileList = fileList.concat(listPaths(filePath)); | ||
} else { | ||
fileList.push(filePath); | ||
} | ||
}); | ||
return fileList; | ||
} | ||
|
||
// Function to get the Next.js routes | ||
export function getNextRoutes(src: string): string[] { | ||
// Get all paths from the `app` directory | ||
const appPaths = listPaths(src).filter((file) => file.endsWith("page.tsx")); | ||
|
||
// Extract the route name for each `page.tsx` file | ||
// Basically anything between [locale] and /page.tsx is extracted, | ||
// which lets us get nested routes such as /newsletter/unsubscribe | ||
const appRoutes = appPaths.map((filePath) => { | ||
const relativePath = path.relative(src, filePath); | ||
const route = relativePath | ||
? "/" + | ||
relativePath | ||
.replace("/page.tsx", "") | ||
.replace(/\[locale\]/g, "") | ||
.replace(/\\/g, "/") | ||
: "/"; | ||
return route.replace(/\/\//g, "/"); | ||
}); | ||
|
||
return appRoutes; | ||
} |
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,74 @@ | ||
import { getNextRoutes, listPaths } from "../../src/utils/getRoutes"; | ||
|
||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
jest.mock("../../src/utils/getRoutes", () => { | ||
const originalModule = jest.requireActual("../../src/utils/getRoutes"); | ||
return { | ||
...originalModule, | ||
listPaths: jest.fn(), | ||
}; | ||
}); | ||
|
||
const mockedListPaths = listPaths as jest.MockedFunction<typeof listPaths>; | ||
|
||
describe("getNextRoutes", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should get Next.js routes from src directory", () => { | ||
const mockedFiles: string[] = getPaths(); | ||
|
||
mockedListPaths.mockReturnValue(mockedFiles); | ||
|
||
const result = getNextRoutes("src/app"); | ||
|
||
expect(result).toEqual([ | ||
"/dev/feature-flags", | ||
"/health", | ||
"/newsletter/confirmation", | ||
"/newsletter", | ||
"/newsletter/unsubscribe", | ||
"/", | ||
"/process", | ||
"/research", | ||
"/search", | ||
]); | ||
}); | ||
}); | ||
|
||
function getPaths() { | ||
return [ | ||
"src/app/[locale]/dev/feature-flags/FeatureFlagsTable.tsx", | ||
"src/app/[locale]/dev/feature-flags/page.tsx", | ||
"src/app/[locale]/health/page.tsx", | ||
"src/app/[locale]/newsletter/NewsletterForm.tsx", | ||
"src/app/[locale]/newsletter/confirmation/page.tsx", | ||
"src/app/[locale]/newsletter/page.tsx", | ||
"src/app/[locale]/newsletter/unsubscribe/page.tsx", | ||
"src/app/[locale]/page.tsx", | ||
"src/app/[locale]/process/ProcessIntro.tsx", | ||
"src/app/[locale]/process/ProcessInvolved.tsx", | ||
"src/app/[locale]/process/ProcessMilestones.tsx", | ||
"src/app/[locale]/process/page.tsx", | ||
"src/app/[locale]/research/ResearchArchetypes.tsx", | ||
"src/app/[locale]/research/ResearchImpact.tsx", | ||
"src/app/[locale]/research/ResearchIntro.tsx", | ||
"src/app/[locale]/research/ResearchMethodology.tsx", | ||
"src/app/[locale]/research/ResearchThemes.tsx", | ||
"src/app/[locale]/research/page.tsx", | ||
"src/app/[locale]/search/SearchForm.tsx", | ||
"src/app/[locale]/search/actions.ts", | ||
"src/app/[locale]/search/error.tsx", | ||
"src/app/[locale]/search/loading.tsx", | ||
"src/app/[locale]/search/page.tsx", | ||
"src/app/api/BaseApi.ts", | ||
"src/app/api/SearchOpportunityAPI.ts", | ||
"src/app/api/mock/APIMockResponse.json", | ||
"src/app/layout.tsx", | ||
"src/app/not-found.tsx", | ||
"src/app/sitemap.ts", | ||
"src/app/template.tsx", | ||
]; | ||
} |