Skip to content

Commit 361dcc4

Browse files
Adjust articles
1 parent 74d7572 commit 361dcc4

File tree

9 files changed

+30
-8
lines changed

9 files changed

+30
-8
lines changed
File renamed without changes.

web/scripts/builder.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@ def parse_articles(self):
8787
article = utils.load_and_validate_yaml(file_path, self.schema_article)
8888
article_content_path = article['content']
8989
article["name"] = os.path.basename(os.path.dirname(file_path))
90+
article["parent_folder"] = os.path.basename(os.path.dirname(os.path.dirname(file_path)))
9091

9192
content_real_path = self.resolve_relative_or_repo_absolute_path(
9293
os.path.dirname(file_path), article_content_path)
9394
with open(content_real_path, 'r') as content_file:
9495
article_content = content_file.read()
9596
article['content_html'] = utils.to_html(article_content)
97+
98+
if article['name'] == 'introduction':
99+
article["path_html"] = '/'
100+
else:
101+
article["path_html"] = f"/{article['name']}/"
102+
96103
self.articles.append(article)
97104
except Exception as e:
98105
self.logger.exception(e)
@@ -411,20 +418,14 @@ def create_article_page(self, article):
411418
article["content_html"] = self.process_special_article_content(article["content_html"])
412419
html_content = self.render_page(article['title'], article_template.render(article=article))
413420

414-
if article['name'] == 'introduction':
415-
web_path = '/'
416-
else:
417-
web_path = f"/{article['name']}/"
418-
article_folder = OUTPUT_HTML_PATH + web_path
421+
article_folder = OUTPUT_HTML_PATH + article["path_html"]
419422

420423
Path(article_folder).mkdir(parents=True, exist_ok=True)
421424

422425
output_path = os.path.join(article_folder, 'index.html')
423426
with open(output_path, 'w') as html_file:
424427
html_file.write(html_content)
425428

426-
article["path_html"] = web_path
427-
428429
self.logger.info(f"Generated {output_path} for article {article['name']}")
429430

430431
def create_category(self, web_path, category_data):
@@ -450,7 +451,28 @@ def create_category(self, web_path, category_data):
450451
else:
451452
category_folder = OUTPUT_HTML_PATH + web_path
452453

453-
if 'subcategories' in category_data:
454+
if 'articles' in category_data:
455+
articles_folder = category_data['articles']['path']
456+
# List folders in articles/folder_name
457+
articles_folder_path = os.path.join(DOCS_REPO_PATH, 'articles', articles_folder)
458+
for article in self.articles:
459+
if article['parent_folder'] == articles_folder:
460+
items.append({
461+
'name': article['title'],
462+
'path_html': article['path_html']
463+
})
464+
elif 'functions' in category_data:
465+
functions_folder = category_data['functions']['path']
466+
functions_type = category_data['functions']['type']
467+
functions_folder_path = os.path.join(DOCS_REPO_PATH, 'functions', functions_folder)
468+
for function in self.functions:
469+
if function['type_name'] == functions_type and function['folder'] == functions_folder:
470+
function["category"] = category_name
471+
items.append({
472+
'name': function['name'],
473+
'path_html': function['path_html']
474+
})
475+
elif 'subcategories' in category_data:
454476
# List subcategories
455477
for subcategory in category_data['subcategories']:
456478
subcat_name = subcategory['name']

0 commit comments

Comments
 (0)