Intégration d'iframe pour les vidéos youtube (REGEX DE LA MORT QUI TUE)

This commit is contained in:
Guams 2025-01-27 22:04:14 +01:00
parent 6c52142c2e
commit 4990bd9db7
2 changed files with 17 additions and 5 deletions

View File

@ -1,9 +1,9 @@
<footer class="footer">
<p class="footer-creator">Site web réalisé par <strong>Guams</strong>.</p>
<p class="footer-banner">Bannière réalisée par <a href="https://twitter.com/Orabiss" target="_blank" class="footer-link">&#64;Orabiss</a> sur Twitter.</p>
<p class="footer-banner">Bannière réalisée par <a href="https://x.com/Orabisss" target="_blank" class="footer-link">&#64;Orabisss</a> sur Twitter.</p>
<p class="footer-follow">Suivez-moi sur :</p>
<p class="footer-links">
<a href="https://x.com/Orabisss" target="_blank" class="footer-link">Twitter</a>
<a href="https://x.com/Guams8" target="_blank" class="footer-link">Twitter</a>
<a href="https://github.com/Guamss" target="_blank" class="footer-link">GitHub</a>
</p>
<p class="footer-copyright">&copy; 2024 Guams. Tous droits réservés.</p>

View File

@ -1,4 +1,4 @@
import {Component, Input, OnDestroy} from '@angular/core';
import {AfterViewInit, Component, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
import {InputTextModule} from 'primeng/inputtext';
import {InputTextareaModule} from 'primeng/inputtextarea';
@ -65,6 +65,7 @@ export class PostFormComponent implements OnDestroy {
}
}
loadPostData(): void {
if (this.postId) {
this.subs.push(
@ -94,7 +95,7 @@ export class PostFormComponent implements OnDestroy {
onSubmit(): void {
if (this.form.valid && this.uploadedFile) {
const formData = this.form.value;
// this.transformParagraphs()
formData.body = this.transformYouTubeLinksToIframes(formData.body);
const postData: any = {
title: formData.title,
description: formData.description,
@ -109,7 +110,10 @@ export class PostFormComponent implements OnDestroy {
return this.postService.changeIllustration(this.postId, this.uploadedFile, this.cookieService.get('token'));
})
).subscribe({
next: (_) => this.successMessage('Succès', 'Post créé avec succès'),
next: (_) => {
this.successMessage('Succès', 'Post mis à jour avec succès')
console.log(this.body);
},
error: (err) => this.failureMessage('Erreur', err.message)
})
);
@ -126,6 +130,7 @@ export class PostFormComponent implements OnDestroy {
).subscribe({
next: () => {
this.router.navigate(['/']).then(() => {
console.log(this.body);
this.successMessage('Succès', 'Post créé avec succès')
});
},
@ -136,6 +141,13 @@ export class PostFormComponent implements OnDestroy {
}
}
private transformYouTubeLinksToIframes(html: string): string {
return html.replace(/<a[^>]*href="(https?:\/\/(?:www\.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]+)[^"]*)".*?<\/a>/g,
(_, url, _prefix, videoId) => {
return `<iframe width="560" height="315" src="https://www.youtube.com/embed/${videoId}" frameborder="0" allowfullscreen></iframe>`;
});
}
choose(callback: Function) {
callback();
}