File tree Expand file tree Collapse file tree 4 files changed +18
-15
lines changed
content/docs/svelte/98-reference Expand file tree Collapse file tree 4 files changed +18
-15
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -60,10 +60,6 @@ function create_docs() {
60
60
return slug . replace ( / \/ [ ^ / ] + ( \/ [ ^ / ] + ) $ / g, '$1' ) ;
61
61
}
62
62
63
- function remove_docs ( slugs : string ) {
64
- return slugs . replace ( / ^ d o c s \/ / , '' ) ;
65
- }
66
-
67
63
let docs : {
68
64
/** The top level entries/packages: svelte/kit/etc. Key is the topic */
69
65
topics : Record < string , Document > ;
@@ -74,7 +70,7 @@ function create_docs() {
74
70
for ( const topic of index . docs . children ) {
75
71
const pkg = topic . slug . split ( '/' ) [ 1 ] ;
76
72
const sections = topic . children ;
77
- const transformed_topic : Document = ( docs . topics [ remove_docs ( topic . slug ) ] = {
73
+ const transformed_topic : Document = ( docs . topics [ topic . slug ] = {
78
74
...topic ,
79
75
children : [ ]
80
76
} ) ;
@@ -90,7 +86,12 @@ function create_docs() {
90
86
91
87
for ( const page of pages ) {
92
88
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 ] = {
94
95
...page ,
95
96
slug,
96
97
next : page . next ?. slug . startsWith ( `docs/${ pkg } /` )
Original file line number Diff line number Diff line change 1
1
import { docs } from '$lib/server/content' ;
2
+ import { redirect } from '@sveltejs/kit' ;
2
3
import { error } from '@sveltejs/kit' ;
3
4
4
5
export const prerender = true ;
5
6
6
7
export async function load ( { params } ) {
7
- const page = docs . topics [ params . path . split ( '/' ) [ 0 ] ] ;
8
+ const topic = params . path . split ( '/' ) [ 0 ] ;
9
+ const document = docs . topics [ `docs/${ topic } ` ] ;
8
10
9
- if ( ! page ) {
11
+ if ( ! document ) {
10
12
error ( 404 , 'Not found' ) ;
11
13
}
12
14
15
+ if ( params . path === topic ) {
16
+ redirect ( 307 , `/${ document . children [ 0 ] . children [ 0 ] . slug } ` ) ;
17
+ }
18
+
13
19
return {
14
- sections : page . children
20
+ sections : document . children
15
21
} ;
16
22
}
Original file line number Diff line number Diff line change 1
1
import { docs } from '$lib/server/content' ;
2
2
import { render_content } from '$lib/server/renderer' ;
3
- import { error , redirect } from '@sveltejs/kit' ;
3
+ import { error } from '@sveltejs/kit' ;
4
4
5
5
export async function load ( { params } ) {
6
- const document = docs . pages [ params . path ] ;
6
+ const document = docs . pages [ `docs/ ${ params . path } ` ] ;
7
7
8
8
if ( ! document ) {
9
- const topic = docs . topics [ params . path ] ;
10
- if ( topic ) {
11
- redirect ( 307 , `/${ topic . children [ 0 ] . children [ 0 ] . slug } ` ) ;
12
- }
13
9
error ( 404 ) ;
14
10
}
15
11
You can’t perform that action at this time.
0 commit comments