Open publication links directly as PDF with HTML fallback
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -77,7 +77,7 @@
|
||||
<ul class="publication-list">
|
||||
@for (id of getPublicationIds(selectedFunder); track id) {
|
||||
<li>
|
||||
<a [href]="id" target="_blank" rel="noopener">{{ id }}</a>
|
||||
<a [href]="id" target="_blank" rel="noopener" (click)="openPublication($event, id)">{{ id }}</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
@@ -15,6 +15,7 @@ export class PersonFundingComponent implements OnInit {
|
||||
private router = inject(Router);
|
||||
private personsApi = inject(PersonsOpenApiService);
|
||||
private initialSelectedFunderKey: string | null = null;
|
||||
private publicationUrlCache = new Map<string, string>();
|
||||
|
||||
funders: any[] = [];
|
||||
filteredFunders: any[] = [];
|
||||
@@ -124,6 +125,12 @@ export class PersonFundingComponent implements OnInit {
|
||||
return funder.publication_ids[this.activeFilter] ?? [];
|
||||
}
|
||||
|
||||
async openPublication(event: MouseEvent, publicationId: string): Promise<void> {
|
||||
event.preventDefault();
|
||||
const url = await this.resolvePreferredPublicationUrl(publicationId);
|
||||
window.open(url, '_blank', 'noopener');
|
||||
}
|
||||
|
||||
getPositionLabel(position: string): string {
|
||||
const labels: Record<string, string> = {
|
||||
first: 'Erstautor',
|
||||
@@ -149,4 +156,42 @@ export class PersonFundingComponent implements OnInit {
|
||||
}
|
||||
return allIds.size;
|
||||
}
|
||||
|
||||
private async resolvePreferredPublicationUrl(publicationId: string): Promise<string> {
|
||||
const cached = this.publicationUrlCache.get(publicationId);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
const fallbackUrl = publicationId;
|
||||
const workId = publicationId.replace('https://openalex.org/', '').trim();
|
||||
if (!workId) {
|
||||
return fallbackUrl;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`https://api.openalex.org/works/${encodeURIComponent(workId)}`);
|
||||
if (!response.ok) {
|
||||
return fallbackUrl;
|
||||
}
|
||||
|
||||
const work = await response.json();
|
||||
const pdfUrl =
|
||||
work?.primary_location?.pdf_url ??
|
||||
work?.best_oa_location?.pdf_url ??
|
||||
null;
|
||||
|
||||
const htmlUrl =
|
||||
work?.primary_location?.landing_page_url ??
|
||||
work?.best_oa_location?.landing_page_url ??
|
||||
work?.open_access?.oa_url ??
|
||||
null;
|
||||
|
||||
const resolvedUrl = pdfUrl || htmlUrl || fallbackUrl;
|
||||
this.publicationUrlCache.set(publicationId, resolvedUrl);
|
||||
return resolvedUrl;
|
||||
} catch {
|
||||
return fallbackUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user