@@ -12,7 +12,6 @@ function processRecursive(
12
12
includePath : string ,
13
13
targetDestPath : string ,
14
14
options : IncludeCollectOpts ,
15
- appendix : Map < string , string > ,
16
15
) {
17
16
const { path, log, copyFile, includedParentPath : includedParentPathNullable , included} = options ;
18
17
const includedParentPath = includedParentPathNullable || path ;
@@ -34,20 +33,16 @@ function processRecursive(
34
33
const includedRelativePath = getRelativePath ( includedParentPath , includePath ) ;
35
34
36
35
// The appendix is the map that protects from multiple include files
37
- if ( ! appendix . has ( includedRelativePath ) ) {
36
+ if ( ! options . appendix ? .has ( includedRelativePath ) ) {
38
37
// Recursive function to include the depth structure
39
- const includeContent = collectRecursive (
40
- content ,
41
- {
42
- ...options ,
43
- path : includePath ,
44
- includedParentPath,
45
- } ,
46
- appendix ,
47
- ) ;
38
+ const includeContent = collectRecursive ( content , {
39
+ ...options ,
40
+ path : includePath ,
41
+ includedParentPath,
42
+ } ) ;
48
43
49
44
// Add to appendix set structure
50
- appendix . set (
45
+ options . appendix ? .set (
51
46
includedRelativePath ,
52
47
`{% included (${ includedRelativePath } ) %}\n${ includeContent } \n{% endincluded %}` ,
53
48
) ;
@@ -59,11 +54,7 @@ function processRecursive(
59
54
}
60
55
}
61
56
62
- function collectRecursive (
63
- result : string ,
64
- options : IncludeCollectOpts ,
65
- appendix : Map < string , string > ,
66
- ) {
57
+ function collectRecursive ( result : string , options : IncludeCollectOpts ) {
67
58
const { root, path, destPath = '' , log, singlePage} = options ;
68
59
69
60
const INCLUDE_REGEXP = / { % \s * i n c l u d e \s * ( n o t i t l e ) ? \s * \[ ( .+ ?) ] \( ( .+ ?) \) \s * % } / g;
@@ -100,7 +91,7 @@ function collectRecursive(
100
91
101
92
includesPaths . push ( includePath ) ;
102
93
103
- processRecursive ( includePath , targetDestPath , options , appendix ) ;
94
+ processRecursive ( includePath , targetDestPath , options ) ;
104
95
105
96
includesPaths . pop ( ) ;
106
97
}
@@ -109,14 +100,16 @@ function collectRecursive(
109
100
}
110
101
111
102
function collect ( input : string , options : IncludeCollectOpts ) {
112
- const appendix : Map < string , string > = new Map ( ) ;
103
+ const shouldWriteAppendix = ! options . appendix ;
104
+
105
+ options . appendix = options . appendix ?? new Map ( ) ;
113
106
114
- input = collectRecursive ( input , options , appendix ) ;
107
+ input = collectRecursive ( input , options ) ;
115
108
116
- if ( ! options . path . includes ( '_includes' ) ) {
109
+ if ( shouldWriteAppendix ) {
117
110
// Appendix should be appended to the end of the file (it supports depth structure, so the included files will have included as well)
118
- if ( appendix . size > 0 ) {
119
- input += '\n' + [ ...appendix . values ( ) ] . join ( '\n' ) ;
111
+ if ( options . appendix . size > 0 ) {
112
+ input += '\n' + [ ...options . appendix . values ( ) ] . join ( '\n' ) ;
120
113
}
121
114
}
122
115
0 commit comments