Skip to content

Commit

Permalink
fix(angular-apollo-tailwind): append protocol if missing from user url
Browse files Browse the repository at this point in the history
Refs: #591
  • Loading branch information
asincole committed Sep 16, 2022
1 parent f6a9578 commit 84cbcdf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { GenerateUrlWithProtocolPipe } from './generate-url-with-protocol.pipe';

describe('GenerateUrlWithProtocolPipe', () => {
it('create an instance', () => {
const pipe = new GenerateUrlWithProtocolPipe();
expect(pipe).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'generateUrlWithProtocol',
})
export class GenerateUrlWithProtocolPipe implements PipeTransform {
transform(value: string): string {
return ['http://', 'https://'].some((protocol) =>
value.startsWith(protocol),
)
? value
: `https://${value}`;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './dfns/format-distance.pipe';
export * from './number/round-up.pipe';
export * from './markdown/markdown.pipe';
export * from './generate-url-with-protocol/generate-url-with-protocol.pipe';
export * from './pipes.module';
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ import { NgModule } from '@angular/core';
import { RoundUpPipe } from './number/round-up.pipe';
import { FormatDistancePipe } from './dfns/format-distance.pipe';
import { MarkdownPipe } from './markdown/markdown.pipe';
import { GenerateUrlWithProtocolPipe } from './generate-url-with-protocol/generate-url-with-protocol.pipe';

@NgModule({
declarations: [FormatDistancePipe, RoundUpPipe, MarkdownPipe],
exports: [FormatDistancePipe, RoundUpPipe, MarkdownPipe],
declarations: [
FormatDistancePipe,
RoundUpPipe,
MarkdownPipe,
GenerateUrlWithProtocolPipe,
],
exports: [
FormatDistancePipe,
RoundUpPipe,
MarkdownPipe,
GenerateUrlWithProtocolPipe,
],
})
export class PipesModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h1 class="mt-2">
></hero-icon>
<a
class="link"
[href]="user.websiteUrl"
[href]="user.websiteUrl | generateUrlWithProtocol"
target="_blank"
rel="noreferrer"
>
Expand All @@ -88,7 +88,7 @@ <h1 class="mt-2">
></sd-twitter-icon>
<a
class="link"
[href]="'https:/twitter.com/' + user.twitterUsername"
[href]="'https://twitter.com/' + user.twitterUsername"
target="_blank"
rel="noreferrer"
>
Expand Down
2 changes: 2 additions & 0 deletions angular-apollo-tailwind/src/app/profile/profile.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ProfileRepoListItemComponent,
ProfileRepoListItemSkeletonComponent,
} from './components';
import { PipesModule } from '@shared';

@NgModule({
declarations: [
Expand Down Expand Up @@ -50,6 +51,7 @@ import {
ReactiveFormsModule,
ReposFilterDropdownModule,
PaginationModule,
PipesModule,
],
})
export class ProfileModule {}

0 comments on commit 84cbcdf

Please sign in to comment.