-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathzep1.js
51 lines (40 loc) · 1.76 KB
/
zep1.js
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
// USO: node zep1
//
// Se ejecuta con el fin de obtener un JSON ordenado con la metadata de cada pagina compilada, de manera que
// se obtenga una palabra clave y una ruta que queda guardada en un archivo llamado metadata_zep.json
const fs = require('fs');
const path = require('path');
const guiasPath = path.join(__dirname, 'docs', '.vitepress', 'dist', 'guias');
function buscarMetadataZep(htmlFilePath) {
const content = fs.readFileSync(htmlFilePath, 'utf-8');
const metaTagMatch = content.match(/<meta\s+name="zep"\s+content="([^"]*)"/);
return metaTagMatch ? metaTagMatch[1] : null;
}
function explorarCarpetas(basePath, relativePath = '') {
const elements = fs.readdirSync(basePath);
const resultado = [];
elements.forEach(element => {
const fullPath = path.join(basePath, element);
const relativeElementPath = path.join(relativePath, element);
if (fs.statSync(fullPath).isDirectory()) {
resultado.push(...explorarCarpetas(fullPath, relativeElementPath));
} else if (path.extname(fullPath) === '.html') {
const zepContent = buscarMetadataZep(fullPath);
if (zepContent) {
resultado.push({
ruta: path.join(relativePath, path.basename(element, '.html')).replace(/\\/g, '/'),
clave: zepContent
});
}
}
});
return resultado;
}
if (fs.existsSync(guiasPath)) {
const datosExtraidos = explorarCarpetas(guiasPath);
const outputPath = path.join(__dirname, 'metadata_zep.json');
fs.writeFileSync(outputPath, JSON.stringify(datosExtraidos, null, 2), 'utf-8');
console.log(`Datos extraídos y guardados en: ${outputPath}`);
} else {
console.error(`La ruta ${guiasPath} no existe.`);
}