diff --git a/www/apps/book/app/sitemap.ts b/www/apps/book/app/sitemap.ts new file mode 100644 index 0000000000..d3bc3e9a9b --- /dev/null +++ b/www/apps/book/app/sitemap.ts @@ -0,0 +1,13 @@ +import { retrieveMdxPages } from "build-scripts" +import type { MetadataRoute } from "next" +import path from "path" +import { config } from "../config" +import { basePathUrl } from "../utils/base-path-url" + +export default function sitemap(): MetadataRoute.Sitemap { + return retrieveMdxPages({ + basePath: path.resolve("app"), + }).map((filePath) => ({ + url: `${config.baseUrl}${basePathUrl(filePath)}`, + })) +} diff --git a/www/apps/book/providers/search.tsx b/www/apps/book/providers/search.tsx index 24ce8468ad..7561600632 100644 --- a/www/apps/book/providers/search.tsx +++ b/www/apps/book/providers/search.tsx @@ -74,7 +74,7 @@ const SearchProvider = ({ children }: SearchProviderProps) => { }, }, ]} - initialDefaultFilters={["book"]} + initialDefaultFilters={["guides"]} > {children} diff --git a/www/apps/resources/app/sitemap.ts b/www/apps/resources/app/sitemap.ts new file mode 100644 index 0000000000..d3bc3e9a9b --- /dev/null +++ b/www/apps/resources/app/sitemap.ts @@ -0,0 +1,13 @@ +import { retrieveMdxPages } from "build-scripts" +import type { MetadataRoute } from "next" +import path from "path" +import { config } from "../config" +import { basePathUrl } from "../utils/base-path-url" + +export default function sitemap(): MetadataRoute.Sitemap { + return retrieveMdxPages({ + basePath: path.resolve("app"), + }).map((filePath) => ({ + url: `${config.baseUrl}${basePathUrl(filePath)}`, + })) +} diff --git a/www/apps/resources/providers/search.tsx b/www/apps/resources/providers/search.tsx index 78fb9f2972..da7390c22f 100644 --- a/www/apps/resources/providers/search.tsx +++ b/www/apps/resources/providers/search.tsx @@ -63,7 +63,7 @@ const SearchProvider = ({ children }: SearchProviderProps) => { }, }, ]} - initialDefaultFilters={["resources"]} + initialDefaultFilters={["guides"]} > {children} diff --git a/www/packages/build-scripts/src/index.ts b/www/packages/build-scripts/src/index.ts index 0e916419df..5de4765f63 100644 --- a/www/packages/build-scripts/src/index.ts +++ b/www/packages/build-scripts/src/index.ts @@ -1,5 +1,6 @@ export * from "./generate-edited-dates.js" export * from "./generate-sidebar.js" +export * from "./retrieve-mdx-pages.js" export * from "./utils/find-metadata-title.js" export * from "./utils/find-page-heading.js" diff --git a/www/packages/build-scripts/src/retrieve-mdx-pages.ts b/www/packages/build-scripts/src/retrieve-mdx-pages.ts new file mode 100644 index 0000000000..fb26ce2097 --- /dev/null +++ b/www/packages/build-scripts/src/retrieve-mdx-pages.ts @@ -0,0 +1,42 @@ +import { readdirSync } from "fs" +import path from "path" +import { getFileSlugSyncUtil } from "remark-rehype-plugins" + +type Options = { + basePath: string +} + +export function retrieveMdxPages({ basePath }: Options): string[] { + function retrieveMdxFilesInPath(dir: string): string[] { + const urls = [] + const files = readdirSync(dir, { + withFileTypes: true, + }) + + for (const file of files) { + const filePath = path.join(dir, file.name) + if (file.isDirectory()) { + if (!file.name.startsWith("_")) { + urls.push(...retrieveMdxFilesInPath(filePath)) + } + continue + } else if (file.name !== "page.mdx") { + continue + } + + const slug = getFileSlugSyncUtil(filePath) + + urls.push( + slug || + filePath + .replace(basePath, "") + .replace(file.name, "") + .replace(/\/$/, "") + ) + } + + return urls + } + + return retrieveMdxFilesInPath(basePath) +} diff --git a/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts b/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts index 6f86c1b28e..436d21e89e 100644 --- a/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts +++ b/www/packages/build-scripts/src/utils/get-core-flows-ref-sidebar-children.ts @@ -1,6 +1,6 @@ -import { getSidebarItemLink, ItemsToAdd } from "build-scripts" import { existsSync, readdirSync } from "fs" import path from "path" +import { getSidebarItemLink, ItemsToAdd } from "../index.js" export default async function getCoreFlowsRefSidebarChildren(): Promise< ItemsToAdd[] diff --git a/www/packages/docs-ui/src/constants.tsx b/www/packages/docs-ui/src/constants.tsx index f5646f46e2..93257285ec 100644 --- a/www/packages/docs-ui/src/constants.tsx +++ b/www/packages/docs-ui/src/constants.tsx @@ -184,12 +184,12 @@ export const mobileSidebarItemsV2: SidebarItem[] = [ export const searchFiltersV2: OptionType[] = [ { - value: "book", - label: "Docs v2", + value: "guides", + label: "Guides", }, { - value: "resources", - label: "Learning Resources", + value: "references-v2", + label: "References", }, { value: "admin-v2",