integrated handling for new thumbnail field from api response
This commit is contained in:
1 parent
36501d3096
commit
3def7a9936
12 files changed
+179
-43
No files matched your search
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 53 KiB |
@@ -31,15 +31,6 @@ const staticMeta = {
|
|||||||
url: 'https://itzminey.dev/socials',
|
url: 'https://itzminey.dev/socials',
|
||||||
color: '#eb284c'
|
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': {
|
'/blog': {
|
||||||
title: 'Blog | itzMiney',
|
title: 'Blog | itzMiney',
|
||||||
description: 'Welcome to my blog! I\'ll post occasional updates here on the stuff I\'m currently up to.',
|
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',
|
url: 'https://itzminey.dev/404',
|
||||||
color: '#eb284c',
|
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': {
|
'/privacy': {
|
||||||
title: 'Privacy Policy | itzMiney',
|
title: 'Privacy Policy | itzMiney',
|
||||||
description: 'My Privacy Policy for the data collected on this site',
|
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',
|
image: 'https://meta.itzminey.dev/assets/ogimg.png',
|
||||||
url: 'https://itzminey.dev/imprint',
|
url: 'https://itzminey.dev/imprint',
|
||||||
color: '#eb284c'
|
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
|
// Output directory for pre-rendered metadata
|
||||||
|
|||||||
@@ -113,6 +113,16 @@ form {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#thumbUrl {
|
||||||
|
margin: 0 0 0 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-bar.mobile #thumbUrl {
|
||||||
|
width: 100%;
|
||||||
|
margin: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
#submitBtn,
|
#submitBtn,
|
||||||
#modeSel {
|
#modeSel {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -29,6 +29,14 @@
|
|||||||
[required]="articleMode === 'create'"
|
[required]="articleMode === 'create'"
|
||||||
[disabled]="articleMode === 'delete' || (articleMode === 'edit' && !editArticleLoaded)"
|
[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 class="mode-select-button" [ngStyle]="{'justify-content': isNarrow ? 'left' : 'center'}">
|
||||||
<div
|
<div
|
||||||
id=modeSel (click)="toggleDropdown()"
|
id=modeSel (click)="toggleDropdown()"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ interface Article {
|
|||||||
title: string;
|
title: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
thumb_url: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
views: number;
|
views: number;
|
||||||
@@ -50,6 +51,8 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
title: string = '';
|
title: string = '';
|
||||||
content: string = '';
|
content: string = '';
|
||||||
|
thumb_url: string = '';
|
||||||
|
originalThumbUrl = '';
|
||||||
|
|
||||||
modalTitle: string = '';
|
modalTitle: string = '';
|
||||||
isUserModalOpen: boolean = false;
|
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()) {
|
if (!title?.trim() || !content?.trim()) {
|
||||||
alert('Both title and content are required!');
|
alert('Both title and content are required!');
|
||||||
return;
|
return;
|
||||||
@@ -122,7 +125,12 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
const token = this.authService.token!;
|
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: () => {
|
next: () => {
|
||||||
alert('Article created successfully.');
|
alert('Article created successfully.');
|
||||||
this.articleIdValue = null;
|
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))) {
|
if (!articleId || isNaN(Number(articleId))) {
|
||||||
alert('Invalid input. Please enter a valid article ID.');
|
alert('Invalid input. Please enter a valid article ID.');
|
||||||
return;
|
return;
|
||||||
@@ -156,12 +164,15 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
const titleChanged = updatedTitle !== this.originalTitle;
|
const titleChanged = updatedTitle !== this.originalTitle;
|
||||||
const contentChanged = updatedContent !== this.originalContent;
|
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.');
|
alert('No changes detected.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updates: { title?: string; content?: string } = {};
|
const updates: { title?: string; content?: string, thumb_url?: string | null } = {};
|
||||||
|
|
||||||
if (titleChanged) {
|
if (titleChanged) {
|
||||||
updates.title = updatedTitle;
|
updates.title = updatedTitle;
|
||||||
@@ -171,6 +182,10 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
updates.content = updatedContent;
|
updates.content = updatedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (thumbUrlChanged) {
|
||||||
|
updates.thumb_url = updatedThumbUrl || null;
|
||||||
|
}
|
||||||
|
|
||||||
this.authService.validateToken().subscribe({
|
this.authService.validateToken().subscribe({
|
||||||
next: (valid) => {
|
next: (valid) => {
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
@@ -192,6 +207,11 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
this.content = updatedContent;
|
this.content = updatedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (thumbUrlChanged) {
|
||||||
|
this.originalThumbUrl = updatedThumbUrl;
|
||||||
|
this.thumb_url = updatedThumbUrl;
|
||||||
|
}
|
||||||
|
|
||||||
this.loadedArticle = {
|
this.loadedArticle = {
|
||||||
...this.loadedArticle,
|
...this.loadedArticle,
|
||||||
...response
|
...response
|
||||||
@@ -258,6 +278,9 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
this.title = this.originalTitle;
|
this.title = this.originalTitle;
|
||||||
this.content = this.originalContent;
|
this.content = this.originalContent;
|
||||||
|
|
||||||
|
this.originalThumbUrl = article.thumb_url ?? '';
|
||||||
|
this.thumb_url = this.originalThumbUrl;
|
||||||
|
|
||||||
this.editArticleLoaded = true;
|
this.editArticleLoaded = true;
|
||||||
this.loadingEditArticle = false;
|
this.loadingEditArticle = false;
|
||||||
this.articleNotFound = false;
|
this.articleNotFound = false;
|
||||||
@@ -483,8 +506,10 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
this.articleNotFound = false;
|
this.articleNotFound = false;
|
||||||
this.originalTitle = '';
|
this.originalTitle = '';
|
||||||
this.originalContent = '';
|
this.originalContent = '';
|
||||||
|
this.originalThumbUrl = '';
|
||||||
this.title = '';
|
this.title = '';
|
||||||
this.content = '';
|
this.content = '';
|
||||||
|
this.thumb_url = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
markArticleNotFound(): void {
|
markArticleNotFound(): void {
|
||||||
@@ -523,10 +548,12 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
this.loadedArticle = article;
|
this.loadedArticle = article;
|
||||||
this.originalTitle = article.title ?? '';
|
this.originalTitle = article.title ?? '';
|
||||||
this.originalContent = article.content ?? '';
|
this.originalContent = article.content ?? '';
|
||||||
|
this.originalThumbUrl = article.thumb_url ?? '';
|
||||||
|
|
||||||
if (this.articleMode === 'edit') {
|
if (this.articleMode === 'edit') {
|
||||||
this.title = this.originalTitle;
|
this.title = this.originalTitle;
|
||||||
this.content = this.originalContent;
|
this.content = this.originalContent;
|
||||||
|
this.thumb_url = this.originalThumbUrl;
|
||||||
this.editArticleLoaded = true;
|
this.editArticleLoaded = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -539,7 +566,11 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get hasArticleChanges(): boolean {
|
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 {
|
isArticleSubmitDisabled(): boolean {
|
||||||
@@ -564,9 +595,9 @@ export class AdminComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
submitArticle() {
|
submitArticle() {
|
||||||
if (this.articleMode === 'create') {
|
if (this.articleMode === 'create') {
|
||||||
this.createArticle(this.title, this.content);
|
this.createArticle(this.title, this.content, this.thumb_url);
|
||||||
} else if (this.articleMode === 'edit') {
|
} 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') {
|
} else if (this.articleMode === 'delete') {
|
||||||
this.deleteArticle(Number(this.articleIdValue));
|
this.deleteArticle(Number(this.articleIdValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
|
position: relative;
|
||||||
font-size: 2.5rem;
|
font-size: 2.5rem;
|
||||||
background: linear-gradient(to top, #a0eddb 0%, #ffffff 100%);
|
background: linear-gradient(to top, #a0eddb 0%, #ffffff 100%);
|
||||||
-webkit-background-clip: text;
|
-webkit-background-clip: text;
|
||||||
@@ -32,6 +33,7 @@ h1 {
|
|||||||
margin-top: 120px;
|
margin-top: 120px;
|
||||||
margin-bottom: 40px;
|
margin-bottom: 40px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.article-content {
|
.article-content {
|
||||||
@@ -51,6 +53,39 @@ h1 {
|
|||||||
line-height: 1.2;
|
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 {
|
.article-meta {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
color: #D6DAEFBD;
|
color: #D6DAEFBD;
|
||||||
|
|||||||
@@ -15,6 +15,13 @@
|
|||||||
<!-- Article -->
|
<!-- Article -->
|
||||||
<div class="article-container">
|
<div class="article-container">
|
||||||
<div>
|
<div>
|
||||||
|
<img
|
||||||
|
class="article-thumb"
|
||||||
|
[src]="article.thumb_url"
|
||||||
|
[alt]="article.title + ' thumbnail'"
|
||||||
|
(error)="onThumbError($event)"
|
||||||
|
[ngClass]="{ 'narrow': isNarrow }"
|
||||||
|
/>
|
||||||
<h1>{{ article.title }}</h1>
|
<h1>{{ article.title }}</h1>
|
||||||
<div class="content-container" [ngStyle]="{'width': isNarrow ? '100%' : '70%'}">
|
<div class="content-container" [ngStyle]="{'width': isNarrow ? '100%' : '70%'}">
|
||||||
<markdown
|
<markdown
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Component, OnInit, ViewEncapsulation} from '@angular/core';
|
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 {ArticleService} from '../../shared/services/article.service';
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute} from '@angular/router';
|
||||||
import {Title} from '@angular/platform-browser';
|
import {Title} from '@angular/platform-browser';
|
||||||
@@ -13,6 +13,7 @@ interface Article {
|
|||||||
title: string;
|
title: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
thumb_url: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
views: number;
|
views: number;
|
||||||
@@ -28,7 +29,8 @@ interface Article {
|
|||||||
NgStyle,
|
NgStyle,
|
||||||
TranslatePipe,
|
TranslatePipe,
|
||||||
ParallaxComponent,
|
ParallaxComponent,
|
||||||
MarkdownModule
|
MarkdownModule,
|
||||||
|
NgClass
|
||||||
],
|
],
|
||||||
templateUrl: './article-page.component.html',
|
templateUrl: './article-page.component.html',
|
||||||
styleUrl: './article-page.component.css'
|
styleUrl: './article-page.component.css'
|
||||||
@@ -43,6 +45,8 @@ export class ArticlePageComponent implements OnInit {
|
|||||||
|
|
||||||
renderedContent: string = '';
|
renderedContent: string = '';
|
||||||
|
|
||||||
|
readonly defaultThumbUrl = '/assets/ogimg.png';
|
||||||
|
|
||||||
isNarrow: boolean = false;
|
isNarrow: boolean = false;
|
||||||
|
|
||||||
constructor(
|
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) {
|
onArticleContentClick(event: MouseEvent) {
|
||||||
const target = event.target as HTMLElement;
|
const target = event.target as HTMLElement;
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.article-card {
|
.article-card {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 18px;
|
||||||
|
text-align: left;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
background: rgba(40, 41, 89, 0.5);
|
background: rgba(40, 41, 89, 0.5);
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
@@ -61,11 +65,40 @@
|
|||||||
transition: background-color 0.3s, transform 0.2s;
|
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 {
|
.article-card:hover {
|
||||||
background: linear-gradient(135deg, #4637cd, #282959);
|
background: linear-gradient(135deg, #4637cd, #282959);
|
||||||
transform: translateY(-5px);
|
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 {
|
h2 {
|
||||||
font-size: 1.6rem;
|
font-size: 1.6rem;
|
||||||
color: white;
|
color: white;
|
||||||
|
|||||||
@@ -15,11 +15,20 @@
|
|||||||
@if (articles$ | async; as articles) {
|
@if (articles$ | async; as articles) {
|
||||||
<div>
|
<div>
|
||||||
@for (article of articles.slice(); track article) {
|
@for (article of articles.slice(); track article) {
|
||||||
<div (click)="navigateToArticle(article.slug)" class="article-card">
|
<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>
|
<h2>{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}</h2>
|
||||||
<p>{{ truncateContent(article.content, 80) }}</p>
|
<p>{{ truncateContent(article.content, 80) }}</p>
|
||||||
<p><small>By {{ article.authorName }} | {{ article.createdAt | date: 'dd/MM/yy, HH:mm' }}</small></p>
|
<p><small>By {{ article.authorName }} | {{ article.createdAt | date: 'dd/MM/yy, HH:mm' }}</small></p>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
} @else {
|
} @else {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {ViewportService} from '../shared/services/viewport.service'
|
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 { ArticleService } from '../shared/services/article.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
@@ -16,7 +16,8 @@ import {ParallaxComponent} from '../shared/parallax/parallax.component';
|
|||||||
SlicePipe,
|
SlicePipe,
|
||||||
NgStyle,
|
NgStyle,
|
||||||
TranslatePipe,
|
TranslatePipe,
|
||||||
ParallaxComponent
|
ParallaxComponent,
|
||||||
|
NgClass
|
||||||
],
|
],
|
||||||
templateUrl: './blog.component.html',
|
templateUrl: './blog.component.html',
|
||||||
styleUrl: './blog.component.css'
|
styleUrl: './blog.component.css'
|
||||||
@@ -24,6 +25,8 @@ import {ParallaxComponent} from '../shared/parallax/parallax.component';
|
|||||||
export class BlogComponent implements OnInit {
|
export class BlogComponent implements OnInit {
|
||||||
articles$: Observable<any[]> | undefined;
|
articles$: Observable<any[]> | undefined;
|
||||||
isNarrow: boolean = false;
|
isNarrow: boolean = false;
|
||||||
|
readonly defaultThumbUrl = '/assets/ogimg.png';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private deviceService: ViewportService,
|
private deviceService: ViewportService,
|
||||||
private articleService: ArticleService,
|
private articleService: ArticleService,
|
||||||
@@ -37,6 +40,14 @@ export class BlogComponent implements OnInit {
|
|||||||
this.articles$ = this.articleService.getAllArticles();
|
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 {
|
navigateToArticle(slug: string): void {
|
||||||
this.router.navigate([`/blog/${slug}`]).then(
|
this.router.navigate([`/blog/${slug}`]).then(
|
||||||
(success) => {
|
(success) => {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ interface Article {
|
|||||||
title: string;
|
title: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
thumb_url: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
views: number;
|
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, {
|
return this.http.post<any[]>(this.apiUrl, {
|
||||||
title,
|
title,
|
||||||
content
|
content,
|
||||||
|
thumb_url: thumb_url?.trim() || null,
|
||||||
},{
|
},{
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`
|
'Authorization': `Bearer ${token}`
|
||||||
@@ -70,7 +77,7 @@ export class ArticleService {
|
|||||||
editArticle(
|
editArticle(
|
||||||
id: number,
|
id: number,
|
||||||
token: string | null,
|
token: string | null,
|
||||||
updates: { title?: string; content?: string }
|
updates: { title?: string; content?: string, thumb_url?: string | null }
|
||||||
): Observable<any> {
|
): Observable<any> {
|
||||||
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`);
|
||||||
return this.http.put<any>(`${this.apiUrl}/${id}`, updates, { headers });
|
return this.http.put<any>(`${this.apiUrl}/${id}`, updates, { headers });
|
||||||
|
|||||||
Reference in new issue
Block a user