11import type { Tokens } from 'marked' ;
22import { index , docs as _docs , examples } from '$lib/server/content' ;
33import { json } from '@sveltejs/kit' ;
4- import { transform , slugify , clean } from '@sveltejs/site-kit/markdown' ;
4+ import { transform , slugify , clean , create_slug_deduper } from '@sveltejs/site-kit/markdown' ;
55import type { Block } from '@sveltejs/site-kit/search' ;
66import { get_slug } from '../tutorial/[...slug]/content.server' ;
77
@@ -38,6 +38,8 @@ async function content() {
3838 const intro = sections ?. shift ( ) ?. trim ( ) ! ;
3939 const rank = + metadata . rank ;
4040
41+ const dedupe = create_slug_deduper ( ) ;
42+
4143 blocks . push ( {
4244 breadcrumbs : [ ...breadcrumbs , clean ( metadata . title ?? '' ) ] ,
4345 href : get_href ( [ slug ] ) ,
@@ -53,13 +55,15 @@ async function content() {
5355 continue ;
5456 }
5557
58+ const h2_slug = dedupe ( slugify ( h2 ) ) ;
59+
5660 const content = lines . join ( '\n' ) ;
5761 const subsections = content . trim ( ) . split ( '## ' ) ;
5862 const intro = subsections ?. shift ( ) ?. trim ( ) ;
5963 if ( intro ) {
6064 blocks . push ( {
6165 breadcrumbs : [ ...breadcrumbs , clean ( metadata . title ) , clean ( h2 ) ] ,
62- href : get_href ( [ slug , slugify ( h2 ) ] ) ,
66+ href : get_href ( [ slug , h2_slug ] ) ,
6367 content : await plaintext ( intro ) ,
6468 rank
6569 } ) ;
@@ -73,9 +77,11 @@ async function content() {
7377 continue ;
7478 }
7579
80+ const h3_slug = dedupe ( `${ h2_slug } -${ slugify ( h3 ) } ` ) ;
81+
7682 blocks . push ( {
7783 breadcrumbs : [ ...breadcrumbs , clean ( metadata . title ) , clean ( h2 ) , clean ( h3 ) ] ,
78- href : get_href ( [ slug , slugify ( h2 ) + '-' + slugify ( h3 ) ] ) ,
84+ href : get_href ( [ slug , h3_slug ] ) ,
7985 content : await plaintext ( lines . join ( '\n' ) . trim ( ) ) ,
8086 rank
8187 } ) ;
0 commit comments