diff --git a/src/app/portal/components/single/single-result-link/single-result-link.component.html b/src/app/portal/components/single/single-result-link/single-result-link.component.html index fa8b4d234..6c5265dea 100644 --- a/src/app/portal/components/single/single-result-link/single-result-link.component.html +++ b/src/app/portal/components/single/single-result-link/single-result-link.component.html @@ -6,24 +6,23 @@ diff --git a/src/app/portal/components/single/single-result-link/single-result-link.component.ts b/src/app/portal/components/single/single-result-link/single-result-link.component.ts index 5e7494347..624e6d2bb 100644 --- a/src/app/portal/components/single/single-result-link/single-result-link.component.ts +++ b/src/app/portal/components/single/single-result-link/single-result-link.component.ts @@ -5,30 +5,17 @@ // :author: CSC - IT Center for Science Ltd., Espoo Finland servicedesk@csc.fi // :license: MIT -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Input } from '@angular/core'; @Component({ selector: 'app-single-result-link', templateUrl: './single-result-link.component.html', styleUrls: ['./single-result-link.component.scss'], }) -export class SingleResultLinkComponent implements OnInit { +export class SingleResultLinkComponent { @Input() tag: string; @Input() icon: boolean; @Input() url: string; @Input() label: string; @Input() simple: boolean; - - constructor() {} - - ngOnInit(): void {} - - fixExternalUrl(url: string) { - // Fix url address to be handled as external link if prefix missing - return url.startsWith('http') - ? url - : url.startsWith('www') - ? 'https://' + url - : '//' + url; - } } diff --git a/src/app/portal/pipes/fix-external-url.pipe.ts b/src/app/portal/pipes/fix-external-url.pipe.ts new file mode 100644 index 000000000..1bed790d1 --- /dev/null +++ b/src/app/portal/pipes/fix-external-url.pipe.ts @@ -0,0 +1,16 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'fixExternalUrl', + standalone: true +}) +export class FixExternalUrlPipe implements PipeTransform { + transform(url: string): string { + // Fix url address to be handled as external link if prefix missing + return url.startsWith('http') + ? url + : url.startsWith('www') + ? 'https://' + url + : '//' + url; + } +} diff --git a/src/app/portal/portal.module.ts b/src/app/portal/portal.module.ts index ef2e55115..fd4c8a5cf 100644 --- a/src/app/portal/portal.module.ts +++ b/src/app/portal/portal.module.ts @@ -166,6 +166,7 @@ import { CheckEmptyFieldsPipe } from './pipes/check-empty-fields.pipe'; import { PersonGroupComponent } from './components/single/single-person/person-group/person-group.component'; import { PersonGroupAdditionalComponent } from './components/single/single-person/person-group-additional/person-group-additional.component'; import { FooterComponent } from '../layout/footer/footer.component'; +import { FixExternalUrlPipe } from '@portal/pipes/fix-external-url.pipe'; @NgModule({ declarations: [ @@ -287,7 +288,8 @@ import { FooterComponent } from '../layout/footer/footer.component'; TooltipModule.forRoot(), MatTableModule, MatSortModule, - FooterComponent + FooterComponent, + FixExternalUrlPipe ], exports: [DatasetAuthorComponent, FiltersComponent], providers: [