Created
December 21, 2018 19:13
-
-
Save elgreatly/34abb99878615196e1af5a8e7bbed7fe to your computer and use it in GitHub Desktop.
SeoService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { Meta } from '@angular/platform-browser'; | |
@Injectable() | |
export class SeoService { | |
constructor(private meta: Meta) { } | |
generateTags(config) { | |
// default values | |
config = { | |
title: 'Angular <3 Linkbots', | |
description: 'My SEO friendly Angular Component', | |
image: 'https://example.com/images/logo.png', | |
slug: '', | |
...config | |
} | |
this.meta.updateTag({ name: 'twitter:card', content: 'summary' }); | |
this.meta.updateTag({ name: 'twitter:site', content: '@content' }); | |
this.meta.updateTag({ name: 'twitter:title', content: config.title }); | |
this.meta.updateTag({ name: 'twitter:description', content: config.description }); | |
this.meta.updateTag({ name: 'twitter:image', content: config.image }); | |
this.meta.updateTag({ property: 'og:type', content: 'article' }); | |
this.meta.updateTag({ property: 'og:site_name', content: 'content' }); | |
this.meta.updateTag({ property: 'og:title', content: config.title }); | |
this.meta.updateTag({ property: 'og:description', content: config.description }); | |
this.meta.updateTag({ property: 'og:image', content: config.image }); | |
this.meta.updateTag({ property: 'og:url', content: `https://www.example.com/${config.slug}` }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment