docs: generate sitemaps + change search filters (#8957)

- Generate sitemaps for `book` and `resources` projects (in attempt to resolve some pages not being picked up by the crawler)
- Change the v2 search filters

> Note: will require changes to algolia's crawler + a recrawl once merged
This commit is contained in:
Shahed Nasser
2024-09-03 13:33:08 +03:00
committed by GitHub
parent 8e177538c1
commit f9b0605d67
8 changed files with 76 additions and 7 deletions

View File

@@ -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)}`,
}))
}

View File

@@ -74,7 +74,7 @@ const SearchProvider = ({ children }: SearchProviderProps) => {
},
},
]}
initialDefaultFilters={["book"]}
initialDefaultFilters={["guides"]}
>
{children}
</UiSearchProvider>

View File

@@ -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)}`,
}))
}

View File

@@ -63,7 +63,7 @@ const SearchProvider = ({ children }: SearchProviderProps) => {
},
},
]}
initialDefaultFilters={["resources"]}
initialDefaultFilters={["guides"]}
>
{children}
</UiSearchProvider>

View File

@@ -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"

View File

@@ -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)
}

View File

@@ -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[]

View File

@@ -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",