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:
2025-11-29 09:41:38 +09:00
commit 6e7f8566ef
140 changed files with 40590 additions and 0 deletions

View 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;
}
}