integrated handling for new thumbnail field from api response

This commit is contained in:
itzMiney committed 2026-04-28 13:10:21 +02:00
1 parent 36501d3096
commit 3def7a9936
12 files changed
+182 -46

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 53 KiB

-27
View File
@@ -31,15 +31,6 @@ const staticMeta = {
url: 'https://itzminey.dev/socials',
color: '#eb284c'
},
/*
'/services': {
title: 'Services | itzMiney',
description: 'All the Services I offer are listed here!',
image: 'https://meta.itzminey.dev/assets/ogimg.png',
url: 'https://itzminey.dev/services',
color: '#eb284c'
},
*/
'/blog': {
title: 'Blog | itzMiney',
description: 'Welcome to my blog! I\'ll post occasional updates here on the stuff I\'m currently up to.',
@@ -68,15 +59,6 @@ const staticMeta = {
url: 'https://itzminey.dev/404',
color: '#eb284c',
},
/*
'/tos': {
title: 'Terms of Service | itzMiney',
description: 'My Terms of Service for the Freelancing work I provide',
image: 'https://meta.itzminey.dev/assets/ogimg.png',
url: 'https://itzminey.dev/tos',
color: '#eb284c'
},
*/
'/privacy': {
title: 'Privacy Policy | itzMiney',
description: 'My Privacy Policy for the data collected on this site',
@@ -90,16 +72,7 @@ const staticMeta = {
image: 'https://meta.itzminey.dev/assets/ogimg.png',
url: 'https://itzminey.dev/imprint',
color: '#eb284c'
},
/*
'/shortener': {
title: 'Shortener | itzMiney',
description: 'URL Shortener',
image: 'https://meta.itzminey.dev/assets/ogimg.png',
url: 'https://itzminey.dev/shortener',
color: '#eb284c'
}
*/
};
// Output directory for pre-rendered metadata
+10
View File
@@ -113,6 +113,16 @@ form {
width: 100%;
}
#thumbUrl {
margin: 0 0 0 15px;
}
.action-bar.mobile #thumbUrl {
width: 100%;
margin: 0;
box-sizing: border-box;
}
#submitBtn,
#modeSel {
display: flex;
+8
View File
@@ -29,6 +29,14 @@
[required]="articleMode === 'create'"
[disabled]="articleMode === 'delete' || (articleMode === 'edit' && !editArticleLoaded)"
/>
<input
id="thumbUrl"
type="url"
name="thumb_url"
[(ngModel)]="thumb_url"
placeholder="Thumbnail URL"
[disabled]="articleMode === 'delete' || (articleMode === 'edit' && !editArticleLoaded)"
/>
<div class="mode-select-button" [ngStyle]="{'justify-content': isNarrow ? 'left' : 'center'}">
<div
id=modeSel (click)="toggleDropdown()"
+39 -8
View File
@@ -17,6 +17,7 @@ interface Article {
title: string;
slug: string;
content: string;
thumb_url: string | null;
createdAt: string;
updatedAt: string;
views: number;
@@ -50,6 +51,8 @@ export class AdminComponent implements OnInit, OnDestroy {
title: string = '';
content: string = '';
thumb_url: string = '';
originalThumbUrl = '';
modalTitle: string = '';
isUserModalOpen: boolean = false;
@@ -111,7 +114,7 @@ export class AdminComponent implements OnInit, OnDestroy {
});
}
createArticle(title:string, content: string) {
createArticle(title:string, content: string, thumb_url?: string) {
if (!title?.trim() || !content?.trim()) {
alert('Both title and content are required!');
return;
@@ -122,7 +125,12 @@ export class AdminComponent implements OnInit, OnDestroy {
const token = this.authService.token!;
this.articleService.postArticle(token, title.trim(), content.trim()).subscribe({
this.articleService.postArticle(
token,
title.trim(),
content.trim(),
thumb_url?.trim() || null
).subscribe({
next: () => {
alert('Article created successfully.');
this.articleIdValue = null;
@@ -137,7 +145,7 @@ export class AdminComponent implements OnInit, OnDestroy {
});
}
editArticle(articleId: number, title?: string, content?: string): void {
editArticle(articleId: number, title?: string, content?: string, thumb_url?: string ): void {
if (!articleId || isNaN(Number(articleId))) {
alert('Invalid input. Please enter a valid article ID.');
return;
@@ -156,12 +164,15 @@ export class AdminComponent implements OnInit, OnDestroy {
const titleChanged = updatedTitle !== this.originalTitle;
const contentChanged = updatedContent !== this.originalContent;
if (!titleChanged && !contentChanged) {
const updatedThumbUrl = thumb_url?.trim() ?? '';
const thumbUrlChanged = updatedThumbUrl !== this.originalThumbUrl;
if (!titleChanged && !contentChanged && !thumbUrlChanged) {
alert('No changes detected.');
return;
}
const updates: { title?: string; content?: string } = {};
const updates: { title?: string; content?: string, thumb_url?: string | null } = {};
if (titleChanged) {
updates.title = updatedTitle;
@@ -171,6 +182,10 @@ export class AdminComponent implements OnInit, OnDestroy {
updates.content = updatedContent;
}
if (thumbUrlChanged) {
updates.thumb_url = updatedThumbUrl || null;
}
this.authService.validateToken().subscribe({
next: (valid) => {
if (!valid) return;
@@ -192,6 +207,11 @@ export class AdminComponent implements OnInit, OnDestroy {
this.content = updatedContent;
}
if (thumbUrlChanged) {
this.originalThumbUrl = updatedThumbUrl;
this.thumb_url = updatedThumbUrl;
}
this.loadedArticle = {
...this.loadedArticle,
...response
@@ -258,6 +278,9 @@ export class AdminComponent implements OnInit, OnDestroy {
this.title = this.originalTitle;
this.content = this.originalContent;
this.originalThumbUrl = article.thumb_url ?? '';
this.thumb_url = this.originalThumbUrl;
this.editArticleLoaded = true;
this.loadingEditArticle = false;
this.articleNotFound = false;
@@ -483,8 +506,10 @@ export class AdminComponent implements OnInit, OnDestroy {
this.articleNotFound = false;
this.originalTitle = '';
this.originalContent = '';
this.originalThumbUrl = '';
this.title = '';
this.content = '';
this.thumb_url = '';
}
markArticleNotFound(): void {
@@ -523,10 +548,12 @@ export class AdminComponent implements OnInit, OnDestroy {
this.loadedArticle = article;
this.originalTitle = article.title ?? '';
this.originalContent = article.content ?? '';
this.originalThumbUrl = article.thumb_url ?? '';
if (this.articleMode === 'edit') {
this.title = this.originalTitle;
this.content = this.originalContent;
this.thumb_url = this.originalThumbUrl;
this.editArticleLoaded = true;
}
},
@@ -539,7 +566,11 @@ export class AdminComponent implements OnInit, OnDestroy {
}
get hasArticleChanges(): boolean {
return this.title !== this.originalTitle || this.content !== this.originalContent;
return (
this.title !== this.originalTitle ||
this.content !== this.originalContent ||
this.thumb_url !== this.originalThumbUrl
);
}
isArticleSubmitDisabled(): boolean {
@@ -564,9 +595,9 @@ export class AdminComponent implements OnInit, OnDestroy {
submitArticle() {
if (this.articleMode === 'create') {
this.createArticle(this.title, this.content);
this.createArticle(this.title, this.content, this.thumb_url);
} else if (this.articleMode === 'edit') {
this.editArticle(Number(this.articleIdValue), this.title, this.content);
this.editArticle(Number(this.articleIdValue), this.title, this.content, this.thumb_url);
} else if (this.articleMode === 'delete') {
this.deleteArticle(Number(this.articleIdValue));
}
@@ -24,6 +24,7 @@
}
h1 {
position: relative;
font-size: 2.5rem;
background: linear-gradient(to top, #a0eddb 0%, #ffffff 100%);
-webkit-background-clip: text;
@@ -32,6 +33,7 @@ h1 {
margin-top: 120px;
margin-bottom: 40px;
font-weight: 600;
z-index: 10;
}
.article-content {
@@ -51,6 +53,39 @@ h1 {
line-height: 1.2;
}
.article-thumb {
width: 70%;
aspect-ratio: 2.5 / 1;
object-fit: cover;
border-radius: 25px 25px 0 0;
margin: 67px auto -200px auto;
z-index: -100;
-webkit-mask-image: linear-gradient(
to bottom,
black 0%,
rgba(0, 0, 0, 0.95) 50%,
rgba(0, 0, 0, 0.7) 70%,
rgba(0, 0, 0, 0.3) 85%,
transparent 100%
);
mask-image: linear-gradient(
to bottom,
black 0%,
rgba(0, 0, 0, 0.95) 50%,
rgba(0, 0, 0, 0.7) 70%,
rgba(0, 0, 0, 0.3) 85%,
transparent 100%
);
filter: brightness(0.9);
}
.article-thumb.narrow {
width: 100%;
margin: 50px auto -160px auto;
}
.article-meta {
font-size: 1rem;
color: #D6DAEFBD;
@@ -15,6 +15,13 @@
<!-- Article -->
<div class="article-container">
<div>
<img
class="article-thumb"
[src]="article.thumb_url"
[alt]="article.title + ' thumbnail'"
(error)="onThumbError($event)"
[ngClass]="{ 'narrow': isNarrow }"
/>
<h1>{{ article.title }}</h1>
<div class="content-container" [ngStyle]="{'width': isNarrow ? '100%' : '70%'}">
<markdown
@@ -1,5 +1,5 @@
import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import { DatePipe, NgStyle } from '@angular/common';
import {DatePipe, NgClass, NgStyle} from '@angular/common';
import {ArticleService} from '../../shared/services/article.service';
import {ActivatedRoute} from '@angular/router';
import {Title} from '@angular/platform-browser';
@@ -13,6 +13,7 @@ interface Article {
title: string;
slug: string;
content: string;
thumb_url: string | null;
createdAt: string;
updatedAt: string;
views: number;
@@ -28,7 +29,8 @@ interface Article {
NgStyle,
TranslatePipe,
ParallaxComponent,
MarkdownModule
MarkdownModule,
NgClass
],
templateUrl: './article-page.component.html',
styleUrl: './article-page.component.css'
@@ -43,6 +45,8 @@ export class ArticlePageComponent implements OnInit {
renderedContent: string = '';
readonly defaultThumbUrl = '/assets/ogimg.png';
isNarrow: boolean = false;
constructor(
@@ -95,6 +99,14 @@ export class ArticlePageComponent implements OnInit {
});
}
onThumbError(event: Event): void {
const img = event.target as HTMLImageElement;
if (img.src.endsWith(this.defaultThumbUrl)) return;
img.src = this.defaultThumbUrl;
}
onArticleContentClick(event: MouseEvent) {
const target = event.target as HTMLElement;
+33
View File
@@ -50,6 +50,10 @@
}
.article-card {
display: flex;
align-items: center;
gap: 18px;
text-align: left;
z-index: 10;
background: rgba(40, 41, 89, 0.5);
padding: 15px;
@@ -61,11 +65,40 @@
transition: background-color 0.3s, transform 0.2s;
}
.article-card.narrow {
flex-direction: column;
text-align: center;
width: 90%;
max-width: 90%;
box-sizing: border-box;
margin-left: auto;
margin-right: auto;
}
.article-card:hover {
background: linear-gradient(135deg, #4637cd, #282959);
transform: translateY(-5px);
}
.article-card-thumb {
width: 200px;
aspect-ratio: 3 / 2;
flex-shrink: 0;
object-fit: cover;
border-radius: 28px 12px;
filter: brightness(0.9);
}
.article-card-thumb.narrow {
width: 100%;
aspect-ratio: 2 / 1;
}
.article-card-content {
min-width: 0;
}
h2 {
font-size: 1.6rem;
color: white;
+13 -4
View File
@@ -15,10 +15,19 @@
@if (articles$ | async; as articles) {
<div>
@for (article of articles.slice(); track article) {
<div (click)="navigateToArticle(article.slug)" class="article-card">
<h2>{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}</h2>
<p>{{ truncateContent(article.content, 80) }}</p>
<p><small>By {{ article.authorName }} | {{ article.createdAt | date: 'dd/MM/yy, HH:mm' }}</small></p>
<div (click)="navigateToArticle(article.slug)" class="article-card" [ngClass]="{ 'narrow': isNarrow }">
<img
class="article-card-thumb"
[src]="article.thumb_url || defaultThumbUrl"
[alt]="article.title + ' thumbnail'"
(error)="onThumbError($event)"
[ngClass]="{ 'narrow': isNarrow}"
/>
<div class="article-card-content">
<h2>{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}</h2>
<p>{{ truncateContent(article.content, 80) }}</p>
<p><small>By {{ article.authorName }} | {{ article.createdAt | date: 'dd/MM/yy, HH:mm' }}</small></p>
</div>
</div>
}
</div>
+13 -2
View File
@@ -1,6 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {ViewportService} from '../shared/services/viewport.service'
import { DatePipe, AsyncPipe, SlicePipe, NgStyle } from '@angular/common';
import {DatePipe, AsyncPipe, SlicePipe, NgStyle, NgClass} from '@angular/common';
import { ArticleService } from '../shared/services/article.service';
import { Router } from '@angular/router';
import {Observable} from 'rxjs';
@@ -16,7 +16,8 @@ import {ParallaxComponent} from '../shared/parallax/parallax.component';
SlicePipe,
NgStyle,
TranslatePipe,
ParallaxComponent
ParallaxComponent,
NgClass
],
templateUrl: './blog.component.html',
styleUrl: './blog.component.css'
@@ -24,6 +25,8 @@ import {ParallaxComponent} from '../shared/parallax/parallax.component';
export class BlogComponent implements OnInit {
articles$: Observable<any[]> | undefined;
isNarrow: boolean = false;
readonly defaultThumbUrl = '/assets/ogimg.png';
constructor(
private deviceService: ViewportService,
private articleService: ArticleService,
@@ -37,6 +40,14 @@ export class BlogComponent implements OnInit {
this.articles$ = this.articleService.getAllArticles();
}
onThumbError(event: Event): void {
const img = event.target as HTMLImageElement;
if (img.src.endsWith(this.defaultThumbUrl)) return;
img.src = this.defaultThumbUrl;
}
navigateToArticle(slug: string): void {
this.router.navigate([`/blog/${slug}`]).then(
(success) => {
+10 -3
View File
@@ -8,6 +8,7 @@ interface Article {
title: string;
slug: string;
content: string;
thumb_url: string | null;
createdAt: string;
updatedAt: string;
views: number;
@@ -46,10 +47,16 @@ export class ArticleService {
);
}
postArticle(token: string, title: string, content: string ): Observable<any[]> {
postArticle(
token: string,
title: string,
content: string ,
thumb_url?: string | null
): Observable<any> {
return this.http.post<any[]>(this.apiUrl, {
title,
content
content,
thumb_url: thumb_url?.trim() || null,
},{
headers: {
'Authorization': `Bearer ${token}`
@@ -70,7 +77,7 @@ export class ArticleService {
editArticle(
id: number,
token: string | null,
updates: { title?: string; content?: string }
updates: { title?: string; content?: string, thumb_url?: string | null }
): Observable<any> {
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
return this.http.put<any>(`${this.apiUrl}/${id}`, updates, { headers });