From 845039f9dffb3e5d788a038276a51e26f46726df Mon Sep 17 00:00:00 2001 From: _Bastler Date: Wed, 6 Oct 2021 12:56:10 +0200 Subject: [PATCH] base url --- src/app/app.module.ts | 3 ++- src/app/ui/entry/entry.ui.html | 1 + src/app/ui/entry/entry.ui.scss | 16 +++++++++++++++- src/app/utils/urltext.pipe.ts | 20 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2abbb27..44647d7 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -15,7 +15,7 @@ import { AutofocusDirective } from './material/autofocus'; import { I18nPipe } from './utils/i18n.pipe'; import { MomentPipe } from './utils/moment.pipe'; -import { UrlTextPipe } from './utils/urltext.pipe'; +import { UrlBasePipe, UrlTextPipe } from './utils/urltext.pipe'; import { AppComponent } from './app.component'; import { PageBookmarks } from './pages/bookmarks/bookmarks.page'; import { PageComment } from './pages/comment/comment.page'; @@ -80,6 +80,7 @@ export class XhrInterceptor implements HttpInterceptor { AutofocusDirective, I18nPipe, MomentPipe, + UrlBasePipe, UrlTextPipe, AppComponent, PageBookmarks, diff --git a/src/app/ui/entry/entry.ui.html b/src/app/ui/entry/entry.ui.html index 833e2d4..779b6dc 100644 --- a/src/app/ui/entry/entry.ui.html +++ b/src/app/ui/entry/entry.ui.html @@ -3,6 +3,7 @@ {{'entryType.' + entry.entryType + '.icon' | i18n}} {{entry.title}} {{entry.title}} + ({{entry.url | urlbase}})
diff --git a/src/app/ui/entry/entry.ui.scss b/src/app/ui/entry/entry.ui.scss index d5b0681..e10f33d 100644 --- a/src/app/ui/entry/entry.ui.scss +++ b/src/app/ui/entry/entry.ui.scss @@ -4,6 +4,20 @@ a.title { white-space: break-spaces; } +span.urlbase { + margin-left: 5px; + font-size: 0.7em; + color: $accent; + + a { + color: $accent; + } + + a::after { + display: none; + } +} + small a { color: inherit !important; text-decoration: none; @@ -27,4 +41,4 @@ span.voted { small .mat-icon { top: 2px; margin-right: 0px; -} \ No newline at end of file +} diff --git a/src/app/utils/urltext.pipe.ts b/src/app/utils/urltext.pipe.ts index 8172d25..58e4c75 100644 --- a/src/app/utils/urltext.pipe.ts +++ b/src/app/utils/urltext.pipe.ts @@ -11,4 +11,24 @@ export class UrlTextPipe implements PipeTransform { value = value.replace(this.wwwPattern, '$1$2'); return value; } +} + +@Pipe({ name: 'urlbase' }) +export class UrlBasePipe implements PipeTransform { + + httpPattern = /(\b(https?:\/\/)([-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]))/ig; + + transform(value: string): any { + if (!value.match(this.httpPattern)) { + return ''; + } + + const parts = value.split( '/' ) + + if (parts.length < 3) { + return ''; + } + + return parts[2]; + } } \ No newline at end of file