forked from lobehub/lobe-chat
-
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.
ποΈ perf: add sitemap and robot.txt to improve SEO (lobehub#1337)
* ποΈ fix: add sitemap and robots.txt * π fix: fix canonical url * π fix: fix canonical url * π fix: fix canonical url * π fix: fix deploy url * π fix: fix canonical url * π fix: fix the robots config
- Loading branch information
Showing
11 changed files
with
99 additions
and
5 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 |
---|---|---|
|
@@ -56,3 +56,4 @@ next-env.d.ts | |
.env | ||
public/*.js | ||
bun.lockb | ||
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
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,54 @@ | ||
import { glob } from 'glob'; | ||
|
||
const isVercelPreview = process.env.VERCEL === '1' && process.env.VERCEL_ENV !== 'production'; | ||
|
||
const prodUrl = process.env.SITE_URL || 'https://chat-preview.lobehub.com'; | ||
|
||
const vercelPreviewUrl = `https://${process.env.VERCEL_URL}`; | ||
|
||
const siteUrl = isVercelPreview ? vercelPreviewUrl : prodUrl; | ||
|
||
/** @type {import('next-sitemap').IConfig} */ | ||
const config = { | ||
// next-sitemap does not work with app dir inside the /src dir (and have other problems e.g. with route groups) | ||
// https://github.com/iamvishnusankar/next-sitemap/issues/700#issuecomment-1759458127 | ||
// https://github.com/iamvishnusankar/next-sitemap/issues/701 | ||
// additionalPaths is a workaround for this (once the issues are fixed, we can remove it) | ||
additionalPaths: async () => { | ||
const routes = await glob('src/app/**/page.{md,mdx,ts,tsx}', { | ||
cwd: new URL('.', import.meta.url).pathname, | ||
}); | ||
|
||
// https://nextjs.org/docs/app/building-your-application/routing/colocation#private-folders | ||
const publicRoutes = routes.filter( | ||
(page) => !page.split('/').some((folder) => folder.startsWith('_')), | ||
); | ||
|
||
// https://nextjs.org/docs/app/building-your-application/routing/colocation#route-groups | ||
const publicRoutesWithoutRouteGroups = publicRoutes.map((page) => | ||
page | ||
.split('/') | ||
.filter((folder) => !folder.startsWith('(') && !folder.endsWith(')')) | ||
.join('/'), | ||
); | ||
|
||
const locs = publicRoutesWithoutRouteGroups.map((route) => { | ||
const path = route.replace(/^src\/app/, '').replace(/\/[^/]+$/, ''); | ||
const loc = path === '' ? siteUrl : `${siteUrl}/${path}`; | ||
|
||
return loc; | ||
}); | ||
|
||
const paths = locs.map((loc) => ({ | ||
changefreq: 'daily', | ||
lastmod: new Date().toISOString(), | ||
loc, | ||
priority: 0.7, | ||
})); | ||
|
||
return paths; | ||
}, | ||
siteUrl, | ||
}; | ||
|
||
export default config; |
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,7 @@ | ||
Sitemap: /sitemap.xml | ||
|
||
User-agent: * | ||
Allow: /$ | ||
Allow: /welcome | ||
Allow: /market* | ||
Disallow: / |
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
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
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