Revised Meta Data & improved Routing
This commit is contained in:
1 parent
97217cb149
commit
5097f7c254
6 files changed
+103
-33
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import {Component, OnInit, OnDestroy, AfterViewInit} from '@angular/core';
|
||||
import {Meta, Title} from '@angular/platform-browser';
|
||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||
import {NgIf} from '@angular/common';
|
||||
|
||||
@@ -12,17 +11,13 @@ import {NgIf} from '@angular/common';
|
||||
styleUrls: ['./about.component.css']
|
||||
})
|
||||
export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
constructor(private titleService: Title, private meta: Meta, private deviceService: DeviceDetectorService) {
|
||||
constructor( private deviceService: DeviceDetectorService) {
|
||||
this.isMobile = this.deviceService.isMobile();
|
||||
}
|
||||
isMobile: boolean;
|
||||
private vantaEffect: any;
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('itzMiney\'s Home');
|
||||
this.meta.updateTag({ name: 'description', content: 'Welcome to itzMiney\'s Homepage!\bHere you can find my portfolio and other cool stuff.' });
|
||||
this.meta.updateTag({ property: 'og:image', content: 'https://itzminey.dev/assets/ogimg.png' });
|
||||
|
||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||
|
||||
const bgElement = document.getElementById('vanta-about-bg');
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {NgIf} from '@angular/common';
|
||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||
import {RouterOutlet, provideRouter, Router} from '@angular/router';
|
||||
import {RouterOutlet, ActivatedRoute, Router, NavigationEnd} from '@angular/router';
|
||||
import {NavbarComponent} from './navbar/navbar.component';
|
||||
import {MobileNavbarComponent} from './mobile-navbar/mobile-navbar.component';
|
||||
import {FooterComponent} from './footer/footer.component';
|
||||
import { Title, Meta } from '@angular/platform-browser';
|
||||
import { filter, map, mergeMap } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -12,11 +14,50 @@ import {FooterComponent} from './footer/footer.component';
|
||||
templateUrl: './app.component.html',
|
||||
styleUrl: './app.component.css'
|
||||
})
|
||||
export class AppComponent {
|
||||
title = 'itzmineydev';
|
||||
export class AppComponent implements OnInit {
|
||||
isMobile: boolean;
|
||||
|
||||
constructor(private deviceService: DeviceDetectorService) {
|
||||
constructor(
|
||||
private deviceService: DeviceDetectorService,
|
||||
private router: Router,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private titleService: Title,
|
||||
private metaService: Meta
|
||||
) {
|
||||
this.isMobile = this.deviceService.isMobile();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.router.events
|
||||
.pipe(
|
||||
filter(event => event instanceof NavigationEnd),
|
||||
map(() => this.activatedRoute),
|
||||
map(route => {
|
||||
while (route.firstChild) route = route.firstChild;
|
||||
return route;
|
||||
}),
|
||||
mergeMap(route => route.data)
|
||||
)
|
||||
.subscribe(data => {
|
||||
const meta = data['meta'] || {};
|
||||
this.updateMetaTags(meta);
|
||||
});
|
||||
}
|
||||
|
||||
updateMetaTags(meta: { title?: string; description?: string; image?: string; url?: string }) {
|
||||
if (meta.title) {
|
||||
this.titleService.setTitle(meta.title);
|
||||
this.metaService.updateTag({ name: 'og:title', content: meta.title });
|
||||
}
|
||||
if (meta.description) {
|
||||
this.metaService.updateTag({ name: 'description', content: meta.description });
|
||||
this.metaService.updateTag({ name: 'og:description', content: meta.description });
|
||||
}
|
||||
if (meta.image) {
|
||||
this.metaService.updateTag({ name: 'og:image', content: meta.image });
|
||||
}
|
||||
if (meta.url) {
|
||||
this.metaService.updateTag({ name: 'og:url', content: meta.url });
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
-6
@@ -5,10 +5,58 @@ import { BlogComponent } from './blog/blog.component';
|
||||
import {NotFoundComponent} from './not-found/not-found.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: '', redirectTo: '/about', pathMatch: 'full' }, // Redirect default route to 'about'
|
||||
{ path: 'about', component: AboutComponent },
|
||||
{ path: 'portfolio', component: PortfolioComponent },
|
||||
{ path: 'blog', component: BlogComponent },
|
||||
|
||||
{ path: '**', pathMatch: 'full', component: NotFoundComponent },
|
||||
{
|
||||
path: '',
|
||||
redirectTo: '/about',
|
||||
pathMatch: 'full'
|
||||
}, // Redirect default route to 'about'
|
||||
{
|
||||
path: 'about',
|
||||
component: AboutComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'itzMiney\'s Home',
|
||||
description: 'Welcome to itzMiney\'s Homepage!\bHere you can find my portfolio and other cool stuff.',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/about'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'portfolio',
|
||||
component: PortfolioComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'Portfolio | itzMiney',
|
||||
description: 'This is my portfolio where you can find examples of my designs and other projects!',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/portfolio'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'blog',
|
||||
component: BlogComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'Blog | itzMiney',
|
||||
description: 'Welcome to my blog!\bI\'ll post occasional updates here on the stuff I\'m currently up to.',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/blog'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '**',
|
||||
pathMatch: 'full',
|
||||
component: NotFoundComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: '404 | Page Not Found',
|
||||
description: 'How the hell did you end up here?',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/404'
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
@@ -1,5 +1,4 @@
|
||||
import {Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
|
||||
import {Meta, Title} from '@angular/platform-browser';
|
||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||
import {NgIf} from '@angular/common';
|
||||
|
||||
@@ -12,17 +11,13 @@ import {NgIf} from '@angular/common';
|
||||
styleUrl: './blog.component.css'
|
||||
})
|
||||
export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
constructor(private titleService: Title, private meta: Meta, private deviceService: DeviceDetectorService) {
|
||||
constructor(private deviceService: DeviceDetectorService) {
|
||||
this.isMobile = this.deviceService.isMobile();
|
||||
}
|
||||
isMobile: boolean;
|
||||
private vantaEffect: any;
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('Blog | itzMiney');
|
||||
this.meta.updateTag({ name: 'description', content: 'Welcome to my blog!\bI\'ll post occasional updates here on the stuff I\'m currently up to.'});
|
||||
this.meta.updateTag({ property: 'og:image', content: 'https://itzminey.dev/assets/ogimg.png' });
|
||||
|
||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||
|
||||
const bgElement = document.getElementById('vanta-blog-bg');
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
|
||||
import {Meta, Title} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-not-found',
|
||||
@@ -9,13 +8,9 @@ import {Meta, Title} from '@angular/platform-browser';
|
||||
})
|
||||
|
||||
export class NotFoundComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
constructor(private titleService: Title, private meta: Meta) {}
|
||||
private vantaEffect: any;
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('404 Not Found');
|
||||
this.meta.updateTag({ name: 'description', content: 'How the hell did you end up here?' });
|
||||
this.meta.updateTag({ property: 'og:image', content: 'https://itzminey.dev/assets/ogimg.png' });
|
||||
|
||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {AfterViewInit, Component, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Meta, Title } from '@angular/platform-browser';
|
||||
import { DeviceDetectorService } from 'ngx-device-detector';
|
||||
import {NgIf} from '@angular/common';
|
||||
|
||||
@@ -12,16 +11,13 @@ import {NgIf} from '@angular/common';
|
||||
styleUrl: './portfolio.component.css'
|
||||
})
|
||||
export class PortfolioComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
constructor(private titleService: Title, private meta: Meta, private deviceService: DeviceDetectorService) {
|
||||
constructor(private deviceService: DeviceDetectorService) {
|
||||
this.isMobile = this.deviceService.isMobile();
|
||||
}
|
||||
isMobile: boolean;
|
||||
private vantaEffect: any;
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('Portfolio | itzMiney');
|
||||
this.meta.updateTag({ name: 'description', content: 'This is my portfolio where you can find examples of my designs and other projects!' });
|
||||
this.meta.updateTag({ property: 'og:image', content: 'https://itzminey.dev/assets/ogimg.png' });
|
||||
window.addEventListener('resize', this.onResize.bind(this)); // Add resize listener for responsiveness
|
||||
|
||||
const bgElement = document.getElementById('vanta-portfolio-bg');
|
||||
|
||||
Reference in new issue
Block a user