@@ -22,7 +22,7 @@ const bsToFs = (p) => p.replace(/\\/g, '/')
22
22
// Gets the folder depth of the specified path
23
23
const dirDepth = ( myDir ) => myDir . split ( Path . sep ) . length
24
24
25
- const returnEmbedContents = ( match , p1 , p2 , p3 , offset , string ) => {
25
+ const returnEmbedContents = ( match , p1 , p2 , p3 , offset , string ) => {
26
26
console . log ( "Found Embed: " + p1 ) ;
27
27
try {
28
28
embedContents = Fs . readFileSync ( './docs/' + p1 , { encoding : 'utf8' } ) ;
@@ -40,18 +40,18 @@ const renderTemplate = (template, vars, currentPageInfo) => {;
40
40
template = template . replace ( new RegExp ( '{{\\s*' + key + '\\s*}}' , 'gi' ) , value )
41
41
}
42
42
43
-
43
+
44
44
template = template . replace ( new RegExp ( '(?<!code>){{embed\:([^"\']*?)}}' , 'gi' ) , returnEmbedContents ) ;
45
45
46
46
return template
47
47
}
48
48
49
- // Gets the relative path to the source dir from a docs page
49
+ // Gets the relative path to the source dir from a docs page, returning a web-safe path
50
50
const getRelativeRootFromPage = ( pagePath ) => {
51
51
let depth = dirDepth ( pagePath ) - dirDepth ( Path . resolve ( CONFIG . sourceDir ) )
52
- let relPath = ( '..' + Path . sep ) . repeat ( depth - 1 )
53
-
54
- return relPath
52
+ if ( depth <= 1 ) return './' ;
53
+ let relPath = '../' . repeat ( depth - 1 ) ;
54
+ return relPath . replace ( / \/ + $ / , '' ) + '/' ;
55
55
}
56
56
57
57
// Returns a function that will slugify a heading and also handle future duplicate slugs when called again
0 commit comments