Implement ID-based routing and folder auto-generation from titles
Major features:
- Switch from slug-based to ID-based routing (/documents/123)
- Enable title editing with automatic slug/path regeneration
- Auto-generate folder structure from title slashes (e.g., Laravel/Livewire/Components)
- Persist sidebar folder open/close state using localStorage
- Remove slug unique constraint (ID routing makes it unnecessary)
- Implement recursive tree view with multi-level folder support
Architecture changes:
- DocumentService: Add generatePathAndSlug() for title-based path generation
- Routes: Change from {document:slug} to {document} for ID binding
- SidebarTree: Extract recursive rendering to partials/tree-item.blade.php
- Database: Remove unique constraint from documents.slug column
UI improvements:
- Display only last path component in sidebar (Components vs Laravel/Livewire/Components)
- Folder state persists across page navigation via localStorage
- Title field accepts slashes for folder organization
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
37
src/app/Helpers/SlugHelper.php
Normal file
37
src/app/Helpers/SlugHelper.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Cocur\Slugify\Slugify;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SlugHelper
|
||||
{
|
||||
/**
|
||||
* Generate a slug from a title, supporting Japanese and other non-ASCII characters
|
||||
*
|
||||
* @param string $title
|
||||
* @param string|null $fallback Optional fallback if slug is empty
|
||||
* @return string
|
||||
*/
|
||||
public static function generate(string $title, ?string $fallback = null): string
|
||||
{
|
||||
$slugify = new Slugify(['lowercase' => true]);
|
||||
|
||||
// Try to generate slug with cocur/slugify
|
||||
$slug = $slugify->slugify($title);
|
||||
|
||||
// If slug is empty (happens with pure Japanese/Chinese characters),
|
||||
// use fallback or generate a unique identifier
|
||||
if (empty($slug)) {
|
||||
if ($fallback) {
|
||||
$slug = $fallback;
|
||||
} else {
|
||||
// Use timestamp + random string for unique slug
|
||||
$slug = date('YmdHis') . '-' . Str::random(8);
|
||||
}
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user