@@ -6,18 +6,8 @@ import type {
6
6
7
7
const H1_REGEX = / ^ # ( .+ ) $ / m;
8
8
const FRONTMATTER_TITLE_REGEX = / t i t l e : [ " ' ] ( .+ ) [ " ' ] / ;
9
- const DESCRIPTION_REGEX private buildPath ( relativePath : string ) : string {
10
- let p = relativePath . replace ( / \. ( m d | m d x ) $ / , "" ) ;
11
- // Normalize path separators to forward slashes for web paths
12
- p = p . replace ( / \\ / g, "/" ) ;
13
- if ( p . endsWith ( "/index" ) ) {
14
- p = p . replace ( / \/ i n d e x $ / , "/" ) ;
15
- }
16
- if ( ! p . startsWith ( "/" ) ) {
17
- p = "/" + p ;
18
- }
19
- return p ;
20
- } ption: [ "'](.+)[" ']/;
9
+ const DESCRIPTION_REGEX = / d e s c r i p t i o n : [ " ' ] ( .+ ) [ " ' ] / ;
10
+ const FRONTMATTER_URL_REGEX = / u r l : \s * ( .+ ) / ;
21
11
const TAGS_REGEX = / t a g s : \[ ( .* ?) \] / ;
22
12
const FRONTMATTER_COMMAND_REGEX = / \b c o m m a n d : \s * ( [ " ' ] ? ) ( [ a - z A - Z 0 - 9 _ - ] + ) \1/ ;
23
13
@@ -121,14 +111,14 @@ export class MarkdownIndexer implements IIndexDocuments {
121
111
// Get category and section
122
112
const { category, section, subsection } = this . getCategoryAndSection ( relPath ) ;
123
113
124
- const url = this . buildUrl ( relPath ) ;
114
+ const url = this . buildUrl ( relPath , frontmatter ) ;
125
115
126
116
return {
127
117
id : this . generateId ( relPath ) ,
128
118
title : title ,
129
119
content : prefixedContent ,
130
120
url,
131
- path : this . buildPath ( relPath ) ,
121
+ path : this . buildPath ( relPath , frontmatter ) ,
132
122
category : category ,
133
123
section : section ,
134
124
subsection : subsection || undefined ,
@@ -212,10 +202,25 @@ export class MarkdownIndexer implements IIndexDocuments {
212
202
. toLowerCase ( ) ;
213
203
}
214
204
215
- private buildUrl ( relativePath : string ) : string {
205
+ private buildUrl ( relativePath : string , frontmatter ?: string ) : string {
206
+ // Check for frontmatter URL first
207
+ if ( frontmatter ) {
208
+ const urlMatch = frontmatter . match ( FRONTMATTER_URL_REGEX ) ;
209
+ if ( urlMatch ) {
210
+ let frontmatterUrl = urlMatch [ 1 ] . trim ( ) ;
211
+ // Remove quotes if present
212
+ frontmatterUrl = frontmatterUrl . replace ( / ^ [ ' " ` ] | [ ' " ` ] $ / g, '' ) ;
213
+ // Ensure it starts with /
214
+ if ( ! frontmatterUrl . startsWith ( "/" ) ) {
215
+ frontmatterUrl = "/" + frontmatterUrl ;
216
+ }
217
+ const BASE_URL = "https://docs.deno.com" ;
218
+ return `${ BASE_URL } ${ frontmatterUrl } ` ;
219
+ }
220
+ }
221
+
222
+ // Fall back to path-based URL
216
223
let url = relativePath . replace ( / \. ( m d | m d x ) $ / , "" ) ;
217
- // Normalize path separators to forward slashes for web URLs
218
- url = url . replace ( / \\ / g, "/" ) ;
219
224
if ( url . endsWith ( "/index" ) ) {
220
225
url = url . replace ( / \/ i n d e x $ / , "/" ) ;
221
226
}
@@ -226,8 +231,26 @@ export class MarkdownIndexer implements IIndexDocuments {
226
231
const BASE_URL = "https://docs.deno.com" ; // Replace with your actual base URL
227
232
228
233
return `${ BASE_URL } ${ url } ` ;
229
- } private buildPath ( relativePath : string ) : string {
230
- let p = relativePath . replace ( / \. ( m d | m d x ) $ / , "" ) ;
234
+ }
235
+
236
+ private buildPath ( relativePath : string , frontmatter ?: string ) : string {
237
+ // Check for frontmatter URL first
238
+ if ( frontmatter ) {
239
+ const urlMatch = frontmatter . match ( FRONTMATTER_URL_REGEX ) ;
240
+ if ( urlMatch ) {
241
+ let frontmatterUrl = urlMatch [ 1 ] . trim ( ) ;
242
+ // Remove quotes if present
243
+ frontmatterUrl = frontmatterUrl . replace ( / ^ [ ' " ` ] | [ ' " ` ] $ / g, '' ) ;
244
+ // Ensure it starts with /
245
+ if ( ! frontmatterUrl . startsWith ( "/" ) ) {
246
+ frontmatterUrl = "/" + frontmatterUrl ;
247
+ }
248
+ return frontmatterUrl ;
249
+ }
250
+ }
251
+
252
+ // Fall back to path-based URL
253
+ let p = relativePath . replace ( / \. ( m d | m d x ) $ / , "" ) ;
231
254
if ( p . endsWith ( "/index" ) ) {
232
255
p = p . replace ( / \/ i n d e x $ / , "/" ) ;
233
256
}
0 commit comments