All files / app/services meta-tag.service.ts

100% Statements 56/56
37.5% Branches 3/8
100% Functions 3/3
100% Lines 56/56

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 571x 1x 1x 1x 1x 1x 1x 1x 1x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x  
import { Injectable, inject } from '@angular/core';
import { Meta, MetaDefinition } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { environment } from '@environments/environment';
 
@Injectable({
	providedIn: 'root',
})
export class MetaTagService {
	private router = inject(Router);
	private meta = inject(Meta);
 
	public getMetaTags(title: string, desc: string, image?: string): MetaDefinition[] {
		const defaultTitle = 'Top Trip | Go Real Travel';
		const defaultDesc = 'Plan your perfect trip with Go Real Travel.';
		const imageUrl = environment.frontendUrl + '/assets/images/logo.png';
		const pageUrl = environment.frontendUrl + this.router.url;
 
		return [
			// Open Graph meta tags
			{ property: 'og:type', content: 'website' },
			{ property: 'og:title', content: title || defaultTitle },
			{ property: 'og:description', content: desc || defaultDesc },
			{ property: 'og:image', content: image || imageUrl },
			{ property: 'og:url', content: pageUrl },
			{ property: 'og:site_name', content: 'Go Real Travel' },
 
			// Twitter Card meta tags
			{ name: 'twitter:card', content: image || imageUrl },
			{ name: 'twitter:title', content: title || defaultTitle },
			{ name: 'twitter:description', content: desc || defaultDesc },
			{ name: 'twitter:image', content: image || imageUrl },
 
			// Standard meta description
			{ name: 'description', content: desc || defaultDesc },
		];
	}
 
	public removeMetaTags(): void {
		this.meta.removeTag('name="description"');
 
		// Open Graph meta tags
		this.meta.removeTag('property="og:title"');
		this.meta.removeTag('property="og:type"');
		this.meta.removeTag('property="og:image"');
		this.meta.removeTag('property="og:url"');
		this.meta.removeTag('property="og:description"');
		this.meta.removeTag('property="og:site_name"');
 
		// Twitter meta tags
		this.meta.removeTag('name="twitter:card"');
		this.meta.removeTag('name="twitter:title"');
		this.meta.removeTag('name="twitter:description"');
		this.meta.removeTag('name="twitter:image"');
	}
}