Added blog functionality, reworked backend api requests
This commit is contained in:
1 parent
a4b69c5b9a
commit
dae95810f2
16 files changed
+696
-171
No files matched your search
@@ -0,0 +1,114 @@
|
||||
@keyframes fadeIn {
|
||||
0% {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
|
||||
#vanta-article-bg {
|
||||
animation: fadeIn 1s ease-out;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw; /* Full viewport width */
|
||||
height: 100vh; /* Full viewport height */
|
||||
z-index: -100; /* Place the background behind content */
|
||||
}
|
||||
.height-container {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.article-container {
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 50%, rgb(0, 0, 0) 100%);
|
||||
padding: 30px;
|
||||
justify-items: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.content-container {
|
||||
display: inline-grid;
|
||||
max-width: 960px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5rem;
|
||||
color: #fff;
|
||||
margin-top: 120px;
|
||||
margin-bottom: 40px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.article-content {
|
||||
font-size: 1.2rem;
|
||||
color: #fff;
|
||||
line-height: 1.8; /* Improve readability */
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.article-meta {
|
||||
font-size: 1rem;
|
||||
color: #e6e6e6;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.article-meta p {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.content-container button {
|
||||
background-color: #713252;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
border-radius: 25px;
|
||||
transition: background-color 0.3s;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.content-container button:hover {
|
||||
background-color: #bf9bae;
|
||||
}
|
||||
|
||||
.error-message h1 {
|
||||
font-size: 10rem;
|
||||
margin: 0;
|
||||
font-weight: 700;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.error-message p {
|
||||
font-size: 1.5rem;
|
||||
margin: 20px 0;
|
||||
font-weight: 400;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.error-message button {
|
||||
background-color: #713252;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
border-radius: 25px;
|
||||
transition: background-color 0.3s;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.error-message button:hover {
|
||||
background-color: #bf9bae;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<div id="vanta-article-bg"></div>
|
||||
<div class="height-container">
|
||||
<div class="article-container" *ngIf="article; else error">
|
||||
<div>
|
||||
<!-- Article Title -->
|
||||
<h1>{{ article.title }}</h1>
|
||||
<div class="content-container">
|
||||
<!-- Article Content -->
|
||||
<div class="article-content" [innerHTML]="article.content"></div>
|
||||
|
||||
<a href="/blog"><button>Back to Overview</button></a>
|
||||
<!-- Article Metadata -->
|
||||
<div class="article-meta">
|
||||
<p><strong>Author:</strong> {{ article.authorName}}</p>
|
||||
<p><strong>Views:</strong> {{ article.views }}</p><br>
|
||||
<p><strong>Created At:</strong> {{ article.createdAt | date:'medium' }}</p>
|
||||
<p><strong>Last Updated:</strong> {{ article.updatedAt | date:'medium' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Error Message -->
|
||||
<ng-template #error>
|
||||
<div class="error-message">
|
||||
<h1>404</h1>
|
||||
<p>Article not found!</p>
|
||||
<a href="/blog"><button>Back to Overview</button></a>
|
||||
</div>
|
||||
</ng-template>
|
||||
</div>
|
||||
@@ -0,0 +1,130 @@
|
||||
import {AfterViewInit, Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '@angular/core';
|
||||
import {DeviceDetectorService} from '../services/device-detector.service'
|
||||
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';
|
||||
|
||||
interface Article {
|
||||
id: number;
|
||||
title: string;
|
||||
slug: string;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
views: number;
|
||||
authorId: number;
|
||||
authorName: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-article-page',
|
||||
imports: [
|
||||
NgIf,
|
||||
DatePipe
|
||||
],
|
||||
templateUrl: './article-page.component.html',
|
||||
styleUrl: './article-page.component.css'
|
||||
})
|
||||
export class ArticlePageComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
private readonly elementId = 'vanta-article-bg';
|
||||
isMobile: boolean = false;
|
||||
article: Article | undefined;
|
||||
currentArticle: any;
|
||||
constructor(
|
||||
private deviceService: DeviceDetectorService,
|
||||
private vantaService: VantaBackgroundService,
|
||||
private articleService: ArticleService,
|
||||
private updateMetaService: UpdateMetaService,
|
||||
private route: ActivatedRoute,
|
||||
@Inject(PLATFORM_ID) private platformId: Object
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.isMobile = this.deviceService.isMobile;
|
||||
|
||||
this.route.params.subscribe((params) => {
|
||||
const slug = params['slug'];
|
||||
if (slug) {
|
||||
this.loadArticleMetaBySlug(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'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
window.addEventListener('resize', this.onResize.bind(this));
|
||||
}
|
||||
const slug = this.route.snapshot.paramMap.get('slug') || '';
|
||||
this.articleService.getArticleBySlug(slug).subscribe(
|
||||
(article) => {
|
||||
this.article = article;
|
||||
console.log('Article found!')
|
||||
},
|
||||
(error) => {
|
||||
console.error('Error fetching article:', error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.vantaService.initVanta(this.elementId, {
|
||||
color: 0xac1f4e,
|
||||
backgroundColor: 0x191522
|
||||
});
|
||||
}
|
||||
ngOnDestroy() {
|
||||
this.vantaService.destroyVanta(this.elementId);
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
window.removeEventListener('resize', this.onResize);
|
||||
}
|
||||
}
|
||||
|
||||
onResize() {
|
||||
this.vantaService.resizeVanta(this.elementId);
|
||||
}
|
||||
|
||||
loadArticleMetaBySlug(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'
|
||||
});
|
||||
} 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'
|
||||
});
|
||||
}
|
||||
},
|
||||
(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'
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user