Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Refactor sitemap creation

Jakub Novake39588b663cf
diff --git a/apps/docs/next.config.mjs b/apps/docs/next.config.mjs
index d9c9d5cf2..d9c8b3ec4 100644
--- a/apps/docs/next.config.mjs
+++ b/apps/docs/next.config.mjs
@@ -46,7 +46,7 @@ const codeSnippetsDir = path.resolve('./src/code')
/** @type {import('next').NextConfig} */
const nextConfig = {
- assetPrefix: '/assets',
+ assetPrefix: process.env.ENV === 'production' ? '/assets' : '',
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'mdx'],
basePath: '',
webpack: config => {
diff --git a/apps/docs/src/app/(dashboard)/dashboard/sitemap.ts b/apps/docs/src/app/(dashboard)/dashboard/sitemap.ts
index f1aadeb20..572981775 100644
--- a/apps/docs/src/app/(dashboard)/dashboard/sitemap.ts
+++ b/apps/docs/src/app/(dashboard)/dashboard/sitemap.ts
@@ -1,29 +1,14 @@
import { MetadataRoute } from 'next'
-import fs from 'fs'
import path from 'path'
-import { getAllPageFilePaths } from '@/utils/sitemap'
-
-function nonNull<T>(value: T | null): value is T {
- return value !== null
-}
+import { getPageForSitemap } from '@/utils/sitemap'
export default function sitemap(): MetadataRoute.Sitemap {
- const appDirectory = path.join(process.cwd(), 'src', 'app', '(dashboard)', 'dashboard')
- const mdxFilePaths = getAllPageFilePaths(appDirectory)
- const priority = 0.5
-
- return mdxFilePaths
- .map((filePath) => {
- const pathname = path
- .relative(appDirectory, filePath)
- .replace(/\/page\.mdx$/, '')
- const url = `https://e2b.dev/dashboard/${pathname}`
- const lastModified = fs.statSync(filePath).mtime
- return {
- url,
- lastModified,
- priority,
- }
- })
- .filter(nonNull)
+ const appDirectory = path.join(
+ process.cwd(),
+ 'src',
+ 'app',
+ '(dashboard)',
+ 'dashboard',
+ )
+ return getPageForSitemap(appDirectory, 'https://e2b.dev/dashboard/', 0.5)
}
diff --git a/apps/docs/src/app/(docs)/docs/sitemap.ts b/apps/docs/src/app/(docs)/docs/sitemap.ts
index 515fe9304..b2b7e1215 100644
--- a/apps/docs/src/app/(docs)/docs/sitemap.ts
+++ b/apps/docs/src/app/(docs)/docs/sitemap.ts
@@ -1,30 +1,10 @@
import { MetadataRoute } from 'next'
-import fs from 'fs'
import path from 'path'
-import { getAllPageFilePaths } from '@/utils/sitemap'
-
-function nonNull<T>(value: T | null): value is T {
- return value !== null
-}
+import { getPageForSitemap } from '@/utils/sitemap'
export default function sitemap(): MetadataRoute.Sitemap {
const appDirectory = path.join(process.cwd(), 'src', 'app', '(docs)', 'docs')
- const mdxFilePaths = getAllPageFilePaths(appDirectory)
- const priority = 0.5
-
- return mdxFilePaths
- .map((filePath) => {
- const pathname = path
- .relative(appDirectory, filePath)
- .replace(/\/page\.mdx$/, '')
- const url = `https://e2b.dev/docs/${pathname}`
- const lastModified = fs.statSync(filePath).mtime
- return {
- url,
- lastModified,
- priority,
- }
- })
- .filter(nonNull)
+ return getPageForSitemap(appDirectory, 'https://e2b.dev/docs/', 0.5).filter(
+ (page) => page.url.startsWith('https://e2b.dev/docs/api/'),
+ )
}
-
diff --git a/apps/docs/src/utils/sitemap.ts b/apps/docs/src/utils/sitemap.ts
index 00d595360..b40633875 100644
--- a/apps/docs/src/utils/sitemap.ts
+++ b/apps/docs/src/utils/sitemap.ts
@@ -1,15 +1,46 @@
import fs from 'fs'
import path from 'path'
+import { MetadataRoute } from 'next'
-export function getAllPageFilePaths(directory: string): string[] {
+function nonNull<T>(value: T | null): value is T {
+ return value !== null
+}
+
+export function getPageForSitemap(
+ directory: string,
+ urlPrefix: string,
+ priority: number,
+): MetadataRoute.Sitemap {
+ const files = getFiles(directory)
+
+ return files
+ .map((filePath) => {
+ const pathname = path
+ .relative(directory, filePath)
+ .replace(/\/page\.mdx$/, '')
+ .replace(/\/page\.tsx$/, '')
+ const url = new URL(pathname, urlPrefix).href
+ const lastModified = fs.statSync(filePath).mtime
+ return {
+ url,
+ lastModified,
+ priority,
+ }
+ })
+ .filter(nonNull)
+}
+function getFiles(directory: string): string[] {
const fileNames = fs.readdirSync(directory)
const filePaths = fileNames
.map((fileName) => {
const filePath = path.join(directory, fileName)
const stat = fs.statSync(filePath)
if (stat.isDirectory()) {
- return getAllPageFilePaths(filePath)
- } else if (path.basename(filePath) === 'page.mdx' || path.basename(filePath) === 'page.tsx') {
+ return getFiles(filePath)
+ } else if (
+ path.basename(filePath) === 'page.mdx' ||
+ path.basename(filePath) === 'page.tsx'
+ ) {
return filePath
}
})