Change d'interface plus légére, modification side barre

This commit is contained in:
2025-12-24 16:14:17 +01:00
parent cc1d6880a7
commit 917a31d5a8
46 changed files with 7484 additions and 298 deletions

155
CLAUDE.md
View File

@ -9,11 +9,13 @@ A lightweight web-based Markdown note-taking application with a Go backend and m
**Key Features**:
- **Daily Notes**: Quick daily journaling with interactive calendar, keyboard shortcuts (Ctrl/Cmd+D), and structured templates
- **Favorites System**: Star important notes and folders for quick access from the sidebar
- **Public Notes**: Share selected notes publicly without authentication via server-rendered HTML pages
- **Note Linking**: Create links between notes with `/link` command and fuzzy search modal
- **Vim Mode**: Full Vim keybindings support (hjkl navigation, modes, commands) for power users
- **Multiple Themes**: 8 dark themes (Material Dark, Monokai, Dracula, One Dark, Solarized, Nord, Catppuccin, Everforest)
- **Font Customization**: 8 fonts (JetBrains Mono, Fira Code, Inter, etc.) with 4 size options
- **Keyboard Shortcuts**: 10+ global shortcuts for navigation, editing, and productivity
- **Internationalization**: Full i18n support with English and French translations, automatic language detection
**Recent Modernization**: The project has been migrated from a simple textarea editor to CodeMirror 6, with a Vite build system for frontend modules. The backend remains unchanged, maintaining the same Go architecture with htmx for dynamic interactions.
@ -21,31 +23,41 @@ A lightweight web-based Markdown note-taking application with a Go backend and m
### Backend (Go)
Four main packages under `internal/`:
Five main packages under `internal/`:
- **indexer**: Maintains an in-memory index mapping tags to note files. Parses YAML front matter from `.md` files to build the index. Thread-safe with RWMutex.
- **watcher**: Uses `fsnotify` to monitor filesystem changes and trigger re-indexing with 200ms debounce. Recursively watches all subdirectories.
- **i18n**: Internationalization support with JSON-based translations. Loads translations at startup and provides `T()` function for translation lookups with variable interpolation.
- **api**: HTTP handlers that serve templates and handle CRUD operations on notes. Updates front matter automatically on save.
- `handler.go` - Main HTML endpoints for the web interface
- `rest_handler.go` - REST API endpoints (v1)
- `daily_notes.go` - Daily note creation and calendar functionality
- `favorites.go` - Favorites management (star/unstar notes and folders)
- `public.go` - Public notes sharing with server-side HTML rendering
The server (`cmd/server/main.go`) coordinates these components:
1. Loads initial index from notes directory
2. Starts filesystem watcher for automatic re-indexing
3. Pre-parses HTML templates from `templates/`
4. Serves routes:
2. Loads translations from `locales/` directory (JSON files for each language)
3. Starts filesystem watcher for automatic re-indexing
4. Pre-parses HTML templates from `templates/`
5. Serves routes:
- `/` (main page)
- `/api/v1/notes` and `/api/v1/notes/*` (REST API - JSON responses)
- `/api/i18n/{lang}` (Translation JSON endpoint)
- `/api/search` (HTML search results)
- `/api/notes/*` (HTML editor for notes)
- `/api/tree` (HTML file tree)
- `/api/folders/create` (Folder management)
- `/api/files/move` (File/folder moving)
- `/api/home` (Home page)
- `/api/daily-notes/*` (Daily note creation and calendar)
- `/api/favorites/*` (Favorites management)
5. Handles static files from `static/` directory
- `/api/about` (About page)
- `/api/daily` and `/api/daily/*` (Daily note creation and calendar)
- `/api/favorites` (Favorites management)
- `/api/folder/*` (Folder view)
- `/public` (Public notes list - no auth required)
- `/public/view/*` (View public note - no auth required)
- `/api/public/toggle` (Toggle public status - requires auth in production)
- `/api/public/list` (List public notes JSON)
6. Handles static files from `static/` directory and `public/` directory (for public HTML exports)
### Frontend
@ -69,9 +81,14 @@ frontend/src/
├── file-tree.js # Drag-and-drop file organization
├── favorites.js # Favorites system (star/unstar functionality)
├── daily-notes.js # Daily notes creation and calendar widget
├── public-toggle.js # Public/private status toggle for notes
├── keyboard-shortcuts.js # Global keyboard shortcuts management
├── theme-manager.js # Theme switching and persistence
├── font-manager.js # Font selection and size management
├── i18n.js # i18n client with translation function and language detection
├── language-manager.js # Language selector UI and page translation
├── sidebar-sections.js # Sidebar sections management (Recent/Favorites/All notes)
├── debug.js # Debug utilities
└── ui.js # Sidebar toggle functionality
```
@ -289,6 +306,33 @@ The favorites system allows quick access to frequently used notes and folders:
Favorites are loaded on server startup and updated in real-time via htmx.
### Public Notes
**Implementation**: `internal/api/public.go` and `frontend/src/public-toggle.js`
The public notes feature allows sharing selected notes publicly without requiring authentication:
**Features**:
- **Toggle Button**: Click 🔒 Privé/🌐 Public button in the editor to publish/unpublish notes
- **Server-side Rendering**: Notes converted to HTML using `goldmark` (Go Markdown library)
- **Public Routes**: `/public` (list) and `/public/view/{path}` (individual note) - no auth required
- **Persistence**: Public notes list stored in `notes/.public.json`
- **GitHub Flavored Markdown**: Supports tables, strikethrough, task lists, syntax highlighting
- **SEO-friendly**: Pre-rendered HTML with proper meta tags
- **Internationalized**: Full i18n support for public pages
**Security Model**:
- Public routes (`/public*`) are accessible without authentication
- Admin routes (`/api/public/toggle`) should be protected by reverse proxy auth (Authelia, Authentik, Basic Auth)
- In production, use nginx/Caddy with auth to protect all routes except `/public*`
**Command-line tool**:
```bash
go run ./cmd/server list-public # List all published notes
```
**Documentation**: See `PUBLIC_NOTES.md` for complete security recommendations and usage guide.
### Note Format
Notes have YAML front matter with these fields:
@ -372,6 +416,7 @@ go mod tidy
Key backend dependencies:
- `github.com/fsnotify/fsnotify` - Filesystem watcher
- `gopkg.in/yaml.v3` - YAML parsing for front matter
- `github.com/yuin/goldmark` - Markdown to HTML conversion for public notes (with GFM extensions)
### Vite Build System
@ -510,6 +555,65 @@ Themes are applied via CSS custom properties and persist in localStorage.
Font settings apply to both the editor and preview pane.
### Internationalization (i18n)
**Implementation**: `internal/i18n/i18n.go`, `frontend/src/i18n.js`, `frontend/src/language-manager.js`
The application provides full internationalization support:
#### Backend (Go)
- **Package**: `internal/i18n/i18n.go` - Translation engine with JSON-based translation files
- **Storage**: Translation files in `locales/` directory (e.g., `en.json`, `fr.json`)
- **Loading**: Translations loaded once at server startup from `locales/` directory
- **Translation Function**: `T(lang, key, vars...)` - Looks up translation keys with optional variable interpolation
- **API Endpoint**: `/api/i18n/{lang}` - Serves translation JSON for frontend consumption
- **Helper Functions**: `getLanguage(r)` and `t(r, key, vars...)` in handler.go for request-scoped translations
#### Frontend (JavaScript)
- **Module**: `frontend/src/i18n.js` - Client-side translation with automatic language detection
- **Detection Order**:
1. localStorage (`language` key)
2. Browser language (navigator.language)
3. Default to English
- **Translation Function**: `t(key, vars)` - Looks up translations with variable interpolation
- **Page Translation**: `translatePage()` - Automatically translates elements with `data-i18n` attributes
- **Language Manager**: `frontend/src/language-manager.js` - UI for language selection in Settings modal
- **Persistence**: Language preference stored in localStorage
- **Reload**: Automatic page translation on language change
#### Available Languages
- **English** (en) - Default language
- **French** (fr) - Full translation
#### Adding New Languages
1. Create new JSON file in `locales/` (e.g., `locales/es.json`)
2. Copy structure from `en.json` with 200+ translation keys
3. Translate all keys maintaining the nested structure
4. Add language option to Settings modal in templates
5. Restart server to load new translations
#### Translation Key Structure
```
app.name → "Personotes"
menu.home → "Home" / "Accueil"
editor.save → "Save" / "Sauvegarder"
editor.confirmDelete → "Are you sure...?" (supports {{filename}} interpolation)
errors.methodNotAllowed → "Method not allowed" / "Méthode non supportée"
```
#### Variable Interpolation
```javascript
// JavaScript
t('editor.confirmDelete', { filename: 'test.md' })
// → "Are you sure you want to delete this note (test.md)?"
// Go
h.t(r, "editor.confirmDelete", map[string]string{"filename": "test.md"})
// → "Êtes-vous sûr de vouloir supprimer cette note (test.md) ?"
```
**Documentation**: See `I18N_IMPLEMENTATION.md` for complete implementation details.
### Vim Mode
**Implementation**: `frontend/src/vim-mode-manager.js` using `@replit/codemirror-vim`
@ -565,6 +669,13 @@ File path validation in `handler.go` and `rest_handler.go`:
- CORS not configured (same-origin only)
- No rate limiting (add middleware if needed)
**Public Notes Security**:
- Routes `/public` and `/public/view/*` are intentionally public (no auth required)
- Route `/api/public/toggle` MUST be protected in production (requires auth to publish/unpublish)
- Use reverse proxy (nginx with Authelia/Authentik, or Basic Auth) to protect admin routes
- Public HTML is server-rendered with goldmark (prevents XSS, safe rendering)
- See `PUBLIC_NOTES.md` for complete security setup guide
### Template System
Templates are pre-parsed at startup. The API handler returns HTML fragments that htmx inserts into the page. Out-of-band swaps update the file tree sidebar without full page reload.
@ -752,10 +863,14 @@ personotes/
│ │ ├── handler.go # HTTP handlers for CRUD operations
│ │ ├── rest_handler.go # REST API v1 endpoints
│ │ ├── daily_notes.go # Daily notes functionality
│ │ ── favorites.go # Favorites management
│ │ ── favorites.go # Favorites management
│ │ └── public.go # Public notes sharing
│ ├── indexer/
│ │ ├── indexer.go # Note indexing and search
│ │ └── indexer_test.go # Indexer tests
│ ├── i18n/
│ │ ├── i18n.go # Internationalization engine
│ │ └── i18n_test.go # i18n tests
│ └── watcher/
│ └── watcher.go # Filesystem watcher with fsnotify
├── frontend/ # Frontend build system
@ -767,9 +882,15 @@ personotes/
│ │ ├── file-tree.js # Drag-and-drop file tree
│ │ ├── favorites.js # Favorites system
│ │ ├── daily-notes.js # Daily notes and calendar widget
│ │ ├── public-toggle.js # Public/private status toggle
│ │ ├── keyboard-shortcuts.js # Global keyboard shortcuts
│ │ ├── theme-manager.js # Theme switching
│ │ ├── font-manager.js # Font customization
│ │ ├── i18n.js # i18n client and translation
│ │ ├── language-manager.js # Language selector UI
│ │ ├── link-inserter.js # Note linking modal
│ │ ├── sidebar-sections.js # Sidebar sections management
│ │ ├── debug.js # Debug utilities
│ │ └── ui.js # Sidebar toggle
│ ├── package.json # NPM dependencies
│ ├── package-lock.json
@ -785,11 +906,20 @@ personotes/
│ ├── file-tree.html # File tree sidebar
│ ├── search-results.html # Search results
│ └── new-note-prompt.html # New note modal
├── locales/ # i18n translation files
│ ├── en.json # English translations (200+ keys)
│ ├── fr.json # French translations (200+ keys)
│ └── README.md # Translation guide
├── notes/ # Note storage directory
│ ├── *.md # Markdown files with YAML front matter
│ ├── daily/ # Daily notes (YYYY-MM-DD.md)
│ ├── .favorites.json # Favorites list (auto-generated)
│ ├── .public.json # Public notes list (auto-generated)
│ └── daily-note-template.md # Optional daily note template
├── public/ # Public HTML exports (auto-generated)
│ ├── index.html # Public notes list page
│ ├── *.html # Individual public notes (HTML)
│ └── static/ # Static assets for public pages
├── docs/ # Documentation
│ ├── KEYBOARD_SHORTCUTS.md # Keyboard shortcuts reference
│ ├── DAILY_NOTES.md # Daily notes guide
@ -798,6 +928,8 @@ personotes/
├── go.mod # Go dependencies
├── go.sum
├── API.md # REST API documentation
├── I18N_IMPLEMENTATION.md # i18n implementation guide
├── PUBLIC_NOTES.md # Public notes documentation and security guide
└── CLAUDE.md # This file
```
@ -809,8 +941,10 @@ personotes/
- `internal/api/rest_handler.go` - REST API v1 endpoints
- `internal/api/daily_notes.go` - Daily notes and calendar functionality
- `internal/api/favorites.go` - Favorites management
- `internal/api/public.go` - Public notes sharing and HTML export
- `internal/indexer/indexer.go` - Search and indexing logic
- `internal/watcher/watcher.go` - Filesystem monitoring
- `internal/i18n/i18n.go` - Internationalization engine
**Frontend Development**:
- `frontend/src/editor.js` - CodeMirror editor, preview, slash commands
@ -820,12 +954,17 @@ personotes/
- `frontend/src/file-tree.js` - File tree interactions and drag-and-drop
- `frontend/src/favorites.js` - Favorites system
- `frontend/src/daily-notes.js` - Daily notes creation and calendar widget
- `frontend/src/public-toggle.js` - Public/private status toggle
- `frontend/src/keyboard-shortcuts.js` - Global keyboard shortcuts
- `frontend/src/theme-manager.js` - Theme switching logic
- `frontend/src/font-manager.js` - Font customization logic
- `frontend/src/i18n.js` - i18n client and translation
- `frontend/src/language-manager.js` - Language selector UI
- `frontend/src/sidebar-sections.js` - Sidebar sections management
- `frontend/src/ui.js` - UI utilities (sidebar toggle)
- `static/theme.css` - Styling and theming (8 themes)
- `templates/*.html` - HTML templates (Go template syntax)
- `locales/*.json` - Translation files (en.json, fr.json)
**Configuration**:
- `frontend/vite.config.js` - Frontend build configuration