Skip to content

Commit

Permalink
chore: enhance Table of Contents generation and path normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneholloman committed Sep 24, 2024
1 parent e4fdf1e commit 48dc9d1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ codemapper https://github.com/shaneholloman/ansible-role-apache
- [ ] Implement a clever way to include images in the artifacts, maybe base64 encode them directly to the markdown file, but that could chew thru tokens at prompt time? Suggestions?
- [ ] Add support for other Git hosting services (e.g., GitLab, Bitbucket)
- [ ] Implement a progress indicator for cloning/analyzing large repositories
- [ ] Table of Contents in some cases needs improvement. We may add some ignores
- [x] Table of Contents in some cases needs improvement. We may add some ignores
- [ ] For TOC consider a more robust library like `md_toc` no user complaints yet
- [x] Use changelog.md for version history

## Contributing
Expand All @@ -136,14 +137,6 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

## Version History

- 3.2.0 (2024-09-23):
- Improved handling of large and binary files:
- Large and binary files are now always acknowledged without attempting to print their contents
- File type and size information is displayed for large and binary files
- Removed option to include large file contents as it's not practical for binary files
- Simplified command-line options by removing flags related to large file handling
- Added PyPI installation support
[For full version history, see [changelog.md](changelog.md)]

---
Expand Down
25 changes: 25 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

## Version History

- 3.3.0 (2024-09-24):
- Improved Table of Contents (TOC) generation:
- Fixed issue with double dots appearing for hidden files and directories
- Standardized path separators to forward slashes for cross-platform consistency
- Corrected handling of file paths with backslashes on Windows systems
- Enhanced path normalization in file collection process:
- Ensured consistent use of forward slashes in file paths across all platforms
- Refined TOC link generation:
- Removed unwanted '%' characters from TOC links
- Improved handling of special characters in file and directory names
- Updated `generate_toc` function for better accuracy and readability:
- Preserved original path structure, including single leading dots for hidden items
- Eliminated redundant dot addition for already dot-prefixed paths
- Optimized `collect_file_paths` function:
- Implemented consistent path normalization to forward slashes
- Improved cross-platform compatibility in file path handling

- 3.2.0 (2024-09-23):
- Improved handling of large and binary files:
- Large and binary files are now always acknowledged without attempting to print their contents
- File type and size information is displayed for large and binary files
- Removed option to include large file contents as it's not practical for binary files
- Simplified command-line options by removing flags related to large file handling
- Added PyPI installation support

- 3.2.0 (2024-09-23):
- Improved handling of large and binary files:
- Large and binary files are now always acknowledged without attempting to print their contents
Expand Down
16 changes: 13 additions & 3 deletions src/codemapper/codemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ def collect_file_paths(
file_path = os.path.join(root, filename)
if include_ignored or not gitignore_spec.match_file(file_path):
rel_path = os.path.relpath(file_path, start=directory_path)
file_paths.append(rel_path)
# Normalize path separators to forward slashes
normalized_path = rel_path.replace(os.sep, "/")
file_paths.append(normalized_path)

return file_paths

Expand Down Expand Up @@ -267,8 +269,16 @@ def generate_toc(file_paths: List[str], base_name: str) -> str:
)

for path in sorted_paths:
link = path.lower().replace(".", "").replace("/", "")
toc.append(f" - [{path}](#{link})")
# Normalize path separators to forward slashes
normalized_path = path.replace(os.sep, "/")

# Create the link by removing dots, slashes, and backslashes
link = normalized_path.lower().replace(".", "").replace("/", "")

# Use the normalized path as the heading, without adding an extra dot
heading = normalized_path

toc.append(f" - [{heading}](#{link})")

toc.append("")
toc.append("<!-- /TOC -->")
Expand Down

0 comments on commit 48dc9d1

Please sign in to comment.