@@ -16,6 +16,7 @@ import {
1616 pathWithForwardSlashes ,
1717 safeExistsSync ,
1818} from "../../../core/path.ts" ;
19+ import { capitalizeTitle } from "../../../core/text.ts" ;
1920import { engineValidExtensions } from "../../../execute/engine.ts" ;
2021import { inputTargetIndex , resolveInputTarget } from "../../project-index.ts" ;
2122
@@ -151,7 +152,7 @@ async function nodesToEntries(
151152 } ) ;
152153 } else {
153154 entries . push ( {
154- title : basename ( href ) ,
155+ title : titleFromPath ( href ) ,
155156 children : await nodesToEntries (
156157 project ,
157158 `${ root } ${ node } /` ,
@@ -182,19 +183,28 @@ async function nodesToEntries(
182183 }
183184 } ) ;
184185}
185-
186186async function entryFromHref ( project : ProjectContext , href : string ) {
187187 const index = await inputTargetIndex ( project , href ) ;
188188 return {
189189 title : index ?. title ||
190190 ( await resolveInputTarget ( project , href ) ) ?. title ||
191- dirAndStem ( href ) [ 1 ] ,
191+ titleFromPath ( dirAndStem ( href ) [ 1 ] ) ,
192192 href : href ,
193193 order : asNumber ( index ?. markdown . yaml ?. [ kOrder ] ) ,
194194 empty : index ?. markdown . markdown . trim ( ) . length == 0 ,
195195 } ;
196196}
197197
198+ function titleFromPath ( path : string ) {
199+ const name = basename ( path ) ;
200+ // if there are no spaces then try to split on dashes/underscoes and autocapitalize
201+ if ( ! name . includes ( " " ) ) {
202+ return capitalizeTitle ( name . replaceAll ( / [ _ \- ] + / g, " " ) ) ;
203+ } else {
204+ return name ;
205+ }
206+ }
207+
198208function sidebarItemsFromEntries ( entries : Entry [ ] ) : SidebarItem [ ] {
199209 return entries . map ( ( entry ) => {
200210 if ( entry . children ) {
0 commit comments