Skip to content

Commit e51cf30

Browse files
committed
Dynamic path names
1 parent b327991 commit e51cf30

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

apps/svelte.dev/src/lib/server/content.ts

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -130,39 +130,15 @@ function create_docs() {
130130

131131
export const docs = create_docs();
132132

133-
export const examples = index.examples.children;
133+
// Automatically determine packages from the docs directory structure
134+
export const packages = Array.from(
135+
new Set(
136+
Object.keys(docs.topics)
137+
.map((topic) => topic.split('/')[1])
138+
.filter(Boolean)
139+
)
140+
) as const;
134141

135-
function getDocumentationSectionPriority(path: string): number {
136-
if (path.includes('/docs/svelte/')) return 0;
137-
if (path.includes('/docs/kit/')) return 1;
138-
if (path.includes('/docs/cli/')) return 2;
139-
return 3;
140-
}
141-
142-
export function sortDocumentationPaths(paths: string[]): string[] {
143-
return paths.sort((a, b) => {
144-
// First compare by section priority
145-
const priorityA = getDocumentationSectionPriority(a);
146-
const priorityB = getDocumentationSectionPriority(b);
147-
if (priorityA !== priorityB) return priorityA - priorityB;
148-
149-
// Get directory paths
150-
const dirA = a.split('/').slice(0, -1).join('/');
151-
const dirB = b.split('/').slice(0, -1).join('/');
152-
153-
// If in the same directory, prioritize index.md
154-
if (dirA === dirB) {
155-
if (a.endsWith('index.md')) return -1;
156-
if (b.endsWith('index.md')) return 1;
157-
return a.localeCompare(b);
158-
}
159-
160-
// Otherwise sort by directory path
161-
return dirA.localeCompare(dirB);
162-
});
163-
}
164-
165-
export const packages = ['svelte', 'kit', 'cli'] as const;
166142
export type Package = (typeof packages)[number];
167143

168144
const DOCUMENTATION_NAMES: Record<Package, string> = {
@@ -332,3 +308,33 @@ export function generateLlmContent(
332308

333309
return content;
334310
}
311+
312+
function getDocumentationSectionPriority(path: string): number {
313+
if (path.includes('/docs/svelte/')) return 0;
314+
if (path.includes('/docs/kit/')) return 1;
315+
if (path.includes('/docs/cli/')) return 2;
316+
return 3;
317+
}
318+
319+
export function sortDocumentationPaths(paths: string[]): string[] {
320+
return paths.sort((a, b) => {
321+
// First compare by section priority
322+
const priorityA = getDocumentationSectionPriority(a);
323+
const priorityB = getDocumentationSectionPriority(b);
324+
if (priorityA !== priorityB) return priorityA - priorityB;
325+
326+
// Get directory paths
327+
const dirA = a.split('/').slice(0, -1).join('/');
328+
const dirB = b.split('/').slice(0, -1).join('/');
329+
330+
// If in the same directory, prioritize index.md
331+
if (dirA === dirB) {
332+
if (a.endsWith('index.md')) return -1;
333+
if (b.endsWith('index.md')) return 1;
334+
return a.localeCompare(b);
335+
}
336+
337+
// Otherwise sort by directory path
338+
return dirA.localeCompare(dirB);
339+
});
340+
}

0 commit comments

Comments
 (0)