Removed redundant meta tag handling, updated routing
This commit is contained in:
1 parent
cce6b58331
commit
b83e994f06
10 files changed
+51
-186
No files matched your search
@@ -2,6 +2,7 @@ import {AfterViewInit, Component, OnDestroy, OnInit, PLATFORM_ID, Inject} from '
|
||||
import {isPlatformBrowser, NgStyle} from '@angular/common';
|
||||
import {VantaBackgroundService} from '../services/vanta-background.service';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-about',
|
||||
@@ -17,10 +18,12 @@ export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
constructor(
|
||||
private vantaService: VantaBackgroundService,
|
||||
private deviceService: DeviceDetectorService,
|
||||
private titleService: Title,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('itzMiney\'s Home');
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
window.addEventListener('resize', this.onResize.bind(this));
|
||||
|
||||
@@ -5,6 +5,7 @@ import {NgFor, NgIf, NgStyle} from '@angular/common';
|
||||
import {Observer} from 'rxjs';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin',
|
||||
@@ -28,11 +29,13 @@ export class AdminComponent implements OnInit {
|
||||
constructor(
|
||||
private articleService: ArticleService,
|
||||
private router: Router,
|
||||
private deviceService: DeviceDetectorService
|
||||
private deviceService: DeviceDetectorService,
|
||||
private titleService: Title
|
||||
) {}
|
||||
|
||||
// Fetch articles from backend
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('Admin Panel | itzMiney')
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
if (!this.token) {
|
||||
this.navigateToLogin();
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {ActivatedRoute, NavigationEnd, Router, RouterOutlet} from '@angular/router';
|
||||
import {ActivatedRoute, Router, RouterOutlet} from '@angular/router';
|
||||
import {NavbarComponent} from './navbar/navbar.component';
|
||||
import {MobileNavbarComponent} from './mobile-navbar/mobile-navbar.component';
|
||||
import {FooterComponent} from './footer/footer.component';
|
||||
import {filter, map, mergeMap} from 'rxjs/operators';
|
||||
import {DeviceDetectorService} from './services/device-detector.service';
|
||||
import { UpdateMetaService } from './services/update-meta.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@@ -23,41 +21,15 @@ export class AppComponent implements OnInit {
|
||||
private router: Router,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private deviceService: DeviceDetectorService,
|
||||
private updateMetaService: UpdateMetaService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.router.events.subscribe(() => this.checkRoute())
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
|
||||
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'] || {};
|
||||
if (this.router.url === '/about') {
|
||||
// fallback meta data
|
||||
meta.title = meta.title || 'itzMiney\'s Home';
|
||||
meta.description = meta.description || 'Welcome to itzMiney\'s Homepage! Here you can find my portfolio and other cool stuff.';
|
||||
meta.image = meta.image || 'https://itzminey.dev/assets/ogimg.png';
|
||||
meta.url = meta.url || 'https://itzminey.dev';
|
||||
meta.color = meta.color || '#eb284c';
|
||||
}
|
||||
this.updateMetaService.updateMetaTags(meta);
|
||||
this.checkRoute();
|
||||
});
|
||||
}
|
||||
|
||||
checkRoute() {
|
||||
const currentRoute = this.activatedRoute.snapshot.firstChild?.routeConfig?.path;
|
||||
|
||||
|
||||
switch (currentRoute) {
|
||||
case 'admin': {
|
||||
this.showNavbar = false;
|
||||
|
||||
+8
-88
@@ -8,92 +8,12 @@ import {AdminComponent} from './admin/admin.component';
|
||||
import {ArticlePageComponent} from './article-page/article-page.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: AboutComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'itzMiney\'s Home',
|
||||
description: 'Welcome to itzMiney\'s Homepage! Here you can find my portfolio and other cool stuff.',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/about',
|
||||
color: '#eb284c'
|
||||
}
|
||||
}
|
||||
}, // Redirect default route to 'about'
|
||||
{
|
||||
path: 'about',
|
||||
redirectTo: '/',
|
||||
pathMatch: 'full',
|
||||
},
|
||||
{
|
||||
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',
|
||||
color: '#eb284c'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'blog',
|
||||
component: BlogComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'Blog | itzMiney',
|
||||
description: 'Welcome to my blog! I\'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',
|
||||
color: '#eb284c'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
component: LoginComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'Login | itzMiney',
|
||||
description: 'Admin Panel Login',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/login',
|
||||
color: '#eb284c'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'admin',
|
||||
component: AdminComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'Admin Panel | itzMiney',
|
||||
description: 'Admin Panel',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/admin',
|
||||
color: '#eb284c'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'blog/:slug',
|
||||
component: ArticlePageComponent
|
||||
},
|
||||
{
|
||||
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',
|
||||
color: '#eb284c'
|
||||
}
|
||||
}
|
||||
}
|
||||
{ path: '', component: AboutComponent },
|
||||
{ path: 'about', redirectTo: '/', pathMatch: 'full' },
|
||||
{ path: 'portfolio', component: PortfolioComponent },
|
||||
{ path: 'blog', component: BlogComponent },
|
||||
{ path: 'login', component: LoginComponent },
|
||||
{ path: 'admin', component: AdminComponent },
|
||||
{ path: 'blog/:slug', component: ArticlePageComponent },
|
||||
{ path: '**', pathMatch: 'full', component: NotFoundComponent }
|
||||
];
|
||||
@@ -4,7 +4,7 @@ import {DatePipe, isPlatformBrowser, NgIf} from '@angular/common';
|
||||
import {VantaBackgroundService} from '../services/vanta-background.service';
|
||||
import {ArticleService} from '../services/article.service';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {UpdateMetaService} from '../services/update-meta.service';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
|
||||
interface Article {
|
||||
id: number;
|
||||
@@ -36,7 +36,7 @@ export class ArticlePageComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
private deviceService: DeviceDetectorService,
|
||||
private vantaService: VantaBackgroundService,
|
||||
private articleService: ArticleService,
|
||||
private updateMetaService: UpdateMetaService,
|
||||
private titleService: Title,
|
||||
private route: ActivatedRoute,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {
|
||||
@@ -48,15 +48,9 @@ export class ArticlePageComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
this.route.params.subscribe((params) => {
|
||||
const slug = params['slug'];
|
||||
if (slug) {
|
||||
this.loadArticleMetaBySlug(slug);
|
||||
this.loadTitleBySlug(slug);
|
||||
} else {
|
||||
this.updateMetaService.updateMetaTags({
|
||||
title: 'Article | itzMiney',
|
||||
description: 'An article on itzMiney\'s Blog.',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev/blog',
|
||||
color: '#ffffff'
|
||||
});
|
||||
this.titleService.setTitle('Article | itzMiney');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -92,38 +86,20 @@ export class ArticlePageComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
this.vantaService.resizeVanta(this.elementId);
|
||||
}
|
||||
|
||||
loadArticleMetaBySlug(slug: string) {
|
||||
loadTitleBySlug(slug: string) {
|
||||
this.articleService.getArticleBySlug(slug).subscribe(
|
||||
(article) => {
|
||||
if (article) {
|
||||
this.currentArticle = article;
|
||||
this.updateMetaService.updateMetaTags({
|
||||
title: article.title,
|
||||
description: article.content.slice(0, 150), // First 150 characters
|
||||
image: 'https://itzminey.dev/assets/ogimg.png', // Use article image or default
|
||||
url: `https://itzminey.dev/blog/${article.slug}`,
|
||||
color: '#ffffff'
|
||||
});
|
||||
this.titleService.setTitle( article.title );
|
||||
} else {
|
||||
console.warn('Article not found for slug:', slug);
|
||||
this.updateMetaService.updateMetaTags({
|
||||
title: 'Article Not Found',
|
||||
description: 'The requested article could not be found.',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev',
|
||||
color: '#ff0000'
|
||||
});
|
||||
this.titleService.setTitle('Article Not Found');
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('Failed to load article metadata', error);
|
||||
this.updateMetaService.updateMetaTags({
|
||||
title: 'Error',
|
||||
description: 'An error occurred while loading this article.',
|
||||
image: 'https://itzminey.dev/assets/ogimg.png',
|
||||
url: 'https://itzminey.dev',
|
||||
color: '#ff0000'
|
||||
});
|
||||
console.error('Failed to load article title', error);
|
||||
this.titleService.setTitle('Error loading Article');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {VantaBackgroundService} from '../services/vanta-background.service';
|
||||
import { ArticleService } from '../services/article.service';
|
||||
import { Router } from '@angular/router';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-blog',
|
||||
@@ -28,10 +29,12 @@ export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
private vantaService: VantaBackgroundService,
|
||||
private articleService: ArticleService,
|
||||
private router: Router,
|
||||
private titleService: Title,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('Blog | itzMiney')
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
window.addEventListener('resize', this.onResize.bind(this));
|
||||
@@ -40,7 +43,18 @@ export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
}
|
||||
|
||||
navigateToArticle(slug: string): void {
|
||||
this.router.navigate([`/blog/${slug}`]);
|
||||
this.router.navigate([`/blog/${slug}`]).then(
|
||||
(success) => {
|
||||
if (success) {
|
||||
console.log('Navigation to article succeeded');
|
||||
} else {
|
||||
console.warn('Navigation to article failed');
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
console.error('Navigation error:', error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {NgIf} from '@angular/common';
|
||||
import {VantaBackgroundService} from '../services/vanta-background.service';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {isPlatformBrowser} from '@angular/common';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
@@ -29,10 +30,12 @@ export class LoginComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
private router: Router,
|
||||
private vantaService: VantaBackgroundService,
|
||||
private deviceService: DeviceDetectorService,
|
||||
private titleService: Title,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('Login | itzMiney')
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
window.addEventListener('resize', this.onResize.bind(this));
|
||||
|
||||
@@ -2,6 +2,7 @@ import {AfterViewInit, Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {VantaBackgroundService} from '../services/vanta-background.service';
|
||||
import {isPlatformBrowser} from '@angular/common';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-not-found',
|
||||
@@ -16,11 +17,13 @@ export class NotFoundComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
constructor(
|
||||
private vantaService: VantaBackgroundService,
|
||||
private deviceService: DeviceDetectorService,
|
||||
private titleService: Title,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('404 | Page Not Found')
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
window.addEventListener('resize', this.onResize.bind(this));
|
||||
|
||||
@@ -2,6 +2,7 @@ import {AfterViewInit, Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '
|
||||
import {VantaBackgroundService} from '../services/vanta-background.service';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service';
|
||||
import {isPlatformBrowser, NgStyle} from '@angular/common';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-portfolio',
|
||||
@@ -17,11 +18,12 @@ export class PortfolioComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
constructor(
|
||||
private vantaService: VantaBackgroundService,
|
||||
private deviceService: DeviceDetectorService,
|
||||
private titleService: Title,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.titleService.setTitle('Portfolio | itzMiney');
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
window.addEventListener('resize', this.onResize.bind(this));
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
import { Meta } from '@angular/platform-browser';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UpdateMetaService {
|
||||
|
||||
constructor(private titleService: Title, private metaService: Meta) {}
|
||||
|
||||
updateMetaTags(meta: { title?: string; description?: string; image?: string; url?: string; color?: 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 });
|
||||
}
|
||||
if (meta.color) {
|
||||
this.metaService.updateTag({ name: 'theme-color', content: meta.color });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user