-
Notifications
You must be signed in to change notification settings - Fork 3
fix(web): add robots/sitemap metadata and bypass middleware #507
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { MetadataRoute } from "next"; | ||
|
|
||
| const DEFAULT_SITE_URL = "https://www.solid-connection.com"; | ||
|
|
||
| const getSiteUrl = () => (process.env.NEXT_PUBLIC_WEB_URL ?? DEFAULT_SITE_URL).replace(/\/$/, ""); | ||
|
|
||
| export default function robots(): MetadataRoute.Robots { | ||
| const siteUrl = getSiteUrl(); | ||
| const vercelEnv = process.env.VERCEL_ENV; | ||
| const isNonIndexEnvironment = | ||
| vercelEnv === "preview" || | ||
| vercelEnv === "development" || | ||
| siteUrl.includes("stage") || | ||
| siteUrl.includes("localhost") || | ||
| siteUrl.includes("127.0.0.1"); | ||
|
|
||
| if (isNonIndexEnvironment) { | ||
| return { | ||
| rules: { | ||
| userAgent: "*", | ||
| disallow: "/", | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| rules: { | ||
| userAgent: "*", | ||
| allow: "/", | ||
| }, | ||
| sitemap: `${siteUrl}/sitemap.xml`, | ||
| host: new URL(siteUrl).host, | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { MetadataRoute } from "next"; | ||
|
|
||
| const DEFAULT_SITE_URL = "https://www.solid-connection.com"; | ||
|
|
||
| const getSiteUrl = () => (process.env.NEXT_PUBLIC_WEB_URL ?? DEFAULT_SITE_URL).replace(/\/$/, ""); | ||
|
|
||
| export default function sitemap(): MetadataRoute.Sitemap { | ||
| const siteUrl = getSiteUrl(); | ||
|
|
||
| if (siteUrl.includes("stage") || siteUrl.includes("localhost") || siteUrl.includes("127.0.0.1")) { | ||
| return []; | ||
| } | ||
|
|
||
| const lastModified = new Date(); | ||
|
|
||
| return [ | ||
| { | ||
| url: `${siteUrl}/`, | ||
| lastModified, | ||
| changeFrequency: "daily", | ||
| priority: 1, | ||
| }, | ||
| { | ||
| url: `${siteUrl}/mentor`, | ||
| lastModified, | ||
| changeFrequency: "weekly", | ||
| priority: 0.8, | ||
| }, | ||
| { | ||
| url: `${siteUrl}/university`, | ||
| lastModified, | ||
| changeFrequency: "weekly", | ||
| priority: 0.8, | ||
| }, | ||
| { | ||
| url: `${siteUrl}/terms`, | ||
| lastModified, | ||
| changeFrequency: "yearly", | ||
| priority: 0.5, | ||
| }, | ||
| ]; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,6 @@ export function middleware(request: NextRequest) { | |
| } | ||
| export const config = { | ||
| matcher: [ | ||
| "/((?!api|_next/static|_next/image|static/chunks|images|assets|favicon.ico|sw.js|viewer|fonts|.*\\.splat).*)", | ||
| "/((?!api|_next/static|_next/image|static/chunks|images|assets|favicon.ico|robots.txt|sitemap.xml|sw.js|viewer|fonts|.*\\.splat).*)", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new matcher exclusions Useful? React with 👍 / 👎. |
||
| ], | ||
| }; | ||
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.
The sitemap now includes
/mentor, but this route is still listed inloginNeedPagesinmiddleware.tsand redirects unauthenticated requests to/login. Search crawlers will therefore hit a redirect (or login wall) for a URL advertised as indexable, which can produce sitemap/indexing errors and weakens crawl quality. Only publicly accessible canonical URLs should be emitted here.Useful? React with 👍 / 👎.