From 5b35afd82060ab4e981c145f36db622d1ddec217 Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Sun, 28 Apr 2024 10:36:15 -0400 Subject: [PATCH] (fix): index pages with full slug (#716) --- .../algolia/AlgoliaSearchRecordGenerator.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/servers/fdr/src/services/algolia/AlgoliaSearchRecordGenerator.ts b/servers/fdr/src/services/algolia/AlgoliaSearchRecordGenerator.ts index 54adab8369..9a59362295 100644 --- a/servers/fdr/src/services/algolia/AlgoliaSearchRecordGenerator.ts +++ b/servers/fdr/src/services/algolia/AlgoliaSearchRecordGenerator.ts @@ -48,6 +48,16 @@ class NavigationContext { public withPathParts(pathParts: PathPart[]) { return new NavigationContext(this.#indexSegment, [...this.#pathParts, ...pathParts]); } + + /** + * @returns A new `NavigationContext` instance. + */ + public withFullSlug(fullSlug: string[]) { + return new NavigationContext( + this.#indexSegment, + fullSlug.map((urlSlug) => ({ name: urlSlug, urlSlug })), + ); + } } interface AlgoliaSearchRecordGeneratorConfig { @@ -225,7 +235,14 @@ export class AlgoliaSearchRecordGenerator { if (pageContent == null) { return []; } - const pageContext = context.withPathPart({ name: page.title, urlSlug: page.urlSlug }); + + const pageContext = + page.fullSlug != null + ? context.withFullSlug(page.fullSlug) + : context.withPathPart({ + name: page.title, + urlSlug: page.urlSlug, + }); const processedContent = convertMarkdownToText(pageContent.markdown); const { indexSegment } = context; return [