Skip to content
This repository was archived by the owner on Jan 12, 2019. It is now read-only.

Commit 662d7e8

Browse files
committed
SEO Part 3: Meta tag inclusion done
1 parent 616f002 commit 662d7e8

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

Diff for: src/app/app.component.ts

+37-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from "@angular/core";
2-
import { Title } from "@angular/platform-browser";
2+
import { Title, Meta } from "@angular/platform-browser";
33
import { Router, NavigationEnd } from "@angular/router";
44

55
import { GoogleAnalyticsService } from "./shared/";
@@ -11,23 +11,53 @@ import { GoogleAnalyticsService } from "./shared/";
1111
})
1212
export class AppComponent {
1313
routes = {
14-
"/": "Home Page",
15-
"/home": "Home Page",
16-
"/about": "About Us",
17-
"/contact": "Contact Us",
14+
"/": {
15+
title: "Home Page",
16+
desc: "This is the description of Home Page"
17+
},
18+
"/home": {
19+
title: "Home Page",
20+
desc: "This is the description of Home Page"
21+
},
22+
"/about": {
23+
title: "About Us",
24+
desc: "This page will describe some things about us"
25+
},
26+
"/contact": {
27+
title: "Contact Us",
28+
desc: "This page will tell you how to contact us"
29+
}
1830
};
1931

2032
constructor(
2133
public router: Router,
2234
private googleAnalyticsService: GoogleAnalyticsService,
23-
private titleService: Title
35+
private titleService: Title,
36+
private meta: Meta
2437
) {
2538
this.router.events.subscribe(event => {
2639
if (event instanceof NavigationEnd) {
27-
this.titleService.setTitle(this.routes[event.url]);
40+
this.handleSEO(event);
2841

2942
this.googleAnalyticsService.emitPageEvent(event);
3043
}
3144
});
3245
}
46+
47+
handleSEO(event: NavigationEnd) {
48+
const desc = this.routes[event.url].desc;
49+
50+
// Generic
51+
this.titleService.setTitle(this.routes[event.url].title);
52+
this.meta.addTag({ name: "description", content: desc });
53+
54+
// Twitter Metadata
55+
this.meta.addTag({ name: "twitter:card", content: "summary_large_image" });
56+
this.meta.addTag({ name: "twitter:site", content: "@AbhijitKarDikha" });
57+
this.meta.addTag({ name: "twitter:creator", content: "@AbhijitKarDikha" });
58+
this.meta.addTag({ name: "twitter:title", content: desc });
59+
this.meta.addTag({ name: "twitter:description", content: desc });
60+
this.meta.addTag({ name: "twitter:text:description", content: desc });
61+
this.meta.addTag({ name: "twitter:image", content: "https://www.abhijit-kar.com/assets/meta/screenshot.png" });
62+
}
3363
}

0 commit comments

Comments
 (0)