20
20
21
21
from ..configuration import VoilaConfiguration
22
22
from ..paths import ROOT , collect_static_paths , collect_template_paths
23
- from ..utils import find_all_lab_theme , get_page_config
23
+ from ..utils import DateTimeEncoder , find_all_lab_theme , get_page_config
24
24
from .exporter import VoiliteExporter
25
25
from .voilite_tree_exporter import VoiliteTreeExporter
26
26
@@ -66,6 +66,7 @@ class Voilite(Application):
66
66
'template' : 'VoilaConfiguration.template' ,
67
67
'theme' : 'VoilaConfiguration.theme' ,
68
68
'base_url' : 'Voilite.base_url' ,
69
+ 'contents' : 'Voilite.contents' ,
69
70
}
70
71
71
72
output_prefix = Unicode (
@@ -74,6 +75,10 @@ class Voilite(Application):
74
75
help = _ ('Path to the output directory' ),
75
76
)
76
77
78
+ contents = Unicode (
79
+ 'files' , config = True , help = _ ('Name of the user contents directory' )
80
+ )
81
+
77
82
@default ('log_level' )
78
83
def _default_log_level (self ):
79
84
return logging .INFO
@@ -186,11 +191,14 @@ def copy_static_files(self, federated_extensions: TypeList[str]) -> None:
186
191
)
187
192
188
193
template_name = self .voilite_configuration .template
189
- ignore_func = lambda dir , files : [
190
- f
191
- for f in files
192
- if os .path .isfile (os .path .join (dir , f )) and f [- 3 :] != 'css'
193
- ]
194
+
195
+ def ignore_func (dir , files ) -> List [str ]:
196
+ return [
197
+ f
198
+ for f in files
199
+ if os .path .isfile (os .path .join (dir , f )) and f [- 3 :] != 'css'
200
+ ]
201
+
194
202
for root in self .static_paths :
195
203
abspath = os .path .abspath (root )
196
204
if os .path .exists (abspath ):
@@ -215,6 +223,45 @@ def copy_static_files(self, federated_extensions: TypeList[str]) -> None:
215
223
)
216
224
shutil .copytree (theme [1 ], theme_dst , dirs_exist_ok = True )
217
225
226
+ # Copy additional files
227
+ in_files_path = os .path .join (os .getcwd (), self .contents )
228
+ out_files_path = os .path .join (dest_static_path , 'files' )
229
+ if os .path .exists (in_files_path ):
230
+ shutil .copytree (
231
+ in_files_path , os .path .join (out_files_path , self .contents )
232
+ )
233
+ self .index_user_files ()
234
+
235
+ def index_user_files (self , current_path = '' ) -> None :
236
+
237
+ dest_static_path = os .path .join (os .getcwd (), self .output_prefix )
238
+ cm = self .contents_manager
239
+ contents = cm .get (current_path )
240
+ contents ['content' ] = sorted (
241
+ contents ['content' ], key = lambda i : i ['name' ]
242
+ )
243
+ if current_path == '' :
244
+ contents ['content' ] = list (
245
+ filter (
246
+ lambda c : c ['type' ] == 'directory'
247
+ and c ['name' ] == self .contents ,
248
+ contents ['content' ],
249
+ )
250
+ )
251
+ for item in contents ['content' ]:
252
+ if item ['type' ] == 'directory' :
253
+ self .index_user_files (item ['path' ])
254
+
255
+ output_dir = os .path .join (
256
+ dest_static_path , 'api' , 'contents' , current_path
257
+ )
258
+ if not os .path .exists (output_dir ):
259
+ os .makedirs (output_dir , exist_ok = True )
260
+ with open (os .path .join (output_dir , 'all.json' ), 'w' ) as f :
261
+ json .dump (
262
+ contents , f , sort_keys = True , indent = 2 , cls = DateTimeEncoder
263
+ )
264
+
218
265
def convert_notebook (
219
266
self ,
220
267
nb_path : str ,
@@ -262,6 +309,7 @@ def convert_directory(self, page_config):
262
309
contents_manager = self .contents_manager ,
263
310
base_url = self .base_url ,
264
311
page_config = page_config ,
312
+ contents_directory = self .contents ,
265
313
)
266
314
nb_paths = tree_exporter .from_contents ()
267
315
for nb in nb_paths :
0 commit comments