File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,6 +68,14 @@ async function walkDirectory(dir: URL): Promise<URL[]> {
6868 return results ;
6969}
7070
71+ function generateTitle ( content : string , file : URL ) {
72+ const match = content . match ( / t i t l e : \s * [ " ' ] ? ( [ ^ " ' \n ] + ) [ " ' ] ? / ) ;
73+ if ( match ) {
74+ return match [ 1 ] . replace ( / e x t e n s i o n $ / , "" ) . split ( ":" ) [ 0 ] ;
75+ }
76+ return basename ( file . pathname ) || "" ;
77+ }
78+
7179export async function generateDescriptions ( ) : Promise < Record < string , string > > {
7280 const stats = await fs . stat ( basePath ) ;
7381 if ( ! stats . isDirectory ( ) ) {
@@ -84,10 +92,7 @@ export async function generateDescriptions(): Promise<Record<string, string>> {
8492 try {
8593 const content = await fs . readFile ( fileURL , "utf-8" ) ;
8694
87- const titleMatch = content . match ( / t i t l e : \s * [ " ' ] ? ( [ ^ " ' \n ] + ) [ " ' ] ? / ) ;
88- const title = titleMatch
89- ? titleMatch [ 1 ] . replace ( / e x t e n s i o n $ / , "" ) . split ( ":" ) [ 0 ]
90- : basename ( fileURL . pathname ) || "" ;
95+ const title = generateTitle ( content , fileURL ) ;
9196
9297 const relPath = fileURL . pathname
9398 . replace ( basePath . pathname , "" )
You can’t perform that action at this time.
0 commit comments