integrated handling for new thumbnail field from api response
This commit is contained in:
1 parent
36501d3096
commit
3def7a9936
12 files changed
+182
-46
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in new issue
Block a user