Skip to content

Commit

Permalink
Merge branch 'gen' of https://github.com/sofa-framework/doc into gen
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger committed Jul 25, 2024
2 parents 49b8775 + 40644b6 commit 29110ab
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ on:
push:
branches:
- gen
- master
schedule:
- cron: '0 0 * * *' # every day at midnight

permissions:
id-token: write
pages: write


jobs:
build:
name: Run on ${{ matrix.os }} with SOFA ${{ matrix.sofa_branch }}
Expand Down
Binary file added mkdocs/docs/assets/logo-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed mkdocs/docs/assets/logo.png
Binary file not shown.
13 changes: 7 additions & 6 deletions mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
site_name: SOFA Documentation
site_url: https://alxbilger.github.io/SofaDocGenerator/
site_description: documentation website of the framework SOFA (https://www.sofa-framework.org/)
site_url: https://sofa-framework.github.io/doc/
site_description: Documentation website of the framework SOFA

# Repository
repo_name: sofa-framework/sofa
repo_url: https://github.com/sofa-framework/sofa

theme:
name: material
logo: assets/logo.png
logo: assets/logo-white.png
favicon: assets/favicon.png
palette:
- media: "(prefers-color-scheme)"
Expand All @@ -17,15 +17,15 @@ theme:
name: Switch to light mode
- media: "(prefers-color-scheme: light)"
scheme: default
primary: indigo
accent: indigo
primary: deep orange
accent: deep orange
toggle:
icon: material/toggle-switch
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: black
accent: indigo
accent: deep orange
toggle:
icon: material/toggle-switch-off
name: Switch to system preference
Expand All @@ -51,6 +51,7 @@ extra:
link: https://www.linkedin.com/company/sofa-framework
- icon: fontawesome/brands/discord
link: https://discord.gg/G63t3a8Ra6
homepage: https://www.sofa-framework.org/

markdown_extensions:
- attr_list
Expand Down
63 changes: 57 additions & 6 deletions script/generate_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This script visits all the files of a directory and generates a table of content for mkdocs, in the configuration
file mkdocs.yml.
During the visit, it also renames the files and the folders to remove the numeric suffix. The suffixes are here
just to define the order in the table of content.
Usage:
python script.py <input_file> <input_directory>
Expand All @@ -27,13 +29,41 @@ def remove_extension(filename):
return name_without_extension


def clean_filename(s):
# Use regex to replace the starting substring that matches ^\d+_
s = re.sub(r'^\d+_', '', s)
s = to_lowercase(s)
return s

def to_lowercase(input_string):
# Function to convert uppercase letters to lowercase
return input_string.lower()


def clean_title(s):
if s.endswith('.md'):
s = remove_extension(s)
# Use regex to replace the starting substring that matches ^\d+_
title = re.sub(r'^\d+_', '', s)
title = title.replace("_", " ")
return title
s = clean_filename(s)
s = s.replace("_", " ")
return s

def clean_file_url(s):
s = clean_filename(s)
s = s.replace("_", "-")
return s


def clean_path(path):
# Split the path into components
components = path.split(os.sep)

# Apply clean_filename to each component
cleaned_components = [clean_file_url(component) for component in components]

# Join the cleaned components back into a path
cleaned_path = os.sep.join(cleaned_components)

return cleaned_path


def contains_md_file(directory):
Expand All @@ -44,6 +74,14 @@ def contains_md_file(directory):
return False


def rename_directory(directory):
[dir_head, dir_basename] = os.path.split(directory)
new_directory_name = os.path.join(dir_head, clean_file_url(dir_basename))
if not os.path.exists(new_directory_name):
print('rename', directory, new_directory_name)
os.rename(directory, new_directory_name)


def analyze_folder(yml_file, folder_path):
with open(yml_file, "a") as file:
nav_content = ''
Expand All @@ -54,20 +92,33 @@ def analyze_folder(yml_file, folder_path):
level = root.replace(folder_path, '').count(os.sep)
indent = TAB * level

root_basename = os.path.basename(root)
[root_head, root_basename] = os.path.split(root)
folder_name = clean_title(root_basename)

nav_content += f"{indent}- {folder_name}:\n"
subindent = TAB * (level + 1)
for filename in sorted(files):
if filename.endswith('.md'):
relative_file_path = os.path.relpath(os.path.join(root, filename), folder_path)
cleaned_filename = clean_file_url(filename)
os.rename(os.path.join(root, filename), os.path.join(root, cleaned_filename))
relative_file_path = os.path.relpath(os.path.join(root, cleaned_filename), folder_path)
relative_file_path = clean_path(relative_file_path)
nav_content += f"{subindent}- {clean_title(filename)}: {relative_file_path}\n"

if nav_content != '':
file.write('nav:\n')
file.write(nav_content)
print(nav_content)

for root, dirs, files in os.walk(folder_path, False):
if root == folder_path:
continue # Skip the root directory
for directory in dirs:
full_directory = os.path.join(root, directory)
print('visiting', full_directory)
rename_directory(full_directory)
rename_directory(root)


if __name__ == "__main__":
if len(sys.argv) != 3:
Expand Down
17 changes: 17 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>
#include <mutex>
#include <thread>
#include <sofa/core/CategoryLibrary.h>
#include <sofa/core/ComponentLibrary.h>

#include <sofa/helper/logging/Messaging.h>
Expand Down Expand Up @@ -258,6 +259,22 @@ void generateComponentDoc(
templateContent += "\n";
}

if (creator->getClass())
{
std::vector<std::string> categories;
sofa::core::CategoryLibrary::getCategories(creator->getClass(), categories);

if (!categories.empty())
{
templateContent += "__categories__: \n\n";
for (const auto& category : categories)
{
templateContent += "- " + category + "\n";
}
templateContent += "\n";
}
}

const auto tmpNode = sofa::core::objectmodel::New<sofa::simulation::graph::DAGNode>("tmp");
if (tmpNode)
{
Expand Down

0 comments on commit 29110ab

Please sign in to comment.