Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 2d369a9

Browse files
committed
fix(seo): Add a type for SEO data
1 parent 4130dcd commit 2d369a9

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/app/app.component.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
RouterEvent
77
} from '@angular/router';
88
import { filter, map, mergeMap } from 'rxjs/operators';
9-
import { SeoService } from './services/seo.service';
9+
import { SeoService, SeoData } from './services/seo.service';
1010

1111
interface Menu {
1212
title: string;
@@ -61,12 +61,9 @@ export class AppComponent implements OnInit {
6161
return route;
6262
}),
6363
filter(route => route.outlet === 'primary'),
64-
mergeMap(route => route.data)
64+
mergeMap(route => route.data),
65+
filter((data: SeoData) => data.title !== undefined)
6566
)
66-
.subscribe(data => {
67-
if (data !== {}) {
68-
this._seo.setHeaders(data.title || [], data.description || '');
69-
}
70-
});
67+
.subscribe((data: SeoData) => this._seo.setHeaders(data));
7168
}
7269
}

src/app/operators/components/operator/operator.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ export class OperatorComponent implements OnInit {
3939
this.operators.filter(
4040
(operator: OperatorDoc) => operator.name === name
4141
)[0] || this.notfound();
42-
this._seo.setHeaders(
43-
[this.operator.name, this.operator.operatorType],
44-
this.operator.shortDescription
42+
this._seo.setHeaders({
43+
title: [this.operator.name, this.operator.operatorType],
44+
description: this.operator.shortDescription
4545
? this.operator.shortDescription.description
4646
: ''
47-
);
47+
});
4848
});
4949
}
5050

src/app/services/seo.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import { Injectable } from '@angular/core';
22
import { Title, Meta } from '@angular/platform-browser';
33

4+
export interface SeoData {
5+
title?: string[];
6+
description?: string;
7+
}
8+
49
@Injectable()
510
export class SeoService {
611
// This part is happended at the end of head>title
712
private siteTitle = 'RxJS Documentation';
813

914
constructor(private _title: Title, private _meta: Meta) {}
1015

11-
public setHeaders(titleParts: string[], description: string) {
12-
this._title.setTitle([...titleParts, this.siteTitle].join(' \u2022 '));
13-
if (description && description.length) {
16+
public setHeaders(data: SeoData) {
17+
this._title.setTitle([...data.title, this.siteTitle].join(' \u2022 '));
18+
if (data.description && data.description.length) {
1419
this._meta.updateTag({
15-
content: description,
20+
content: data.description,
1621
name: 'description'
1722
});
1823
}

0 commit comments

Comments
 (0)