|
9 | 9 | LoadSubmenuItemsArgs,
|
10 | 10 | } from "../..";
|
11 | 11 | import DocsService from "../../indexing/docs/DocsService";
|
12 |
| -import preIndexedDocs from "../../indexing/docs/preIndexedDocs"; |
13 | 12 |
|
14 | 13 | import { INSTRUCTIONS_BASE_ITEM } from "./utils";
|
15 | 14 |
|
@@ -64,23 +63,12 @@ class DocsContextProvider extends BaseContextProvider {
|
64 | 63 | return chunksCopy;
|
65 | 64 | }
|
66 | 65 |
|
67 |
| - private _sortByPreIndexedDocs( |
| 66 | + private _sortAlphabetically( |
68 | 67 | submenuItems: ContextSubmenuItem[],
|
69 | 68 | ): ContextSubmenuItem[] {
|
70 |
| - // Sort submenuItems such that the objects with titles which don't occur in configs occur first, and alphabetized |
| 69 | + // Sort submenu items alphabetically by title |
71 | 70 | return submenuItems.sort((a, b) => {
|
72 |
| - const aTitleInConfigs = a.metadata?.preIndexed ?? false; |
73 |
| - const bTitleInConfigs = b.metadata?.preIndexed ?? false; |
74 |
| - |
75 |
| - // Primary criterion: Items not in configs come first |
76 |
| - if (!aTitleInConfigs && bTitleInConfigs) { |
77 |
| - return -1; |
78 |
| - } else if (aTitleInConfigs && !bTitleInConfigs) { |
79 |
| - return 1; |
80 |
| - } else { |
81 |
| - // Secondary criterion: Alphabetical order when both items are in the same category |
82 |
| - return a.title.toString().localeCompare(b.title.toString()); |
83 |
| - } |
| 71 | + return a.title.toString().localeCompare(b.title.toString()); |
84 | 72 | });
|
85 | 73 | }
|
86 | 74 |
|
@@ -165,46 +153,22 @@ class DocsContextProvider extends BaseContextProvider {
|
165 | 153 | }
|
166 | 154 | await docsService.isInitialized;
|
167 | 155 |
|
168 |
| - // Create map of docs url -> submenu item |
169 |
| - const submenuItemsMap = new Map<string, ContextSubmenuItem>(); |
| 156 | + // Create an array to hold submenu items |
| 157 | + const submenuItems: ContextSubmenuItem[] = []; |
170 | 158 |
|
171 |
| - // Add custom docs from config |
| 159 | + // Get all indexed docs from the database |
172 | 160 | const docs = (await docsService.listMetadata()) ?? [];
|
173 | 161 | for (const { startUrl, title, favicon } of docs) {
|
174 |
| - submenuItemsMap.set(startUrl, { |
| 162 | + submenuItems.push({ |
175 | 163 | title,
|
176 | 164 | id: startUrl,
|
177 | 165 | description: new URL(startUrl).hostname,
|
178 | 166 | icon: favicon,
|
179 | 167 | });
|
180 | 168 | }
|
181 | 169 |
|
182 |
| - // Add pre-indexed docs if supported |
183 |
| - const canUsePreindexedDocs = await docsService.canUsePreindexedDocs(); |
184 |
| - if (canUsePreindexedDocs) { |
185 |
| - for (const { startUrl, title } of Object.values(preIndexedDocs)) { |
186 |
| - // Skip if overridden in config |
187 |
| - if (docs.find((d) => d.startUrl === startUrl)) { |
188 |
| - continue; |
189 |
| - } |
190 |
| - submenuItemsMap.set(startUrl, { |
191 |
| - title, |
192 |
| - id: startUrl, |
193 |
| - description: new URL(startUrl).hostname, |
194 |
| - metadata: { |
195 |
| - preIndexed: true, |
196 |
| - }, |
197 |
| - }); |
198 |
| - } |
199 |
| - } |
200 |
| - |
201 |
| - // Create array and sort if pre-indexed is supported |
202 |
| - const submenuItems = Array.from(submenuItemsMap.values()); |
203 |
| - if (canUsePreindexedDocs) { |
204 |
| - return this._sortByPreIndexedDocs(submenuItems); |
205 |
| - } |
206 |
| - |
207 |
| - return submenuItems; |
| 170 | + // Sort alphabetically |
| 171 | + return this._sortAlphabetically(submenuItems); |
208 | 172 | }
|
209 | 173 | }
|
210 | 174 |
|
|
0 commit comments