feat(news): redesign news detail page

This commit is contained in:
2026-07-06 22:45:19 +02:00
parent b9d382c78a
commit 03a2954c72
4 changed files with 510 additions and 102 deletions
+1
View File
@@ -29,6 +29,7 @@ class MatchedTopic(BaseModel):
subfield_name: Optional[str] = None
field_name: Optional[str] = None
domain_name: Optional[str] = None
source_keyword: Optional[str] = None
class NewsArticleDetail(NewsArticle):
@@ -54,7 +54,10 @@
<div class="article-body">
@if (article.full_content) {
<p class="content">{{ article.full_content }}</p>
<p
#articleBody
class="content"
[innerHTML]="highlightedContent"></p>
} @else {
<p class="placeholder">Kein Inhalt verfügbar.</p>
}
@@ -76,81 +79,155 @@
<aside class="sidebar">
<div class="sidebar-card">
<h3>
<mat-icon>group</mat-icon>
Erwähnte Personen
</h3>
<div class="person-list">
@if (article.authors && article.authors.length) {
@for (person of article.authors; track person.name) {
@if (person.is_ude && person.person_id) {
<a
class="person-item is-link"
[routerLink]="['/person', person.person_id, 'overview']">
<div class="avatar">{{ person.name.charAt(0) }}</div>
<span class="person-name">{{ person.name }}</span>
<span class="ude-badge">UDE</span>
</a>
<div class="accordion-panel">
<button
type="button"
class="accordion-header"
(click)="personsOpen = !personsOpen"
[attr.aria-expanded]="personsOpen">
<mat-icon>group</mat-icon>
<span class="accordion-title">Erwähnte Personen</span>
@if (article.authors?.length) {
<span class="count-badge">{{ article.authors!.length }}</span>
}
<mat-icon class="chevron" [class.rotated]="!personsOpen"
>expand_more</mat-icon
>
</button>
@if (personsOpen) {
<div class="accordion-body">
@if (article.authors && article.authors.length) {
<div class="person-list">
@for (person of article.authors; track person.name) {
@if (person.is_ude && person.person_id) {
<a
class="person-item is-link"
[routerLink]="[
'/person',
person.person_id,
'overview',
]">
<div class="avatar">
{{ personInitials(person.name) }}
</div>
<span class="person-name">{{ person.name }}</span>
<span class="ude-badge">UDE</span>
</a>
} @else {
<div class="person-item is-muted">
<div class="avatar">
{{ personInitials(person.name) }}
</div>
<span class="person-name">{{ person.name }}</span>
</div>
}
}
</div>
} @else {
<article class="person-item is-muted">
<div class="avatar">{{ person.name.charAt(0) }}</div>
<span class="person-name">{{ person.name }}</span>
</article>
<p class="placeholder">Keine erwähnten Personen gefunden.</p>
}
}
} @else {
<p class="placeholder">Keine erwähnten Personen gefunden.</p>
</div>
}
</div>
</div>
<div class="sidebar-card">
<h3>
<mat-icon>label</mat-icon>
Schlüsselwörter
</h3>
<div class="chip-list">
@if (article.keywords && article.keywords.length) {
@for (
keyword of article.keywords;
track keyword;
let i = $index
) {
<span
class="topic-chip"
(click)="onKeywordClick(keyword)"
[ngClass]="chipColor(i)"
>{{ keyword }}</span
>
<div class="accordion-panel">
<button
type="button"
class="accordion-header"
(click)="topicsOpen = !topicsOpen"
[attr.aria-expanded]="topicsOpen">
<mat-icon>label</mat-icon>
<span class="accordion-title">Themen & Schlüsselwörter</span>
@if (article.topics?.length) {
<span class="count-badge">{{ article.topics!.length }}</span>
}
} @else {
<p class="placeholder">Keine Schlüsselwörter gefunden.</p>
}
</div>
</div>
<div class="sidebar-card">
<h3>
<mat-icon>label</mat-icon>
Relevante Themen
</h3>
<div class="chip-list">
@if (article.topics && article.topics.length) {
@for (
topic of article.topics;
track topic.id ?? topic.display_name
) {
<app-topic-chip
[label]="topic.display_name ?? ''"
[subfieldName]="topic.subfield_name"
[fieldName]="topic.field_name"
[domainName]="topic.domain_name"
[color]="getTopicColor(topic)"
[disabled]="true">
</app-topic-chip>
}
} @else {
<p class="placeholder">Keine Themen gefunden.</p>
<mat-icon class="chevron" [class.rotated]="!topicsOpen"
>expand_more</mat-icon
>
</button>
@if (topicsOpen) {
<div class="accordion-body">
@if (article.topics && article.topics.length) {
<div class="topics-accordion">
@for (
topic of article.topics;
track topic.id ?? topic.display_name
) {
<div
class="topic-item"
[style.--t]="getTopicColor(topic)">
<button
type="button"
class="topic-item-header"
[class.is-expanded]="expandedTopicId === topic.id"
(click)="toggleTopic(topic.id)">
<span class="topic-item-name">{{
topic.display_name
}}</span>
<mat-icon>{{
expandedTopicId === topic.id
? 'expand_less'
: 'expand_more'
}}</mat-icon>
</button>
@if (expandedTopicId === topic.id) {
<div class="topic-item-body">
@if (topic.source_keyword) {
<p class="kw-suggestion-label">
Vorgeschlagen durch das Schlüsselwort im Text:
</p>
<button
type="button"
class="kw-pill"
(click)="scrollToKeyword(topic.source_keyword)">
»{{ topic.source_keyword }}«
</button>
<p class="kw-hint">
Im Artikel hervorgehoben · klicken zum Springen
</p>
} @else {
<p class="placeholder">
Kein Schlüsselwort verknüpft.
</p>
}
</div>
}
</div>
}
</div>
@if (orphanKeywords.length) {
<div class="chip-group" style="margin-top: 14px">
<span class="chip-group-label"
>Weitere Schlüsselwörter</span
>
<div class="chip-list">
@for (
keyword of orphanKeywords;
track keyword;
let i = $index
) {
<button
type="button"
class="topic-chip kw-chip"
[ngClass]="[
chipColor(i),
activeKeyword === keyword ? 'is-active' : '',
]"
(click)="scrollToKeyword(keyword)">
{{ keyword }}
</button>
}
</div>
</div>
}
} @else {
<p class="placeholder">
Keine Themen oder Schlüsselwörter gefunden.
</p>
}
</div>
}
</div>
</div>
@@ -54,7 +54,7 @@
.detail-layout {
display: grid;
grid-template-columns: 1fr 280px;
grid-template-columns: 1fr 288px;
gap: 40px;
align-items: start;
}
@@ -137,12 +137,15 @@ main {
margin: 0;
color: var(--sg-text-muted);
font-style: italic;
font-size: 13px;
}
.article-actions {
margin-top: 32px;
}
// ── Sidebar ──────────────────────────────────────────────────────────────────
.sidebar {
display: flex;
flex-direction: column;
@@ -154,45 +157,87 @@ main {
}
.sidebar-card {
padding: 20px;
border: 1px solid #d7e4ff;
border-radius: 16px;
background: #ffffff;
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
overflow: hidden;
}
h3 {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 14px;
font-size: 14px;
font-weight: 600;
color: var(--sg-text);
// ── Accordion ────────────────────────────────────────────────────────────────
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
color: var(--sg-text-muted);
}
.accordion-panel {
display: block;
}
.accordion-header {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
padding: 16px 20px;
background: none;
border: none;
cursor: pointer;
text-align: left;
font-size: 14px;
font-weight: 600;
color: var(--sg-text);
transition: background 0.12s;
&:hover {
background: #f6f9ff;
}
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
color: var(--sg-text-muted);
flex-shrink: 0;
}
}
.accordion-title {
flex: 1;
}
.count-badge {
padding: 2px 7px;
border-radius: 999px;
background: #e8effe;
color: #3b5bd6;
font-size: 11px;
font-weight: 700;
}
.chevron {
transition: transform 0.2s ease;
color: var(--sg-text-muted) !important;
&.rotated {
transform: rotate(-90deg);
}
}
.accordion-body {
padding: 0 20px 16px;
}
// ── Persons ───────────────────────────────────────────────────────────────────
.person-list {
display: flex;
flex-direction: column;
gap: 8px;
max-height: 375px;
overflow-y: auto;
padding-right: 4px;
gap: 6px;
}
.person-item {
display: grid;
grid-template-columns: 38px minmax(0, 1fr) auto;
gap: 11px;
grid-template-columns: 36px minmax(0, 1fr) auto;
gap: 10px;
align-items: center;
padding: 12px;
padding: 10px 12px;
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-muted);
}
@@ -234,32 +279,152 @@ main {
.avatar {
display: grid;
place-items: center;
width: 38px;
height: 38px;
width: 36px;
height: 36px;
border-radius: 50%;
background: #e5ecfb;
color: var(--sg-text);
font-size: 15px;
font-size: 13px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.04em;
flex-shrink: 0;
}
.person-name {
color: var(--sg-text);
font-size: 13px;
font-weight: 700;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
// ── Topic accordion items ─────────────────────────────────────────────────────
.topics-accordion {
display: flex;
flex-direction: column;
gap: 8px;
}
.topic-item {
border-radius: 12px;
overflow: hidden;
border: 1.5px solid color-mix(in srgb, var(--t) 38%, #ffffff);
}
.topic-item-header {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
padding: 11px 14px;
background: color-mix(in srgb, var(--t) 13%, #ffffff);
color: color-mix(in srgb, var(--t) 90%, #0f172a);
border: none;
cursor: pointer;
text-align: left;
font-size: 13px;
font-weight: 600;
line-height: 1.35;
transition: background 0.15s;
&:hover {
background: color-mix(in srgb, var(--t) 22%, #ffffff);
}
&.is-expanded {
background: var(--t);
color: #ffffff;
mat-icon {
color: rgba(255, 255, 255, 0.85);
}
}
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
flex-shrink: 0;
color: color-mix(in srgb, var(--t) 70%, #0f172a);
}
}
.topic-item-name {
flex: 1;
}
.topic-item-body {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 8px;
padding: 14px 14px 14px;
background: #ffffff;
}
.kw-suggestion-label {
margin: 0;
font-size: 12px;
color: var(--sg-text-muted);
}
.kw-pill {
display: inline-flex;
align-items: center;
padding: 6px 14px;
border-radius: 999px;
border: 1.5px solid color-mix(in srgb, var(--t) 50%, #ffffff);
background: color-mix(in srgb, var(--t) 10%, #ffffff);
color: color-mix(in srgb, var(--t) 90%, #0f172a);
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: background 0.12s;
&:hover {
background: color-mix(in srgb, var(--t) 22%, #ffffff);
}
}
.kw-hint {
margin: 0;
font-size: 11px;
color: var(--sg-text-muted);
}
// ── Topics & Keywords ─────────────────────────────────────────────────────────
.chip-group {
display: flex;
flex-direction: column;
gap: 8px;
& + .chip-group {
margin-top: 14px;
}
}
.chip-group-label {
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--sg-text-muted);
}
.chip-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
gap: 6px;
}
.topic-chip {
display: inline-flex;
align-items: center;
padding: 6px 12px;
padding: 5px 11px;
border: 1px solid var(--topic-border);
border-radius: 8px;
background: var(--topic-bg);
@@ -269,6 +434,22 @@ main {
line-height: 1.25;
}
.kw-chip {
cursor: pointer;
transition:
box-shadow 0.12s,
background 0.12s;
&:hover {
box-shadow: 0 0 0 2px var(--topic-border);
}
&.is-active {
box-shadow: 0 0 0 2px var(--topic-color);
font-weight: 600;
}
}
.purple {
--topic-border: #d8cafe;
--topic-bg: #f6f0ff;
@@ -298,3 +479,39 @@ main {
--topic-bg: #fff1f5;
--topic-color: #d12f61;
}
// ── Keyword highlights in article text ───────────────────────────────────────
@keyframes kw-flash {
0% {
background: color-mix(in srgb, var(--t) 45%, #ffffff);
}
40% {
background: color-mix(in srgb, var(--t) 45%, #ffffff);
}
100% {
background: transparent;
}
}
:host ::ng-deep .kw-mark {
background: transparent;
color: var(--t);
text-decoration: underline;
text-decoration-color: var(--t);
text-decoration-style: solid;
text-decoration-thickness: 2px;
text-underline-offset: 2px;
font-weight: inherit;
border-radius: 2px;
padding: 0 1px;
transition: background 0.15s;
&:hover {
background: color-mix(in srgb, var(--t) 15%, #ffffff);
}
&.kw-flash {
animation: kw-flash 2.4s ease-out forwards;
}
}
@@ -1,4 +1,11 @@
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
import {
Component,
DestroyRef,
ElementRef,
OnInit,
ViewChild,
inject,
} from '@angular/core';
import { Location, NgClass } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, RouterLink } from '@angular/router';
@@ -6,9 +13,9 @@ import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Router } from '@angular/router';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { WorksService } from '../../api';
import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.component';
import { topicHierarchyColor } from '../../shared/utils/topic-colors';
interface MentionedPerson {
@@ -23,6 +30,7 @@ interface MatchedTopic {
subfield_name?: string | null;
field_name?: string | null;
domain_name?: string | null;
source_keyword?: string | null;
}
interface NewsArticleDetail {
@@ -46,23 +54,30 @@ interface NewsArticleDetail {
MatProgressSpinnerModule,
RouterLink,
NgClass,
TopicChipComponent,
],
templateUrl: './news-detail.component.html',
styleUrl: './news-detail.component.scss',
})
export class NewsDetailComponent implements OnInit {
@ViewChild('articleBody') articleBodyRef?: ElementRef<HTMLElement>;
private readonly destroyRef = inject(DestroyRef);
private readonly route = inject(ActivatedRoute);
private readonly httpClient = inject(HttpClient);
private readonly worksService = inject(WorksService);
private readonly location = inject(Location);
private readonly router = inject(Router);
private readonly sanitizer = inject(DomSanitizer);
article: NewsArticleDetail | null = null;
highlightedContent: SafeHtml = this.sanitizer.bypassSecurityTrustHtml('');
loading = false;
notFound = false;
personsOpen = true;
topicsOpen = true;
activeKeyword: string | null = null;
expandedTopicId: string | null = null;
private readonly chipColors = ['purple', 'blue', 'green', 'orange', 'pink'];
getTopicColor(topic: MatchedTopic): string {
@@ -79,6 +94,45 @@ export class NewsDetailComponent implements OnInit {
return this.chipColors[index % this.chipColors.length];
}
personInitials(name: string): string {
const parts = name.trim().split(/\s+/);
if (parts.length === 1) return parts[0].charAt(0).toUpperCase();
return (
parts[0].charAt(0) + parts[parts.length - 1].charAt(0)
).toUpperCase();
}
get orphanKeywords(): string[] {
const keywords = this.article?.keywords ?? [];
const topics = this.article?.topics ?? [];
const usedKeywords = new Set(
topics.map((t) => t.source_keyword?.toLowerCase()).filter(Boolean),
);
return keywords.filter((kw) => !usedKeywords.has(kw.toLowerCase()));
}
toggleTopic(id: string | null | undefined): void {
this.expandedTopicId = this.expandedTopicId === id ? null : (id ?? null);
}
scrollToKeyword(keyword: string): void {
this.activeKeyword = keyword;
const body = this.articleBodyRef?.nativeElement;
if (!body) return;
body
.querySelectorAll<HTMLElement>('.kw-flash')
.forEach((el) => el.classList.remove('kw-flash'));
const marks = body.querySelectorAll<HTMLElement>('[data-kw]');
for (const mark of Array.from(marks)) {
if (mark.dataset['kw']?.toLowerCase() === keyword.toLowerCase()) {
mark.scrollIntoView({ behavior: 'smooth', block: 'center' });
mark.classList.add('kw-flash');
setTimeout(() => mark.classList.remove('kw-flash'), 2400);
break;
}
}
}
ngOnInit(): void {
this.route.paramMap
.pipe(takeUntilDestroyed(this.destroyRef))
@@ -119,6 +173,9 @@ export class NewsDetailComponent implements OnInit {
.subscribe({
next: (article) => {
this.article = article;
this.highlightedContent = this.buildHighlightedContent(article);
this.activeKeyword = null;
this.expandedTopicId = null;
this.loading = false;
},
error: () => {
@@ -127,4 +184,60 @@ export class NewsDetailComponent implements OnInit {
},
});
}
private buildHighlightedContent(article: NewsArticleDetail): SafeHtml {
const text = article.full_content;
if (!text) return this.sanitizer.bypassSecurityTrustHtml('');
const keywords = article.keywords ?? [];
const keywordColorMap = new Map<string, string>();
for (const topic of article.topics ?? []) {
if (topic.source_keyword) {
keywordColorMap.set(
topic.source_keyword.toLowerCase(),
this.getTopicColor(topic),
);
}
}
const orphanColors = [
'#7255d9',
'#0b63ce',
'#24834f',
'#c67500',
'#d12f61',
];
let orphanIdx = 0;
let html = this.escapeHtml(text);
if (keywords.length) {
[...keywords]
.sort((a, b) => b.length - a.length)
.forEach((kw) => {
let color = keywordColorMap.get(kw.toLowerCase());
if (!color) {
color = orphanColors[orphanIdx % orphanColors.length];
orphanIdx++;
}
const kwHtml = this.escapeHtml(kw);
const re = new RegExp(`(${this.escapeRegex(kwHtml)})`, 'gi');
html = html.replace(
re,
`<mark class="kw-mark" style="--t:${color}" data-kw="${kwHtml}">$1</mark>`,
);
});
}
return this.sanitizer.bypassSecurityTrustHtml(html);
}
private escapeHtml(text: string): string {
return text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
private escapeRegex(text: string): string {
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
}