-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean-html-tags.js
More file actions
63 lines (50 loc) · 1.7 KB
/
clean-html-tags.js
File metadata and controls
63 lines (50 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const fs = require('fs');
const path = require('path');
const sanitizeHtml = require('sanitize-html');
const baseDir = path.join(__dirname, '.');
const dataFile = path.join(baseDir, 'source', '_data', 'breaches.json');
console.log('Chargement des données...');
const db = JSON.parse(fs.readFileSync(dataFile, 'utf-8'));
let cleanedCount = 0;
console.log(`Traitement de ${db.breaches.length} fuites...`);
// Fonction pour enlever les balises HTML
function removeHtmlTags(text) {
if (!text || typeof text !== 'string') {
return text;
}
// Enlever les balises HTML en utilisant une bibliothèque de sanitisation
return sanitizeHtml(text, {
allowedTags: [],
allowedAttributes: {}
});
}
db.breaches.forEach((breach, index) => {
if (!breach || breach.IsRetired) {
return;
}
// Nettoyer le champ Description
if (breach.Description && typeof breach.Description === 'string') {
const cleaned = removeHtmlTags(breach.Description);
if (cleaned !== breach.Description) {
breach.Description = cleaned;
cleanedCount++;
}
}
// Nettoyer le champ content
if (breach.content && typeof breach.content === 'string') {
const cleaned = removeHtmlTags(breach.content);
if (cleaned !== breach.content) {
breach.content = cleaned;
cleanedCount++;
}
}
});
// Mettre à jour la date
db.lastUpdated = new Date().toISOString();
// Sauvegarder
console.log('\nSauvegarde des modifications...');
fs.writeFileSync(dataFile, JSON.stringify(db, null, 2));
fs.writeFileSync(path.join(baseDir, 'source', 'data', 'breaches.json'), JSON.stringify(db, null, 2));
console.log('\n✅ Traitement terminé !');
console.log(` - ${cleanedCount} champs nettoyés`);