Update documentation loader limit and optimize sitemap generation
The documentation loader has been updated to limit the number of items to 500 from the previous limit of 'Number.MAX_SAFE_INTEGER'. Additionally, the handling of URL generation and item retrieval in 'server-sitemap.xml/route.ts' has been refactored for more effective sitemap generation. A new 'robots.ts' file was created to set up default rules for web robots accessing the site.
This commit is contained in:
@@ -54,7 +54,7 @@ function Node({
|
|||||||
activePath: string;
|
activePath: string;
|
||||||
}) {
|
}) {
|
||||||
const pathPrefix = `/docs`;
|
const pathPrefix = `/docs`;
|
||||||
const url = `${pathPrefix}/${node.url}`;
|
const url = `${pathPrefix}/${node.slug}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ async function docsLoader(language: string | undefined) {
|
|||||||
const { items: pages } = await cms.getContentItems({
|
const { items: pages } = await cms.getContentItems({
|
||||||
collection: 'documentation',
|
collection: 'documentation',
|
||||||
language,
|
language,
|
||||||
limit: Number.MAX_SAFE_INTEGER,
|
limit: 500
|
||||||
});
|
});
|
||||||
|
|
||||||
return pages;
|
return pages;
|
||||||
|
|||||||
13
apps/web/app/robots.ts
Normal file
13
apps/web/app/robots.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { MetadataRoute } from 'next';
|
||||||
|
|
||||||
|
import appConfig from '~/config/app.config';
|
||||||
|
|
||||||
|
export default function robots(): MetadataRoute.Robots {
|
||||||
|
return {
|
||||||
|
rules: {
|
||||||
|
userAgent: '*',
|
||||||
|
allow: '/',
|
||||||
|
},
|
||||||
|
sitemap: `${appConfig.url}/server-sitemap.xml`,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,13 +5,12 @@ import { createCmsClient } from '@kit/cms';
|
|||||||
import appConfig from '~/config/app.config';
|
import appConfig from '~/config/app.config';
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const urls = getSiteUrls();
|
const paths = getPaths();
|
||||||
|
const contentItems = await getContentItems();
|
||||||
const items = await getAllItems();
|
|
||||||
|
|
||||||
return getServerSideSitemap([
|
return getServerSideSitemap([
|
||||||
...urls,
|
...paths,
|
||||||
...items.map((path) => {
|
...contentItems.map((path) => {
|
||||||
return {
|
return {
|
||||||
loc: new URL(path, appConfig.url).href,
|
loc: new URL(path, appConfig.url).href,
|
||||||
lastmod: new Date().toISOString(),
|
lastmod: new Date().toISOString(),
|
||||||
@@ -20,8 +19,8 @@ export async function GET() {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSiteUrls() {
|
function getPaths() {
|
||||||
const urls = [
|
const paths = [
|
||||||
'/',
|
'/',
|
||||||
'/faq',
|
'/faq',
|
||||||
'/blog',
|
'/blog',
|
||||||
@@ -31,17 +30,18 @@ function getSiteUrls() {
|
|||||||
'/cookie-policy',
|
'/cookie-policy',
|
||||||
'/terms-of-service',
|
'/terms-of-service',
|
||||||
'/privacy-policy',
|
'/privacy-policy',
|
||||||
|
// add more paths here
|
||||||
];
|
];
|
||||||
|
|
||||||
return urls.map((url) => {
|
return paths.map((path) => {
|
||||||
return {
|
return {
|
||||||
loc: new URL(url, appConfig.url).href,
|
loc: new URL(path, appConfig.url).href,
|
||||||
lastmod: new Date().toISOString(),
|
lastmod: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAllItems() {
|
async function getContentItems() {
|
||||||
const client = await createCmsClient();
|
const client = await createCmsClient();
|
||||||
|
|
||||||
const posts = client
|
const posts = client
|
||||||
|
|||||||
Reference in New Issue
Block a user