Updated sanitization and truncation of article previews
This commit is contained in:
1 parent
5bbadfef1c
commit
6986c67494
2 files changed
+11
-1
No files matched your search
@@ -9,7 +9,7 @@
|
|||||||
<div *ngIf="articles$ | async as articles; else noArticles">
|
<div *ngIf="articles$ | async as articles; else noArticles">
|
||||||
<div *ngFor="let article of articles.slice().reverse()" (click)="navigateToArticle(article.slug)" class="article-card">
|
<div *ngFor="let article of articles.slice().reverse()" (click)="navigateToArticle(article.slug)" class="article-card">
|
||||||
<h2>{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}</h2>
|
<h2>{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}</h2>
|
||||||
<p>{{ (article.content | slice:0:80) + (article.content.length > 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>
|
||||||
|
|||||||
@@ -75,4 +75,14 @@ export class BlogComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
onResize() {
|
onResize() {
|
||||||
this.vantaService.resizeVanta(this.elementId);
|
this.vantaService.resizeVanta(this.elementId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user