@@ -10,7 +10,7 @@ import { fileURLToPath } from 'url';
10
10
const __filename = fileURLToPath ( import . meta. url ) ;
11
11
const __dirname = dirname ( __filename ) ;
12
12
13
- const local_conf = __dirname + '/../.vitepress/local.js'
13
+ const local_conf_path = __dirname + '/../.vitepress/local.js'
14
14
15
15
export function normalizeArrayData ( data , keys ) {
16
16
for ( const [ k , v ] of Object . entries ( data ) ) {
@@ -29,15 +29,26 @@ export function normalizeArrayData(data, keys) {
29
29
return data
30
30
}
31
31
32
+ let local_conf = null
33
+ async function loadLocalConf ( ) {
34
+ if ( local_conf === null ) {
35
+ if ( fs . existsSync ( local_conf_path ) ) {
36
+ local_conf = await import ( local_conf_path )
37
+ } else {
38
+ local_conf = false
39
+ }
40
+ }
41
+
42
+ return local_conf
43
+ }
44
+
32
45
export async function loadData ( id ) {
33
46
let path = '../data/' + id + '.js'
34
47
35
48
/* Check for config override file. */
36
- if ( fs . existsSync ( local_conf ) ) {
37
- const data = await import ( local_conf )
38
- if ( data . data_paths [ id ] ) {
39
- path = data . data_paths [ id ]
40
- }
49
+ const lconf = await loadLocalConf ( )
50
+ if ( lconf && lconf . data_paths [ id ] ) {
51
+ path = lconf . data_paths [ id ]
41
52
}
42
53
43
54
try {
@@ -50,47 +61,39 @@ export async function loadData(id) {
50
61
51
62
export async function sourceFiles ( ) {
52
63
/* Check for config override file. */
53
- if ( fs . existsSync ( local_conf ) ) {
54
- const data = await import ( local_conf )
55
- if ( data . source_paths ) {
56
- return data . source_paths
57
- }
64
+ const lconf = await loadLocalConf ( )
65
+ if ( lconf && lconf . source_paths ) {
66
+ return lconf . source_paths
58
67
}
59
68
60
69
return [ 'docs/**/*.md' ]
61
70
}
62
71
63
72
export async function watchFiles ( ) {
64
73
/* Check for config override file. */
65
- if ( fs . existsSync ( local_conf ) ) {
66
- const data = await import ( local_conf )
67
- if ( data . watch_paths ) {
68
- return data . watch_paths
69
- }
74
+ const lconf = await loadLocalConf ( )
75
+ if ( lconf && lconf . watch_paths ) {
76
+ return lconf . watch_paths
70
77
}
71
78
72
79
return [ 'docs/**/*.md' , 'docs/**/*.inc' , 'data/**/*' ]
73
80
}
74
81
75
82
export async function manFiles ( ) {
76
83
/* Check for config override file. */
77
- if ( fs . existsSync ( local_conf ) ) {
78
- const data = await import ( local_conf )
79
- if ( data . man_paths ) {
80
- return data . man_paths
81
- }
84
+ const lconf = await loadLocalConf ( )
85
+ if ( lconf && lconf . man_paths ) {
86
+ return lconf . man_paths
82
87
}
83
88
84
89
return [ 'docs/core/man/*.[[:digit:]].md' ]
85
90
}
86
91
87
92
export async function pluginFiles ( ) {
88
93
/* Check for config override file. */
89
- if ( fs . existsSync ( local_conf ) ) {
90
- const data = await import ( local_conf )
91
- if ( data . plugin_paths ) {
92
- return data . plugin_paths
93
- }
94
+ const lconf = await loadLocalConf ( )
95
+ if ( lconf && lconf . plugin_paths ) {
96
+ return lconf . plugin_paths
94
97
}
95
98
96
99
return [ 'docs/core/plugins/*.md' ]
@@ -102,11 +105,10 @@ export async function frontmatterIter(callback) {
102
105
let spt = [ ]
103
106
let spt_conf = { 'docs/:path(.*)' : ':path' }
104
107
105
- if ( fs . existsSync ( local_conf ) ) {
106
- const data = await import ( local_conf )
107
- if ( data . source_path_translations ) {
108
- spt_conf = data . source_path_translations
109
- }
108
+ /* Check for config override file. */
109
+ const lconf = await loadLocalConf ( )
110
+ if ( lconf && lconf . source_path_translations ) {
111
+ spt_conf = lconf . source_path_translations
110
112
}
111
113
112
114
spt = Object . entries ( spt_conf ) . map ( ( [ from , to ] ) => ( {
0 commit comments