@@ -68,13 +68,36 @@ def parse_elements(self):
6868 element = utils .load_and_validate_yaml (file_path , self .schema_element )
6969
7070 element ['real_path' ] = file_path
71+ element ['path_html' ] = f"/{ element ['name' ]} /"
7172 element ['description_html' ] = utils .to_html (element ['description' ])
7273
7374 self .elements .append (element )
7475 except Exception as e :
7576 self .logger .exception (e )
7677 raise WikiBuilderError (f'Error loading element { file_path } ' )
7778
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+
78101 def parse_events (self ):
79102 pass
80103
@@ -262,10 +285,10 @@ def remove_function_repeated_defs(self, function):
262285
263286 return function
264287
265- def resolve_relative_or_repo_absolute_path (self , folder , path ):
288+ def resolve_relative_or_repo_absolute_path (self , path_to_folder , path ):
266289 if path .startswith ('/' ):
267290 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 )
269292
270293 def parse_function_examples (self , function ):
271294 examples = {}
@@ -334,7 +357,7 @@ def parse_function_preview_images(self, function):
334357 return function
335358
336359 def render_page (self , title , content ):
337- return self .layout_template .render (
360+ return self .input_env . get_template ( 'layout.html' ) .render (
338361 wiki_version = self .wiki_version ,
339362 preview_mode = os .environ .get ('CI_PREVIEW' , True ),
340363 year = date .today ().year ,
@@ -347,25 +370,33 @@ def create_element_page(self, element):
347370 element_template = self .input_env .get_template ('element.html' )
348371 html_content = self .render_page (element ['name' ].capitalize (), element_template .render (element = element ))
349372
350- web_path = f"/{ element ['name' ]} /"
351- element_folder = OUTPUT_HTML_PATH + web_path
373+ element_folder = OUTPUT_HTML_PATH + element ["path_html" ]
352374
353375 Path (element_folder ).mkdir (parents = True , exist_ok = True )
354376
355377 output_path = os .path .join (element_folder , 'index.html' )
356378 with open (output_path , 'w' ) as html_file :
357379 html_file .write (html_content )
358380
359- element ["path_html" ] = web_path
360-
361381 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
362394
363395 def create_function_page (self , function ):
364396 function_template = self .input_env .get_template ('function.html' )
365397 html_content = self .render_page (function ['name' ], function_template .render (function = function ))
366398
367- web_path = function ["path_html" ]
368- function_folder = OUTPUT_HTML_PATH + web_path
399+ function_folder = OUTPUT_HTML_PATH + function ["path_html" ]
369400
370401 Path (function_folder ).mkdir (parents = True , exist_ok = True )
371402
@@ -375,25 +406,15 @@ def create_function_page(self, function):
375406
376407 self .logger .info (f"Generated { output_path } " )
377408
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 ):
387410 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 = '/'
395416 else :
396- web_path = f"/{ article_name } /"
417+ web_path = f"/{ article [ 'name' ] } /"
397418 article_folder = OUTPUT_HTML_PATH + web_path
398419
399420 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
404425
405426 article ["path_html" ] = web_path
406427
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' ]} " )
410429
411430 def create_category (self , web_path , category_data ):
412431 if category_data .get ('subcategories' ):
@@ -431,30 +450,7 @@ def create_category(self, web_path, category_data):
431450 else :
432451 category_folder = OUTPUT_HTML_PATH + web_path
433452
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 :
458454 # List subcategories
459455 for subcategory in category_data ['subcategories' ]:
460456 subcat_name = subcategory ['name' ]
@@ -535,9 +531,7 @@ def create_pages(self):
535531 self .categories = {}
536532
537533 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 :
541535 self .create_category (item ['path_html' ], item ['category' ])
542536
543537 for item in self .navigation :
@@ -552,7 +546,11 @@ def create_item(item):
552546
553547 # Populate see_also for elements
554548 # self.generate_element_relations()
555-
549+
550+ # Create article pages
551+ for article in self .articles :
552+ self .create_article_page (article )
553+
556554 # Create function pages
557555 for function in self .functions :
558556 self .create_function_page (function )
@@ -561,9 +559,6 @@ def create_item(item):
561559 for element in self .elements :
562560 self .create_element_page (element )
563561
564- # Other articles
565- self .create_article ('privacy' )
566-
567562 self .create_404_page ()
568563
569564 def copy_assets (self ):
@@ -585,10 +580,10 @@ def copy_assets(self):
585580
586581 def generate_wiki (self ):
587582 self .input_env = jinja2 .Environment (loader = jinja2 .FileSystemLoader (INPUT_RESOURCES_PATH ))
588- self .layout_template = self .input_env .get_template ('layout.html' )
589583
590584 self .load_schemas ()
591585
586+ self .parse_articles ()
592587 self .parse_functions ()
593588 self .parse_events ()
594589 self .parse_elements ()
0 commit comments