-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #347]: Add next sitemap #354
Open
rylew1
wants to merge
6
commits into
main
Choose a base branch
from
rylew/347-next-sitemap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−2
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
export default function Page() { | ||
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,17 @@ | ||
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,41 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
// Helper function to list all paths in a directory 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 | ||
// for any additional overrides add more replace here... | ||
.replace("/page.tsx", "") | ||
.replace(/\[locale\]/g, "") | ||
.replace(/\\/g, "/") | ||
: "/"; | ||
return route.replace(/\/\//g, "/"); | ||
}); | ||
|
||
return appRoutes; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit of a separate issue but this fixes an actual a11y issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a localization library in this repo - is there a reason not to use it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Just added it .
I assume because we're not really refining tickets here we're not splitting them up as we might on our normal projects - first inclination is to actually break a task like that out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to say that you think including content strings using the localization library should be a separate task ticketed separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so because it's getting a bit off track of the intent of this PR