65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {DeviceDetectorService} from '../shared/services/device-detector.service'
|
|
import { DatePipe, AsyncPipe, SlicePipe, NgStyle } from '@angular/common';
|
|
import { ArticleService } from '../shared/services/article.service';
|
|
import { Router } from '@angular/router';
|
|
import {Observable} from 'rxjs';
|
|
import {Title} from '@angular/platform-browser';
|
|
import {TranslatePipe} from '@ngx-translate/core';
|
|
import {ParallaxComponent} from '../shared/parallax/parallax.component';
|
|
|
|
@Component({
|
|
selector: 'app-blog',
|
|
imports: [
|
|
DatePipe,
|
|
AsyncPipe,
|
|
SlicePipe,
|
|
NgStyle,
|
|
TranslatePipe,
|
|
ParallaxComponent
|
|
],
|
|
templateUrl: './blog.component.html',
|
|
styleUrl: './blog.component.css'
|
|
})
|
|
export class BlogComponent implements OnInit {
|
|
articles$: Observable<any[]> | undefined;
|
|
isMobile: boolean = false;
|
|
constructor(
|
|
private deviceService: DeviceDetectorService,
|
|
private articleService: ArticleService,
|
|
private router: Router,
|
|
private titleService: Title
|
|
) {}
|
|
|
|
ngOnInit() {
|
|
this.titleService.setTitle('Blog | itzMiney')
|
|
this.isMobile = this.deviceService.isMobile;
|
|
this.articles$ = this.articleService.getAllArticles();
|
|
}
|
|
|
|
navigateToArticle(slug: string): void {
|
|
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);
|
|
}
|
|
);
|
|
}
|
|
|
|
sanitizeContent(content: string): string {
|
|
if (!content) return '';
|
|
return content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
}
|
|
|
|
truncateContent(content: string, length: number): string {
|
|
const sanitized = this.sanitizeContent(content);
|
|
return sanitized.length > length ? sanitized.slice(0, length) + '...' : sanitized;
|
|
}
|
|
}
|