Skip to content

add reading time#366

Merged
LucaNerlich merged 2 commits intomainfrom
358-add-time-to-read-calculation-to-articles
Dec 25, 2025
Merged

add reading time#366
LucaNerlich merged 2 commits intomainfrom
358-add-time-to-read-calculation-to-articles

Conversation

@LucaNerlich
Copy link
Copy Markdown
Owner

@LucaNerlich LucaNerlich commented Dec 25, 2025

Summary by CodeRabbit

  • Neue Funktionen
    • Lesezeitanzeige für Artikel hinzugefügt – geschätzte Lesezeit wird im Artikelheader neben dem Veröffentlichungsdatum angezeigt (automatisch berechnet).
  • Style
    • Metadatenstil vereinheitlicht – Veröffentlichungsdatum und Lesezeit teilen jetzt Typografie und Abstand für konsistente Darstellung.

✏️ Tip: You can customize this high-level summary in your review settings.

@LucaNerlich LucaNerlich linked an issue Dec 25, 2025 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Fügt eine Lesezeitfunktion hinzu: neue Utility zum Berechnen der Lesezeit aus Markdown, Integration der Lesezeit in die Artikelseite (Header-Metadaten) und Anpassung der CSS-Selektoren für Metadatenanzeige.

Changes

Cohort / File(s) Zusammenfassung
Neue Lesezeitfunktion
frontend/src/lib/readingTime.ts
Neue exportierte Funktion calculateReadingTime(markdown: string): string. Entfernt Markdown-Syntax, normalisiert Whitespace, zählt Wörter und berechnet Lesezeit mit 250 WPM. Gibt "< 1 min read" oder " min read" zurück.
Lesezeitintegration in Seite
frontend/app/artikel/[slug]/page.tsx
Importiert calculateReadingTime, berechnet readingTime aus article.content und rendert die Lesezeit neben dem Veröffentlichungsdatum in den Header-Metadaten.
CSS für Metadaten
frontend/app/artikel/[slug]/page.module.css
Selector erweitert von .publishedDate zu .publishedDate, .readingTime; gemeinsame Stilregeln hinzugefügt/angepasst: display: block; color: var(--color-text-muted); font-size: 0.875rem; margin-bottom: 1rem; font-weight: 500.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Browser as Browser (Page)
participant Page as Artikel-Seite (page.tsx)
participant Util as readingTime util (readingTime.ts)
participant Article as Article Data (article.content)

Note over Page,Article: Seiten-Rendering beginnt
Page->>Article: lädt article.content
Page->>Util: ruft calculateReadingTime(article.content) auf
Util-->>Page: gibt formatted readingTime zurück
Page->>Browser: rendert Titel, publishedDate, readingTime, Beschreibung

rect rgb(220,235,255)
Note right of Util: Markdown-Sanitization → Wortzählung → Minutenberechnung
end

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • add reading time #366: Implementiert dieselbe reading-time-Änderung (neue calculateReadingTime, Rendering in page.tsx, CSS-Anpassung), daher stark inhaltlich verwandt.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Der Titel "add reading time" beschreibt präzise die Hauptänderung: Das Hinzufügen einer Lesezeitberechnung. Dies stimmt vollständig mit den Änderungen überein (neue CSS-Klasse, Komponenten-Integration und Utility-Funktion).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48dea12 and ee3668b.

📒 Files selected for processing (1)
  • frontend/app/artikel/[slug]/page.module.css

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
frontend/app/artikel/[slug]/page.module.css (1)

36-42: Styling ist korrekt, optionale Konsolidierung möglich

Die Styles für .readingTime sind identisch mit .publishedDate (Zeilen 28-34). Du könntest eine gemeinsame Klasse wie .metadata oder .metaText einführen und beide Elemente damit stylen, um Code-Duplikation zu vermeiden.

