feat(docs): resolve contextual handbook topics
This commit is contained in:
@@ -794,8 +794,25 @@ function uniqueTopics(topics: DocsDocumentationTopic[]): DocsDocumentationTopic[
|
||||
|
||||
function selectedPageFromSearch(search: string, pages: DocsPageNode[]): DocsPageNode | null {
|
||||
if (!pages.length) return null;
|
||||
const requested = new URLSearchParams(search).get("topic") || "";
|
||||
return pages.find((page) => page.id === requested) ?? pages[0];
|
||||
const params = new URLSearchParams(search);
|
||||
const requested = params.get("topic") || "";
|
||||
if (requested) return pages.find((page) => page.id === requested) ?? pages[0];
|
||||
const helpContext = params.get("context") || "";
|
||||
if (helpContext) {
|
||||
const exact = pages.find((page) => page.kind === "topic" && metadataList(page.topic.metadata, "help_contexts").includes(helpContext));
|
||||
if (exact) return exact;
|
||||
const moduleId = helpContextModuleId(helpContext);
|
||||
const moduleTopic = pages.find((page) => page.kind === "topic" && page.topic.source_module_id === moduleId);
|
||||
if (moduleTopic) return moduleTopic;
|
||||
}
|
||||
return pages[0];
|
||||
}
|
||||
|
||||
function helpContextModuleId(value: string): string {
|
||||
const prefix = value.split(".", 1)[0];
|
||||
if (prefix === "campaign") return "campaigns";
|
||||
if (prefix === "address-book") return "addresses";
|
||||
return prefix;
|
||||
}
|
||||
|
||||
function outlineForPage(page: DocsPageNode | null, showTechnical: boolean): OutlineItem[] {
|
||||
|
||||
Reference in New Issue
Block a user