Add badge with link to author profile in news
This commit is contained in:
@@ -10,8 +10,8 @@ from fastapi import HTTPException
|
||||
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR
|
||||
|
||||
from ..integrations import elasticsearch
|
||||
from ..persons.logic import get_author_name_by_id
|
||||
from .model import NewsArticle, NewsArticleDetail, NewsPage
|
||||
from ..persons.logic import find_ude_author_by_name, get_author_name_by_id
|
||||
from .model import MentionedPerson, NewsArticle, NewsArticleDetail, NewsPage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -139,10 +139,24 @@ def get_news_by_id(news_id: str) -> NewsArticleDetail:
|
||||
url=source.get("url"),
|
||||
full_content=source.get("full_content"),
|
||||
relevant=relevant,
|
||||
authors=authors,
|
||||
authors=_build_mentioned_persons(authors),
|
||||
)
|
||||
|
||||
|
||||
def _build_mentioned_persons(author_names: list) -> list:
|
||||
|
||||
persons = []
|
||||
for name in author_names:
|
||||
match = find_ude_author_by_name(name)
|
||||
if match:
|
||||
persons.append(
|
||||
MentionedPerson(name=name, is_ude=True, person_id=match["id"])
|
||||
)
|
||||
else:
|
||||
persons.append(MentionedPerson(name=name))
|
||||
return persons
|
||||
|
||||
|
||||
def _get_postproc_labels(news_id: str) -> tuple[bool | None, list]:
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
|
||||
@@ -16,10 +16,16 @@ class NewsArticle(BaseModel):
|
||||
snippet: Optional[str] = None
|
||||
|
||||
|
||||
class MentionedPerson(BaseModel):
|
||||
name: str
|
||||
is_ude: bool = False
|
||||
person_id: Optional[str] = None
|
||||
|
||||
|
||||
class NewsArticleDetail(NewsArticle):
|
||||
full_content: Optional[str] = None
|
||||
relevant: Optional[bool] = None
|
||||
authors: List[str] = []
|
||||
authors: List[MentionedPerson] = []
|
||||
|
||||
|
||||
class NewsPage(BaseModel):
|
||||
|
||||
@@ -30,6 +30,60 @@ from inse.persons.model import (
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
INDEX_NAME = "openalex-authors"
|
||||
UDE_INSTITUTION_ID = "https://openalex.org/I62318514" # Universität Duisburg-Essen
|
||||
|
||||
def find_ude_author_by_name(display_name: str) -> Optional[dict]:
|
||||
query = {
|
||||
"_source": ["display_name"],
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"match_phrase": {
|
||||
"display_name": display_name
|
||||
}
|
||||
},
|
||||
{
|
||||
"nested": {
|
||||
"path": "affiliations",
|
||||
"query": {
|
||||
"term": {
|
||||
"affiliations.institution.id": UDE_INSTITUTION_ID
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
"size": 10,
|
||||
}
|
||||
|
||||
try:
|
||||
data = elasticsearch.search(index=INDEX_NAME, body=query)
|
||||
except Exception:
|
||||
logger.exception(f"UDE-Lookup für '{display_name}' fehlgeschlagen.")
|
||||
return None
|
||||
|
||||
hits = data.get("hits", {}).get("hits", [])
|
||||
|
||||
display_name = display_name.strip().lower()
|
||||
exact_matches = []
|
||||
|
||||
for hit in hits:
|
||||
hit_display_name = hit.get("_source", {}).get("display_name", "")
|
||||
if hit_display_name.strip().lower() == display_name:
|
||||
exact_matches.append(hit)
|
||||
|
||||
if not exact_matches:
|
||||
return None
|
||||
|
||||
hit = exact_matches[0]
|
||||
|
||||
return {
|
||||
"id": hit.get("_id"),
|
||||
"display_name": hit.get("_source", {}).get("display_name"),
|
||||
}
|
||||
|
||||
|
||||
def get_author_name_by_id(author_id: str) -> Optional[str]:
|
||||
|
||||
@@ -82,11 +82,21 @@
|
||||
</h3>
|
||||
<div class="person-list">
|
||||
@if (article.authors && article.authors.length) {
|
||||
@for (person of article.authors; track person) {
|
||||
<article class="person-item">
|
||||
<div class="avatar">{{ person.charAt(0) }}</div>
|
||||
<span class="person-name">{{ person }}</span>
|
||||
</article>
|
||||
@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>
|
||||
} @else {
|
||||
<article class="person-item">
|
||||
<div class="avatar">{{ person.name.charAt(0) }}</div>
|
||||
<span class="person-name">{{ person.name }}</span>
|
||||
</article>
|
||||
}
|
||||
}
|
||||
} @else {
|
||||
<p class="placeholder">Keine erwähnten Personen gefunden.</p>
|
||||
|
||||
@@ -184,7 +184,7 @@ main {
|
||||
|
||||
.person-item {
|
||||
display: grid;
|
||||
grid-template-columns: 38px minmax(0, 1fr);
|
||||
grid-template-columns: 38px minmax(0, 1fr) auto;
|
||||
gap: 11px;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
@@ -192,6 +192,29 @@ main {
|
||||
background: var(--sg-surface-muted);
|
||||
}
|
||||
|
||||
.person-item.is-link {
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.person-item.is-link:hover {
|
||||
background: #e5ecfb;
|
||||
}
|
||||
|
||||
.ude-badge {
|
||||
justify-self: end;
|
||||
padding: 3px 9px;
|
||||
border-radius: 999px;
|
||||
background: #effaf3;
|
||||
border: 1px solid #bdebcf;
|
||||
color: #24834f;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
|
||||
@@ -9,6 +9,12 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
|
||||
import { WorksService } from '../../api';
|
||||
|
||||
interface MentionedPerson {
|
||||
name: string;
|
||||
is_ude?: boolean;
|
||||
person_id?: string | null;
|
||||
}
|
||||
|
||||
interface NewsArticleDetail {
|
||||
id: string;
|
||||
date?: string | null;
|
||||
@@ -17,7 +23,7 @@ interface NewsArticleDetail {
|
||||
url?: string | null;
|
||||
full_content?: string | null;
|
||||
relevant?: boolean;
|
||||
authors?: string[];
|
||||
authors?: MentionedPerson[];
|
||||
}
|
||||
|
||||
@Component({
|
||||
|
||||
Reference in New Issue
Block a user