Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
10 changes: 9 additions & 1 deletion util/convert/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@

# Generate the output file path
notebook_name = os.path.splitext(os.path.basename(notebook_path))[0]
markdown_file = os.path.join(markdown_dir, f"{notebook_name}.md")
# Get the directory path relative to the project_dir
dir_path = os.path.dirname(relative_path)
# Replace slashes with hyphens
dir_name = dir_path.replace(os.sep, "-")
Comment on lines +64 to +67

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This change introduces directory names into the markdown file name. It's important to ensure that very long directory names do not result in excessively long file names that could cause issues with file systems or other tools. Consider truncating or hashing the directory name if it exceeds a certain length.

Also, consider the case where dir_path is empty. The current implementation would result in a leading hyphen in the markdown file name. It might be better to conditionally include the dir_name only if it's not empty to avoid the leading hyphen.

Suggested change
# Get the directory path relative to the project_dir
dir_path = os.path.dirname(relative_path)
# Replace slashes with hyphens
dir_name = dir_path.replace(os.sep, "-")
# Get the directory path relative to the project_dir
dir_path = os.path.dirname(relative_path)
# Replace slashes with hyphens
dir_name = dir_path.replace(os.sep, "-")
if dir_name:
markdown_file = os.path.join(markdown_dir, f"{dir_name}-{notebook_name}.md")
else:
markdown_file = os.path.join(markdown_dir, f"{notebook_name}.md")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very relevant for this repo but have added it as it is not a bad idea in general


if dir_name:
markdown_file = os.path.join(markdown_dir, f"{dir_name}-{notebook_name}.md")
else:
markdown_file = os.path.join(markdown_dir, f"{notebook_name}.md")

# Write the combined markdown to a file
with open(markdown_file, "w", encoding="utf-8") as f:
Expand Down