refactor: centralize slugify in utils (#30)#32
Merged
Conversation
Add utils.slugify.slugify (ASCII-safe, matches former export_api). Remove duplicate implementations from api/export_api.py and scripts/export.py; add regression tests. Closes #30
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/export_api.py`:
- Around line 96-99: When slugify(project["name"]) can return an empty string
causing rel_path to start with a slash, ensure proj_slug is replaced with a safe
fallback before building rel_path: set proj_slug = slugify(project["name"]) or a
default (e.g., "project" or short_id) and use that sanitized value when
composing rel_path (alongside ts_file, title_slug, short_id) so the zip entry is
never absolute-like.
In `@scripts/export.py`:
- Around line 370-373: slugify(session["title"]) and slugify(project["name"])
can return an empty string; update the assignments for title_slug and
project_slug to fall back to a stable value when empty (e.g., use short_id,
"untitled", or a combination like f"untitled-{short_id}"). Specifically, after
computing title_slug = slugify(session["title"]) and project_slug =
slugify(project["name"]), replace them with logic that checks for a falsy string
and assigns a fallback (reference the variables title_slug, project_slug,
short_id and sid) so exported filenames/paths never contain empty slugs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c67d3b87-cc50-4ce8-a577-dc7c99c29490
📒 Files selected for processing (4)
api/export_api.pyscripts/export.pytests/test_slugify.pyutils/slugify.py
timon0305
requested changes
May 7, 2026
timon0305
approved these changes
May 7, 2026
wpak-ai
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consolidates
_slugifyinto a single implementation underutils.slugify.slugify, completing the residual CCC8 work after PR #24 (session-text exclusion plumbing).api/export_api.pyandscripts/export.pynow both import the shared helper; duplicate local definitions are removed.Changes
utils/slugify.pywithslugify(text: str) -> str: lowercase, replace runs of non-[a-z0-9]with-, strip hyphens (matches formerexport_apibehavior).api/export_api.py: drop local_slugify, usefrom utils.slugify import slugify.scripts/export.py: drop character-loop_slugify(isalnum/ Unicode-preserving), use sharedslugify.tests/test_slugify.pyfor ASCII, punctuation collapse, Unicode titles, empty-ish input, and digits.Behavior note
Canonical slugging is ASCII-only (same as the previous HTTP export path). CLI export filenames for titles with non-ASCII letters may change vs the old script (e.g. accented characters are folded into hyphens like the web bulk export). Zip and download filenames stay predictable across platforms.
Testing
pytest— 186 passed locally.References
claude-code-chat-browser— Exclusion rule consolidation: residual_slugifydivergence (**CCC8**) (3 pt) #30_slugifydivergence);claude-cursor.mdCCC8Summary by CodeRabbit