Skip to content

Commit a9356b8

Browse files
committed
throw error if pages conflict with each other
1 parent ad8bae9 commit a9356b8

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed
File renamed without changes.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ function create_docs() {
6060
return slug.replace(/\/[^/]+(\/[^/]+)$/g, '$1');
6161
}
6262

63-
function remove_docs(slugs: string) {
64-
return slugs.replace(/^docs\//, '');
65-
}
66-
6763
let docs: {
6864
/** The top level entries/packages: svelte/kit/etc. Key is the topic */
6965
topics: Record<string, Document>;
@@ -74,7 +70,7 @@ function create_docs() {
7470
for (const topic of index.docs.children) {
7571
const pkg = topic.slug.split('/')[1];
7672
const sections = topic.children;
77-
const transformed_topic: Document = (docs.topics[remove_docs(topic.slug)] = {
73+
const transformed_topic: Document = (docs.topics[topic.slug] = {
7874
...topic,
7975
children: []
8076
});
@@ -90,7 +86,12 @@ function create_docs() {
9086

9187
for (const page of pages) {
9288
const slug = remove_section(page.slug);
93-
const transformed_page: Document = (docs.pages[remove_docs(slug)] = {
89+
90+
if (Object.hasOwn(docs.pages, slug)) {
91+
throw new Error(`${docs.pages[slug].file} conflicts with ${page.file}`);
92+
}
93+
94+
const transformed_page: Document = (docs.pages[slug] = {
9495
...page,
9596
slug,
9697
next: page.next?.slug.startsWith(`docs/${pkg}/`)

apps/svelte.dev/src/routes/docs/[...path]/+layout.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const prerender = true;
66

77
export async function load({ params }) {
88
const topic = params.path.split('/')[0];
9-
const document = docs.topics[topic];
9+
const document = docs.topics[`docs/${topic}`];
1010

1111
if (!document) {
1212
error(404, 'Not found');

apps/svelte.dev/src/routes/docs/[...path]/+page.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render_content } from '$lib/server/renderer';
33
import { error } from '@sveltejs/kit';
44

55
export async function load({ params }) {
6-
const document = docs.pages[params.path];
6+
const document = docs.pages[`docs/${params.path}`];
77

88
if (!document) {
99
error(404);

0 commit comments

Comments
 (0)