Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: seo meta tags #228

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions libs/blog/feature-home/src/lib/blog-home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ export class BlogHomeComponent implements OnInit {
articles$!: Observable<Results<Article>>;

ngOnInit(): void {
this.metadataService.updateMetadata({
title: 'Inside my head | Valery Melou',
description:
'I talk about Django, Angular... Web Development in general and many other topics. These are just a few of the things in my head.',
});
this.loadArticles();
}

constructor(
private articleService: ArticleService,
private metadataService: MetadataService,
) {}
metadataService: MetadataService,
) {
metadataService.updateMetadata({
title: 'Inside my head | Valery Melou',
description:
'I talk about Django, Angular... Web Development in general and many other topics. These are just a few of the things in my head.',
});
}

loadArticles(): void {
this.articles$ = this.articleService.get({});
Expand Down
10 changes: 4 additions & 6 deletions libs/pages/about/src/lib/about.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MetadataService } from '@valerymelou/shared/seo';
import { LinkComponent } from '@valerymelou/shared/ui';
Expand All @@ -9,11 +9,9 @@ import { LinkComponent } from '@valerymelou/shared/ui';
imports: [CommonModule, LinkComponent],
templateUrl: './about.component.html',
})
export class AboutComponent implements OnInit {
constructor(private metadataService: MetadataService) {}

ngOnInit(): void {
this.metadataService.updateMetadata({
export class AboutComponent {
constructor(metadataService: MetadataService) {
metadataService.updateMetadata({
title: 'About myself | Valery Melou',
description:
"I'm now specialized into web development. Building RESTfull APIs with Django and Python then, consuming those APIs with Angular and Typescript.",
Expand Down
10 changes: 4 additions & 6 deletions libs/pages/home/src/lib/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ButtonComponent } from '@valerymelou/shared/ui';
import { MetadataService } from '@valerymelou/shared/seo';
Expand All @@ -11,11 +11,9 @@ import { RouterModule } from '@angular/router';
templateUrl: './home.component.html',
styles: ':host {display: flex; flex-direction: column; flex: 1;}',
})
export class HomeComponent implements OnInit {
constructor(private metadataService: MetadataService) {}

ngOnInit(): void {
this.metadataService.updateMetadata({
export class HomeComponent {
constructor(metadataService: MetadataService) {
metadataService.updateMetadata({
title: 'Home of Valery Melou',
description:
'I build beautiful, interactive and accessible experiences for web and mobile.',
Expand Down
10 changes: 4 additions & 6 deletions libs/pages/projects/src/lib/projects.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MetadataService } from '@valerymelou/shared/seo';

Expand All @@ -8,11 +8,9 @@ import { MetadataService } from '@valerymelou/shared/seo';
imports: [CommonModule],
templateUrl: './projects.component.html',
})
export class ProjectsComponent implements OnInit {
constructor(private metadataService: MetadataService) {}

ngOnInit(): void {
this.metadataService.updateMetadata({
export class ProjectsComponent {
constructor(metadataService: MetadataService) {
metadataService.updateMetadata({
title: 'Some of the things I have built | Valery Melou',
description: 'Here are some of the projects I have worked on.',
});
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/seo/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const DEFAULT_METADATA: PageMetadata = {
description: 'Web developer from Yaounde, Cameroon',
keywords: ['angular', 'django', 'angular', 'web', 'developer', 'yaounde'],
type: 'website',
image: '/assets/images/logo.png',
image: '/assets/images/valerymelou.jpg',
imageAlt: APP_NAME,
};
14 changes: 10 additions & 4 deletions libs/shared/seo/src/lib/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,30 @@ export class MetadataService {
}

private generateOgMetaDefinitions(metadata: PageMetadata): MetaDefinition[] {
const imageUrl = metadata.image.startsWith('http')
? metadata.image
: window.location.origin + metadata.image;
return [
{ name: 'og:url', content: window.location.href },
{ property: 'og:title', content: metadata.title },
{ property: 'og:description', content: metadata.description },
{ property: 'og:type', content: metadata.type },
{ property: 'og:image', content: metadata.image },
{ property: 'og:image:secure_url', content: metadata.image },
{ property: 'og:image', content: imageUrl },
{ property: 'og:image:secure_url', content: imageUrl },
{ property: 'og:image:alt', content: metadata.imageAlt },
];
}

private generateXMetaDefinitions(metadata: PageMetadata): MetaDefinition[] {
const imageUrl = metadata.image.startsWith('http')
? metadata.image
: window.location.origin + metadata.image;
return [
{ name: 'twitter:card', content: 'summary' },
{ name: 'twitter:site', content: '@valerymelou' },
{ name: 'twitter:title', content: metadata.title },
{ name: 'twitter:description', content: metadata.description },
{ name: 'twitter:image', content: metadata.image },
{ name: 'twitter:description', content: imageUrl },
{ name: 'twitter:image', content: imageUrl },
{ name: 'twitter:image:alt', content: metadata.imageAlt },
];
}
Expand Down