home.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Component, OnInit, inject } from '@angular/core';
  2. import { PlatformLocation } from '@angular/common';
  3. import { Meta, Title } from '@angular/platform-browser';
  4. import { TranslateService, _ } from '@ngx-translate/core';
  5. import { ProjectService } from '../service/project-service';
  6. import { ProfileService } from '../service/profile-service';
  7. import { UtilService } from '../service/util-service';
  8. import { ProjectModel } from '../model/project';
  9. import { environment } from '../../environments/environment';
  10. @Component({ selector: 'app-home', templateUrl: './home.html', styleUrl: './home.scss'})
  11. export class Home implements OnInit {
  12. projects: ProjectModel[] = [];
  13. profile: any;
  14. apiURL: string = environment.apiUrl;
  15. utilService: UtilService;
  16. private translate = inject(TranslateService)
  17. constructor(
  18. private projectService: ProjectService, private profileService: ProfileService,
  19. private titleService: Title, private metaService: Meta,
  20. private platformLocation: PlatformLocation
  21. ){
  22. this.utilService = new UtilService();
  23. // Set meta tags
  24. const url = this.platformLocation.protocol + "//" + this.platformLocation.hostname;
  25. this.metaService.addTag({ property: 'canonical', content: url });
  26. this.metaService.addTag({ property: 'og:url', content: url });
  27. this.metaService.addTag({ property: 'og:image', content: url + '/img/logo/leather.png' });
  28. this.translate.get(_('SITE.TITLE')).subscribe((res: string) => {
  29. this.titleService.setTitle(res);
  30. this.metaService.addTag({ property: 'og:title', content: res});
  31. this.metaService.addTag({ property: 'title', content: res});
  32. });
  33. this.translate.get(_('SITE.DESCRIPTION')).subscribe((res: string) => {
  34. this.metaService.addTag({ property: 'og:description', content: res});
  35. this.metaService.addTag({ property: 'description', content: res});
  36. });
  37. }
  38. ngOnInit(): void {
  39. this.projectService.getProjects(1).subscribe(data => { this.projects = data; });
  40. this.profileService.getProfile().subscribe(data => { this.profile = data; });
  41. }
  42. }