refactor(geschichte): add utils.ts (formatAuthorName/DisplayName/PublishedAt), update README
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 1m14s
CI / OCR Service Tests (pull_request) Successful in 23s
CI / Backend Unit Tests (pull_request) Successful in 3m46s
CI / fail2ban Regex (pull_request) Successful in 47s
CI / Semgrep Security Scan (pull_request) Successful in 23s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m8s
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 1m14s
CI / OCR Service Tests (pull_request) Successful in 23s
CI / Backend Unit Tests (pull_request) Successful in 3m46s
CI / fail2ban Regex (pull_request) Successful in 47s
CI / Semgrep Security Scan (pull_request) Successful in 23s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m8s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
28
frontend/src/lib/geschichte/utils.ts
Normal file
28
frontend/src/lib/geschichte/utils.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { formatDate } from '$lib/shared/utils/date';
|
||||
|
||||
type AuthorSummary = { firstName?: string; lastName?: string; email: string };
|
||||
type AuthorView = { displayName: string };
|
||||
|
||||
/** Format an author name from a list summary (firstName + lastName, falling back to email). */
|
||||
export function formatAuthorName(author: AuthorSummary | null | undefined): string {
|
||||
if (!author) return '';
|
||||
const full = [author.firstName, author.lastName].filter(Boolean).join(' ').trim();
|
||||
return full || author.email || '';
|
||||
}
|
||||
|
||||
/** Format an author displayName from a detail view. */
|
||||
export function formatAuthorDisplayName(author: AuthorView | null | undefined): string {
|
||||
return author?.displayName ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a publishedAt ISO string to a localised date string.
|
||||
* Returns null when publishedAt is absent.
|
||||
*/
|
||||
export function formatPublishedAt(
|
||||
publishedAt: string | null | undefined,
|
||||
style: 'short' | 'long' = 'short'
|
||||
): string | null {
|
||||
if (!publishedAt) return null;
|
||||
return formatDate(publishedAt.slice(0, 10), style);
|
||||
}
|
||||
Reference in New Issue
Block a user