1 Star 0 Fork 23

张三峰/lobechat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
next-sitemap.config.mjs 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
ArvinX 提交于 2024-03-08 04:25 . 🐛 fix: fix sitemap config
import { glob } from 'glob';
const isVercelPreview = process.env.VERCEL === '1' && process.env.VERCEL_ENV !== 'production';
const vercelPreviewUrl = `https://${process.env.VERCEL_URL}`;
const siteUrl = isVercelPreview ? vercelPreviewUrl : 'https://chat-preview.lobehub.com';
/** @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,
generateRobotsTxt: true,
};
export default config;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/fff_1993/lobechat.git
git@gitee.com:fff_1993/lobechat.git
fff_1993
lobechat
lobechat
main

搜索帮助