@@ -68,13 +68,36 @@ def parse_elements(self):
68
68
element = utils .load_and_validate_yaml (file_path , self .schema_element )
69
69
70
70
element ['real_path' ] = file_path
71
+ element ['path_html' ] = f"/{ element ['name' ]} /"
71
72
element ['description_html' ] = utils .to_html (element ['description' ])
72
73
73
74
self .elements .append (element )
74
75
except Exception as e :
75
76
self .logger .exception (e )
76
77
raise WikiBuilderError (f'Error loading element { file_path } ' )
77
78
79
+ def parse_articles (self ):
80
+ self .articles = []
81
+
82
+ for root , _ , files in os .walk (os .path .join (DOCS_REPO_PATH , 'articles' )):
83
+ for filename in files :
84
+ if filename .endswith ('.yaml' ):
85
+ file_path = os .path .join (root , filename )
86
+ try :
87
+ article = utils .load_and_validate_yaml (file_path , self .schema_article )
88
+ article_content_path = article ['content' ]
89
+ article ["name" ] = os .path .basename (os .path .dirname (file_path ))
90
+
91
+ content_real_path = self .resolve_relative_or_repo_absolute_path (
92
+ os .path .dirname (file_path ), article_content_path )
93
+ with open (content_real_path , 'r' ) as content_file :
94
+ article_content = content_file .read ()
95
+ article ['content_html' ] = utils .to_html (article_content )
96
+ self .articles .append (article )
97
+ except Exception as e :
98
+ self .logger .exception (e )
99
+ raise WikiBuilderError (f'Error loading article { file_path } ' )
100
+
78
101
def parse_events (self ):
79
102
pass
80
103
@@ -262,10 +285,10 @@ def remove_function_repeated_defs(self, function):
262
285
263
286
return function
264
287
265
- def resolve_relative_or_repo_absolute_path (self , folder , path ):
288
+ def resolve_relative_or_repo_absolute_path (self , path_to_folder , path ):
266
289
if path .startswith ('/' ):
267
290
return os .path .join (DOCS_REPO_PATH , path [1 :])
268
- return os .path .join (folder , path )
291
+ return os .path .join (path_to_folder , path )
269
292
270
293
def parse_function_examples (self , function ):
271
294
examples = {}
@@ -334,7 +357,7 @@ def parse_function_preview_images(self, function):
334
357
return function
335
358
336
359
def render_page (self , title , content ):
337
- return self .layout_template .render (
360
+ return self .input_env . get_template ( 'layout.html' ) .render (
338
361
wiki_version = self .wiki_version ,
339
362
preview_mode = os .environ .get ('CI_PREVIEW' , True ),
340
363
year = date .today ().year ,
@@ -347,25 +370,33 @@ def create_element_page(self, element):
347
370
element_template = self .input_env .get_template ('element.html' )
348
371
html_content = self .render_page (element ['name' ].capitalize (), element_template .render (element = element ))
349
372
350
- web_path = f"/{ element ['name' ]} /"
351
- element_folder = OUTPUT_HTML_PATH + web_path
373
+ element_folder = OUTPUT_HTML_PATH + element ["path_html" ]
352
374
353
375
Path (element_folder ).mkdir (parents = True , exist_ok = True )
354
376
355
377
output_path = os .path .join (element_folder , 'index.html' )
356
378
with open (output_path , 'w' ) as html_file :
357
379
html_file .write (html_content )
358
380
359
- element ["path_html" ] = web_path
360
-
361
381
self .logger .info (f"Generated { output_path } for element { element ['name' ]} " )
382
+
383
+ def process_special_article_content (self , content ):
384
+ specials = utils .get_special_strings (content )
385
+ for special in specials :
386
+ if special == 'elements_list' :
387
+ html_list = "<ul>"
388
+ for element in self .elements :
389
+ html_list += f"<li><a href='{ element ['path_html' ]} '>{ element ['name' ].capitalize ()} </a></li>"
390
+ html_list += "</ul>"
391
+ content = content .replace (f"$$special:{ special } $$" , html_list )
392
+
393
+ return content
362
394
363
395
def create_function_page (self , function ):
364
396
function_template = self .input_env .get_template ('function.html' )
365
397
html_content = self .render_page (function ['name' ], function_template .render (function = function ))
366
398
367
- web_path = function ["path_html" ]
368
- function_folder = OUTPUT_HTML_PATH + web_path
399
+ function_folder = OUTPUT_HTML_PATH + function ["path_html" ]
369
400
370
401
Path (function_folder ).mkdir (parents = True , exist_ok = True )
371
402
@@ -375,25 +406,15 @@ def create_function_page(self, function):
375
406
376
407
self .logger .info (f"Generated { output_path } " )
377
408
378
- def create_article (self , article_name , articles_folder = '' , custom_web_path = False ):
379
- article_real_path = os .path .join (DOCS_REPO_PATH , 'articles' , articles_folder , article_name , f"article.yaml" )
380
- article = utils .load_and_validate_yaml (article_real_path , self .schema_article )
381
-
382
- content_path = article .get ('content' )
383
- content_real_path = self .resolve_relative_or_repo_absolute_path (os .path .dirname (article_real_path ), content_path )
384
- with open (content_real_path , 'r' ) as content_file :
385
- article ['content' ] = content_file .read ()
386
-
409
+ def create_article_page (self , article ):
387
410
article_template = self .input_env .get_template ('article.html' )
388
- article ["content_html" ] = utils .to_html (article ['content' ])
389
- html_content = self .render_page (
390
- article ['title' ],
391
- article_template .render (article = article )
392
- )
393
- if custom_web_path :
394
- web_path = custom_web_path
411
+ article ["content_html" ] = self .process_special_article_content (article ["content_html" ])
412
+ html_content = self .render_page (article ['title' ], article_template .render (article = article ))
413
+
414
+ if article ['name' ] == 'introduction' :
415
+ web_path = '/'
395
416
else :
396
- web_path = f"/{ article_name } /"
417
+ web_path = f"/{ article [ 'name' ] } /"
397
418
article_folder = OUTPUT_HTML_PATH + web_path
398
419
399
420
Path (article_folder ).mkdir (parents = True , exist_ok = True )
@@ -404,9 +425,7 @@ def create_article(self, article_name, articles_folder='', custom_web_path=False
404
425
405
426
article ["path_html" ] = web_path
406
427
407
- self .logger .info (f"Generated { output_path } for article { article_name } " )
408
-
409
- return article
428
+ self .logger .info (f"Generated { output_path } for article { article ['name' ]} " )
410
429
411
430
def create_category (self , web_path , category_data ):
412
431
if category_data .get ('subcategories' ):
@@ -431,30 +450,7 @@ def create_category(self, web_path, category_data):
431
450
else :
432
451
category_folder = OUTPUT_HTML_PATH + web_path
433
452
434
- if 'articles' in category_data :
435
- articles_folder = category_data ['articles' ]['path' ]
436
- # List folders in articles folder
437
- articles_folder_path = os .path .join (DOCS_REPO_PATH , 'articles' , articles_folder )
438
- for article_name in os .listdir (articles_folder_path ):
439
- if not os .path .isdir (os .path .join (articles_folder_path , article_name )):
440
- continue
441
- article = self .create_article (article_name , articles_folder )
442
- items .append ({
443
- 'name' : article ['title' ],
444
- 'path_html' : article ['path_html' ]
445
- })
446
- elif 'functions' in category_data :
447
- functions_folder = category_data ['functions' ]['path' ]
448
- functions_type = category_data ['functions' ]['type' ]
449
- functions_folder_path = os .path .join (DOCS_REPO_PATH , 'functions' , functions_folder )
450
- for function in self .functions :
451
- if function ['type_name' ] == functions_type and function ['folder' ] == functions_folder :
452
- function ["category" ] = category_name
453
- items .append ({
454
- 'name' : function ['name' ],
455
- 'path_html' : function ['path_html' ]
456
- })
457
- elif 'subcategories' in category_data :
453
+ if 'subcategories' in category_data :
458
454
# List subcategories
459
455
for subcategory in category_data ['subcategories' ]:
460
456
subcat_name = subcategory ['name' ]
@@ -535,9 +531,7 @@ def create_pages(self):
535
531
self .categories = {}
536
532
537
533
def create_item (item ):
538
- if 'article' in item :
539
- self .create_article (item ['article' ]['name' ], item ['article' ]['folder' ], item ['path_html' ])
540
- elif 'category' in item :
534
+ if 'category' in item :
541
535
self .create_category (item ['path_html' ], item ['category' ])
542
536
543
537
for item in self .navigation :
@@ -552,7 +546,11 @@ def create_item(item):
552
546
553
547
# Populate see_also for elements
554
548
# self.generate_element_relations()
555
-
549
+
550
+ # Create article pages
551
+ for article in self .articles :
552
+ self .create_article_page (article )
553
+
556
554
# Create function pages
557
555
for function in self .functions :
558
556
self .create_function_page (function )
@@ -561,9 +559,6 @@ def create_item(item):
561
559
for element in self .elements :
562
560
self .create_element_page (element )
563
561
564
- # Other articles
565
- self .create_article ('privacy' )
566
-
567
562
self .create_404_page ()
568
563
569
564
def copy_assets (self ):
@@ -585,10 +580,10 @@ def copy_assets(self):
585
580
586
581
def generate_wiki (self ):
587
582
self .input_env = jinja2 .Environment (loader = jinja2 .FileSystemLoader (INPUT_RESOURCES_PATH ))
588
- self .layout_template = self .input_env .get_template ('layout.html' )
589
583
590
584
self .load_schemas ()
591
585
586
+ self .parse_articles ()
592
587
self .parse_functions ()
593
588
self .parse_events ()
594
589
self .parse_elements ()
0 commit comments