🔎 Optionaler Refactoring-Vorschlag
-.publishedDate {
+.metaText {
     display: block;
     color: var(--color-text-muted);
     font-size: 0.875rem;
     margin-bottom: 1rem;
     font-weight: 500;
 }

-.readingTime {
-    display: block;
-    color: var(--color-text-muted);
-    font-size: 0.875rem;
-    margin-bottom: 1rem;
-    font-weight: 500;
-}

Dann in page.tsx beide Elemente mit styles.metaText versehen.

frontend/src/lib/readingTime.ts (1)

10-77: Solide Implementierung der Lesezeitberechnung

Die Funktion ist gut strukturiert und dokumentiert:

  • Robustes Null-Handling und defensive Programmierung
  • Umfassendes Markdown-Stripping mit durchdachter Reihenfolge
  • 250 WPM ist ein angemessener Standard-Lesewert
  • Klare, wartbare Regex-Patterns

Ein kleiner Hinweis: Markdown-Kombinationen wie ***fett und kursiv*** werden von den aktuellen Regex-Patterns nicht vollständig erfasst, da \*\*([^*]+)\*\* und \*([^*]+)\* jeweils genau 2 bzw. 1 Stern erwarten. Dies könnte bei sehr seltenen Edge Cases zu minimal höheren Wortzählungen führen, ist aber für eine Lesezeitschätzung vernachlässigbar.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6aa2a06 and 48dea12.

📒 Files selected for processing (3)
  • frontend/app/artikel/[slug]/page.module.css
  • frontend/app/artikel/[slug]/page.tsx
  • frontend/src/lib/readingTime.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/security-global-dangerous-flows.mdc)

**/*.{js,ts,tsx}: Do not pass untrusted input to filesystem APIs (e.g., fs.readFile, fs.writeFile, path.join) without strict path validation/allow-lists
Do not interpolate untrusted input into shell/process execution (child_process.exec/spawn/execFile); avoid shell=True equivalents
Avoid dynamic code execution with user input (eval, new Function, setTimeout/setInterval with string)
Ensure user input rendered into HTML/templates (res.send, res.render, ejs/Handlebars/etc.) is properly escaped or sanitized to prevent XSS
Validate and restrict user-controlled URLs before making network requests (fetch, axios) to prevent SSRF

**/*.{js,ts,tsx}: Do not use user input (e.g., req.body, req.query) directly in fs, child_process, or other system-level calls
Do not use eval(), new Function(), or vm.runInNewContext() with user-controllable values
Avoid execSync, spawnSync, or shell execution with untrusted input; do not use synchronous child_process APIs unless strictly necessary and audited
Never hardcode secrets (API keys, private keys, credentials); use environment variables and secure config loading
Validate and sanitize all external inputs (query params, bodies, headers) before use in logic, queries, or file access
Escape dynamic output when inserting into HTML, Markdown, or CLI to prevent injection
Always use HTTPS for remote calls; do not disable SSL validation or use http in production
Do not modify native prototypes (e.g., Object.prototype) or rely on global mutation patterns
Avoid == and !=; always use === and !== for strict equality
Do not use dynamic or user-derived values in require(); use only static imports

Files:

  • frontend/app/artikel/[slug]/page.tsx
  • frontend/src/lib/readingTime.ts
**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/security-global-pathtraversal-prevention.mdc)

**/*.{js,ts}: JavaScript/TypeScript (Node): Use path.resolve/join for file paths and verify the final path starts with the intended directory
Validate JS/TS filenames with a strict allowlist or safe-character regex before file operations

Files:

  • frontend/src/lib/readingTime.ts
🔇 Additional comments (1)
frontend/app/artikel/[slug]/page.tsx (1)

17-17: Saubere Integration des Reading-Time-Features

Die Implementierung ist korrekt:

  • Import der Utility-Funktion ist sauber
  • Null-Handling mit ?? Operator ist robust
  • Die Ausgabe ist als einfacher String sicher vor XSS
  • Das Feature fügt sich konsistent in die bestehende Struktur ein

Also applies to: 82-82, 116-116

@LucaNerlich LucaNerlich merged commit 1ad10c5 into main Dec 25, 2025
1 check was pending
@LucaNerlich LucaNerlich deleted the 358-add-time-to-read-calculation-to-articles branch December 25, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "time to read" calculation to articles

1 participant