1509 lines
43 KiB
JavaScript
1509 lines
43 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Generador de Libro de Estudio Offline
|
|
* ======================================
|
|
*
|
|
* Extrae el contenido académico de las páginas HTML descargadas del campus
|
|
* virtual y genera dos formatos de estudio:
|
|
* - LIBRO_DE_ESTUDIO.html → Versión navegable con portada, índice y CSS
|
|
* - LIBRO_DE_ESTUDIO.md → Versión Markdown para leer en cualquier editor
|
|
*
|
|
* Modo de uso:
|
|
* node generar_dashboard.mjs
|
|
*
|
|
* Requisitos:
|
|
* - Haber ejecutado antes download_course.mjs para tener los HTML locales
|
|
* - Funciona 100% offline, solo usa fs.readFileSync
|
|
*/
|
|
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const DOWNLOADS_DIR = path.join(__dirname, "descargas");
|
|
const SECCIONES_DIR = path.join(DOWNLOADS_DIR, "secciones");
|
|
|
|
// ============================================================
|
|
// DATOS DEL CURSO — Estructura de módulos y secciones
|
|
// ============================================================
|
|
|
|
const MODULOS = [
|
|
{
|
|
titulo: "Módulo 1 — Planificación",
|
|
carpeta: "Modulo_1_Planificacion",
|
|
secciones: [
|
|
{ carpeta: "Planificacion", titulo: "Planificación" },
|
|
{ carpeta: "Preparacion_Atletica", titulo: "Preparación Atlética" },
|
|
{ carpeta: "Explicacion_TP", titulo: "Explicación del Trabajo Práctico a Presentar" },
|
|
{ carpeta: "Seguimientos_Equipos", titulo: "Seguimientos de Equipos" },
|
|
{
|
|
carpeta: "Analisis_Equipos_1",
|
|
titulo: "Análisis de Equipos de Voleibol",
|
|
},
|
|
{
|
|
carpeta: "Analisis_Equipos_2",
|
|
titulo: "Análisis de Equipos de Voleibol 2",
|
|
},
|
|
{
|
|
carpeta: "TP_Final_Unidad",
|
|
titulo: "Trabajo Práctico Final de la Unidad",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
titulo: "Módulo 2 — Entrenamiento",
|
|
carpeta: "Modulo_2_Entrenamiento",
|
|
secciones: [
|
|
{
|
|
carpeta: "Centrales_y_Oponentes",
|
|
titulo: "Entrenamiento de los Centrales y Opuestos/as",
|
|
},
|
|
{ carpeta: "Puntas_y_Liberos", titulo: "Puntas y Liberos/as" },
|
|
{
|
|
carpeta: "Entrenamiento_Armadoras",
|
|
titulo: "Entrenamiento de los y las Armadoras",
|
|
},
|
|
{ carpeta: "Explicacion_TP", titulo: "Explicación del Trabajo Práctico a Presentar" },
|
|
],
|
|
},
|
|
];
|
|
|
|
// ============================================================
|
|
// EXTRACCIÓN DE CONTENIDO DESDE HTML
|
|
// ============================================================
|
|
|
|
/**
|
|
* Lee un archivo HTML y extrae los temas de estudio organizados.
|
|
*
|
|
* Cada fila <tr> dentro de las tablas study-resources representa un tema.
|
|
* Puede contener:
|
|
* - Contenido de estudio en <div class="redactor-usr-input">
|
|
* - Un video Vimeo en <div class="embed-video"> con <iframe>
|
|
* - Un recurso descargable con enlace "Abrir Archivo"
|
|
* - Un enlace externo con "Abrir Enlace"
|
|
*
|
|
* @param {string} filePath - Ruta al archivo pagina.html
|
|
* @returns {Array<{titulo: string, contenido: string, videos: string[], recursos: string[]}>}
|
|
*/
|
|
function extraerTemas(filePath) {
|
|
const temas = [];
|
|
|
|
try {
|
|
if (!fs.existsSync(filePath)) return temas;
|
|
const html = fs.readFileSync(filePath, "utf-8");
|
|
|
|
// Detectar páginas de error
|
|
if (
|
|
html.includes("An Error Occurred") ||
|
|
html.includes("500 Internal Server Error")
|
|
) {
|
|
return temas;
|
|
}
|
|
|
|
// Extraer título de la sección desde el <h1> de la página
|
|
const tituloSeccionMatch = html.match(
|
|
/<div class="pageheader">\s*<h1>([^<]+)<\/h1>/i,
|
|
);
|
|
const tituloSeccion = tituloSeccionMatch
|
|
? tituloSeccionMatch[1].trim()
|
|
: "Materiales de estudio";
|
|
|
|
// Buscar todas las tablas de estudio con un extractor que maneja anidamiento
|
|
const tablas = extraerTablasAnidadas(
|
|
html,
|
|
'table class="table table-bordered study-resources"',
|
|
);
|
|
if (tablas.length === 0) return temas;
|
|
|
|
for (const tabla of tablas) {
|
|
// Extraer tipo de material desde el <th>
|
|
const tipoMatch = tabla.match(/<th[^>]*>([^<]+)<\/th>/i);
|
|
const tipoMaterial = tipoMatch ? tipoMatch[1].trim() : "Material";
|
|
|
|
// Extraer cada fila <tr> manejando anidamiento (pueden tener tablas dentro)
|
|
const filas = extraerFilasAnidadas(tabla);
|
|
|
|
for (const fila of filas) {
|
|
// Saltar filas que solo contienen <th> en el tr directo (encabezados),
|
|
// pero NO filtrar filas cuyo contenido de estudio tenga tablas anidadas con <th>
|
|
const trimmed = fila.trim();
|
|
// Buscar <th> solo dentro del primer nivel del <tr> (antes de cualquier <table> anidada)
|
|
const primerParte = fila.split("<table")[0];
|
|
if (trimmed.startsWith("<tr") && primerParte.includes("<th")) continue;
|
|
// Saltar filas que no tienen <td>
|
|
if (!fila.includes("<td")) continue;
|
|
|
|
const tema = procesarFila(fila, tipoMaterial);
|
|
if (tema) temas.push(tema);
|
|
}
|
|
}
|
|
} catch {
|
|
// Si hay error de lectura, devolver array vacío
|
|
}
|
|
|
|
return temas;
|
|
}
|
|
|
|
/**
|
|
* Extrae bloques <table> del HTML manejando anidamiento correctamente.
|
|
* Busca la cadena de apertura y encuentra su </table> de cierre contando niveles.
|
|
*/
|
|
function extraerTablasAnidadas(html, matchStr) {
|
|
const tablas = [];
|
|
let pos = 0;
|
|
while (true) {
|
|
const start = html.indexOf("<" + matchStr, pos);
|
|
if (start === -1) break;
|
|
// Encontrar el > final de la etiqueta de apertura
|
|
const openEnd = html.indexOf(">", start);
|
|
if (openEnd === -1) break;
|
|
|
|
// Contar anidamiento desde openEnd + 1
|
|
let depth = 1;
|
|
let searchPos = openEnd + 1;
|
|
while (depth > 0 && searchPos < html.length) {
|
|
const nextOpen = html.indexOf("<table", searchPos);
|
|
const nextClose = html.indexOf("</table>", searchPos);
|
|
if (nextClose === -1) break;
|
|
if (nextOpen !== -1 && nextOpen < nextClose) {
|
|
depth++;
|
|
searchPos = nextOpen + 6;
|
|
} else {
|
|
depth--;
|
|
searchPos = nextClose + 8;
|
|
}
|
|
}
|
|
tablas.push(html.substring(start, searchPos));
|
|
pos = searchPos;
|
|
}
|
|
return tablas;
|
|
}
|
|
|
|
/**
|
|
* Extrae filas <tr> de una tabla manejando anidamiento de tablas internas.
|
|
*/
|
|
function extraerFilasAnidadas(tableHTML) {
|
|
const filas = [];
|
|
const tbodyStart = tableHTML.indexOf("<tbody>");
|
|
if (tbodyStart === -1) return filas;
|
|
const tbody = tableHTML.substring(tbodyStart);
|
|
|
|
let pos = 0;
|
|
while (true) {
|
|
const trStart = tbody.indexOf("<tr", pos);
|
|
if (trStart === -1) break;
|
|
|
|
// Encontrar </tr> de cierre contando anidamiento de <tr> y <table>
|
|
let trDepth = 1;
|
|
let tableDepth = 0;
|
|
let searchPos = trStart + 3;
|
|
|
|
while (trDepth > 0 && searchPos < tbody.length) {
|
|
const trOpen = tbody.indexOf("<tr", searchPos);
|
|
const trClose = tbody.indexOf("</tr>", searchPos);
|
|
const tableOpen = tbody.indexOf("<table", searchPos);
|
|
const tableClose = tbody.indexOf("</table>", searchPos);
|
|
|
|
if (trClose === -1) break;
|
|
|
|
// Encontrar el tag relevante más cercano
|
|
let earliestType = null;
|
|
let earliestPos = Infinity;
|
|
|
|
const candidates = [];
|
|
if (trOpen !== -1) candidates.push({ type: "trOpen", pos: trOpen });
|
|
if (trClose !== -1) candidates.push({ type: "trClose", pos: trClose });
|
|
if (tableOpen !== -1)
|
|
candidates.push({ type: "tableOpen", pos: tableOpen });
|
|
if (tableClose !== -1)
|
|
candidates.push({ type: "tableClose", pos: tableClose });
|
|
|
|
for (const c of candidates) {
|
|
if (c.pos < earliestPos) {
|
|
earliestPos = c.pos;
|
|
earliestType = c.type;
|
|
}
|
|
}
|
|
|
|
if (!earliestType) break;
|
|
|
|
switch (earliestType) {
|
|
case "tableOpen":
|
|
tableDepth++;
|
|
searchPos = earliestPos + 6;
|
|
break;
|
|
case "tableClose":
|
|
tableDepth = Math.max(0, tableDepth - 1);
|
|
searchPos = earliestPos + 7;
|
|
break;
|
|
case "trOpen":
|
|
if (tableDepth === 0) trDepth++;
|
|
searchPos = earliestPos + 3;
|
|
break;
|
|
case "trClose":
|
|
if (tableDepth === 0) trDepth--;
|
|
searchPos = earliestPos + 5;
|
|
break;
|
|
}
|
|
}
|
|
|
|
filas.push(tbody.substring(trStart, searchPos));
|
|
pos = searchPos;
|
|
}
|
|
return filas;
|
|
}
|
|
|
|
/**
|
|
* Procesa una fila <tr> individual y extrae título, contenido, videos y recursos.
|
|
*/
|
|
function procesarFila(filaHTML, tipoMaterial) {
|
|
// Extraer título del tema (está dentro de <em>)
|
|
const tituloMatch = filaHTML.match(/<em>([\s\S]*?)<\/em>/i);
|
|
const titulo = tituloMatch
|
|
? limpiarHTML(tituloMatch[1]).trim()
|
|
: "Sin título";
|
|
|
|
// Extraer tipo (Video / Archivo / Enlace)
|
|
const tipoMatch = filaHTML.match(/<strong>(Video|Archivo|Enlace)<\/strong>/i);
|
|
const tipo = tipoMatch ? tipoMatch[1] : "";
|
|
|
|
// Extraer autor
|
|
const autorMatch = filaHTML.match(/por\s+([^•<]+)/i);
|
|
const autor = autorMatch ? autorMatch[1].trim() : "";
|
|
|
|
// Extraer ID de video Vimeo
|
|
const vimeoMatch = filaHTML.match(/player\.vimeo\.com\/video\/(\d+)/i);
|
|
const vimeoID = vimeoMatch ? vimeoMatch[1] : null;
|
|
|
|
// Extraer enlace a recurso (Abrir Archivo o Abrir Enlace)
|
|
const recursoMatch = filaHTML.match(
|
|
/<a[^>]*href="([^"]*)"[^>]*class="btn[^"]*"[^>]*>(Abrir (?:Archivo|Enlace))<\/a>/i,
|
|
);
|
|
const recursoURL = recursoMatch ? recursoMatch[1] : null;
|
|
const recursoTexto = recursoMatch ? recursoMatch[2] : null;
|
|
const recursoIDMatch = recursoURL ? recursoURL.match(/study-resources\/(\d+)\/show/) : null;
|
|
const recursoID = recursoIDMatch ? recursoIDMatch[1] : null;
|
|
|
|
// Extraer contenido de estudio real (dentro de redactor-usr-input)
|
|
const contenidoMatch = filaHTML.match(
|
|
/<div class="redactor-usr-input">([\s\S]*?)<\/div>/i,
|
|
);
|
|
let contenidoHTML = contenidoMatch ? contenidoMatch[1].trim() : "";
|
|
|
|
// Limpiar el contenido: eliminar <br> redundantes, normalizar
|
|
contenidoHTML = limpiarContenidoEstudio(contenidoHTML);
|
|
|
|
// Si no hay contenido de estudio ni video ni recurso, no generamos entrada
|
|
if (!contenidoHTML && !vimeoID && !recursoURL) return null;
|
|
|
|
// Id único para anclajes
|
|
const id = titulo
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9áéíóúüñ]+/gi, "-")
|
|
.replace(/-+/g, "-")
|
|
.replace(/^-|-$/g, "");
|
|
|
|
return {
|
|
id,
|
|
titulo,
|
|
tipo,
|
|
autor,
|
|
contenidoHTML,
|
|
vimeoID,
|
|
recursoURL,
|
|
recursoTexto,
|
|
recursoID,
|
|
tipoMaterial,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Limpia etiquetas HTML no deseadas del contenido de estudio.
|
|
* Preserva el formato educativo: títulos, párrafos, listas, tablas, citas.
|
|
*/
|
|
function limpiarContenidoEstudio(html) {
|
|
if (!html) return "";
|
|
|
|
let texto = html;
|
|
|
|
// Eliminar estilos inline que no aportan valor educativo
|
|
texto = texto.replace(/\s*style="[^"]*"/gi, "");
|
|
|
|
// Normalizar saltos de línea
|
|
texto = texto.replace(/<br\s*\/?>\s*<br\s*\/?>/gi, "<br>");
|
|
texto = texto.replace(/(<br\s*\/?>\s*){3,}/gi, "<br><br>");
|
|
|
|
// Eliminar nbsp excesivos
|
|
texto = texto.replace(/( \s*){3,}/g, " ");
|
|
|
|
// Eliminar divs vacíos o wrappers que no aportan contenido
|
|
texto = texto.replace(/<div>\s*<\/div>/gi, "");
|
|
|
|
return texto.trim();
|
|
}
|
|
|
|
/**
|
|
* Convierte HTML de estudio a Markdown limpio y legible.
|
|
*/
|
|
function htmlAMarkdown(html) {
|
|
if (!html) return "";
|
|
|
|
let md = html;
|
|
|
|
// ── Títulos ──
|
|
md = md.replace(/<h1[^>]*>([\s\S]*?)<\/h1>/gi, "# $1\n\n");
|
|
md = md.replace(/<h2[^>]*>([\s\S]*?)<\/h2>/gi, "## $1\n\n");
|
|
md = md.replace(/<h3[^>]*>([\s\S]*?)<\/h3>/gi, "### $1\n\n");
|
|
md = md.replace(/<h4[^>]*>([\s\S]*?)<\/h4>/gi, "#### $1\n\n");
|
|
md = md.replace(/<h5[^>]*>([\s\S]*?)<\/h5>/gi, "##### $1\n\n");
|
|
|
|
// ── Énfasis ──
|
|
md = md.replace(/<strong>([\s\S]*?)<\/strong>/gi, "**$1**");
|
|
md = md.replace(/<b>([\s\S]*?)<\/b>/gi, "**$1**");
|
|
md = md.replace(/<em>([\s\S]*?)<\/em>/gi, "*$1*");
|
|
md = md.replace(/<i>([\s\S]*?)<\/i>/gi, "*$1*");
|
|
|
|
// ── Párrafos ──
|
|
md = md.replace(/<p[^>]*>([\s\S]*?)<\/p>/gi, "$1\n\n");
|
|
|
|
// ── Listas ──
|
|
md = md.replace(/<ul[^>]*>([\s\S]*?)<\/ul>/gi, "$1\n");
|
|
md = md.replace(/<ol[^>]*>([\s\S]*?)<\/ol>/gi, "$1\n");
|
|
md = md.replace(/<li[^>]*>([\s\S]*?)<\/li>/gi, "- $1\n");
|
|
|
|
// ── Blockquote ──
|
|
md = md.replace(/<blockquote[^>]*>([\s\S]*?)<\/blockquote>/gi, "> $1\n\n");
|
|
// Limpiar <br> dentro de blockquote en markdown
|
|
md = md.replace(/(^>.*)\n>$/gm, "$1");
|
|
|
|
// ── Tablas ──
|
|
md = md.replace(/<table[^>]*>([\s\S]*?)<\/table>/gi, (_, tablaHTML) => {
|
|
return tablaHTMLAMarkdown(tablaHTML);
|
|
});
|
|
|
|
// ── Código inline ──
|
|
md = md.replace(/<code[^>]*>([\s\S]*?)<\/code>/gi, "`$1`");
|
|
|
|
// ── Línea horizontal ──
|
|
md = md.replace(/<hr[^>]*>/gi, "\n---\n");
|
|
|
|
// ── Entity decoding ──
|
|
md = md.replace(/ /g, " ");
|
|
md = md.replace(/&/g, "&");
|
|
md = md.replace(/</g, "<");
|
|
md = md.replace(/>/g, ">");
|
|
md = md.replace(/"/g, '"');
|
|
md = md.replace(/'/g, "'");
|
|
md = md.replace(/á/g, "á");
|
|
md = md.replace(/é/g, "é");
|
|
md = md.replace(/í/g, "í");
|
|
md = md.replace(/ó/g, "ó");
|
|
md = md.replace(/ú/g, "ú");
|
|
md = md.replace(/ñ/g, "ñ");
|
|
md = md.replace(/Á/g, "Á");
|
|
md = md.replace(/É/g, "É");
|
|
md = md.replace(/Í/g, "Í");
|
|
md = md.replace(/Ó/g, "Ó");
|
|
md = md.replace(/Ú/g, "Ú");
|
|
md = md.replace(/Ñ/g, "Ñ");
|
|
md = md.replace(/ü/g, "ü");
|
|
md = md.replace(/Ü/g, "Ü");
|
|
|
|
// ── Eliminar etiquetas HTML residuales ──
|
|
md = md.replace(/<[^>]*>/g, "");
|
|
|
|
// ── Normalizar espacios y líneas ──
|
|
md = md.replace(/\n{4,}/g, "\n\n\n");
|
|
md = md.replace(/[ \t]+\n/g, "\n");
|
|
|
|
// Limpiar espacios al inicio/fin de cada línea
|
|
md = md
|
|
.split("\n")
|
|
.map((l) => l.trim())
|
|
.join("\n");
|
|
|
|
return md.trim();
|
|
}
|
|
|
|
/**
|
|
* Convierte el HTML interno de una tabla (<thead>/<tbody>/<tr>/<td>/<th>)
|
|
* a formato Markdown de tabla.
|
|
*/
|
|
function tablaHTMLAMarkdown(tablaHTML) {
|
|
const filas = [];
|
|
const rowRegex = /<tr[^>]*>([\s\S]*?)<\/tr>/gi;
|
|
let match;
|
|
let esEncabezado = true;
|
|
|
|
while ((match = rowRegex.exec(tablaHTML)) !== null) {
|
|
const celdas = [];
|
|
const cellRegex = /<t[dh][^>]*>([\s\S]*?)<\/t[dh]>/gi;
|
|
let cellMatch;
|
|
|
|
while ((cellMatch = cellRegex.exec(match[1])) !== null) {
|
|
let contenido = cellMatch[1]
|
|
.replace(/<br\s*\/?>/gi, " ")
|
|
.replace(/<[^>]+>/g, "")
|
|
.replace(/ /g, " ")
|
|
.replace(/\s+/g, " ")
|
|
.trim();
|
|
celdas.push(contenido);
|
|
}
|
|
|
|
if (celdas.length > 0) {
|
|
filas.push({ celdas, esEncabezado });
|
|
esEncabezado = false;
|
|
}
|
|
}
|
|
|
|
if (filas.length === 0) return "";
|
|
|
|
let md = "\n";
|
|
const numCols = Math.max(...filas.map((f) => f.celdas.length));
|
|
|
|
// Usar la primera fila como encabezado (o la marcada como th)
|
|
const header = filas[0];
|
|
// Rellenar si faltan columnas
|
|
while (header.celdas.length < numCols) header.celdas.push("");
|
|
md += "| " + header.celdas.join(" | ") + " |\n";
|
|
md += "| " + header.celdas.map(() => "---").join(" | ") + " |\n";
|
|
|
|
// Las filas restantes son datos
|
|
for (let i = 1; i < filas.length; i++) {
|
|
const fila = filas[i];
|
|
while (fila.celdas.length < numCols) fila.celdas.push("");
|
|
md += "| " + fila.celdas.join(" | ") + " |\n";
|
|
}
|
|
|
|
md += "\n";
|
|
return md;
|
|
}
|
|
|
|
/**
|
|
* Limpia texto HTML simple (sin estructura) para obtener solo el texto plano.
|
|
*/
|
|
function limpiarHTML(html) {
|
|
return html
|
|
.replace(/<[^>]*>/g, "")
|
|
.replace(/ /g, " ")
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, "'")
|
|
.replace(/\s+/g, " ")
|
|
.trim();
|
|
}
|
|
|
|
// ============================================================
|
|
// GENERACIÓN DE CONTENIDO ESTRUCTURADO
|
|
// ============================================================
|
|
|
|
/**
|
|
* Recorre todos los módulos y secciones, extrae los temas y los organiza.
|
|
*/
|
|
function generarContenido() {
|
|
const libros = [];
|
|
|
|
for (const modulo of MODULOS) {
|
|
const seccionesConContenido = [];
|
|
|
|
for (const seccion of modulo.secciones) {
|
|
const htmlPath = path.join(
|
|
SECCIONES_DIR,
|
|
modulo.carpeta,
|
|
seccion.carpeta,
|
|
"pagina.html",
|
|
);
|
|
const temas = extraerTemas(htmlPath);
|
|
|
|
if (temas.length > 0) {
|
|
seccionesConContenido.push({
|
|
titulo: seccion.titulo,
|
|
carpeta: seccion.carpeta,
|
|
temas,
|
|
});
|
|
}
|
|
}
|
|
|
|
if (seccionesConContenido.length > 0) {
|
|
libros.push({
|
|
titulo: modulo.titulo,
|
|
carpeta: modulo.carpeta,
|
|
secciones: seccionesConContenido,
|
|
});
|
|
}
|
|
}
|
|
|
|
return libros;
|
|
}
|
|
|
|
// ============================================================
|
|
// GENERACIÓN DE MARKDOWN (.md)
|
|
// ============================================================
|
|
|
|
function generarMarkdown(datos) {
|
|
const ahora = new Date();
|
|
const fecha = ahora.toLocaleDateString("es-AR", {
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
});
|
|
|
|
let totalTemas = 0;
|
|
let md = `# Curso de Entrenador Nacional de Vóley
|
|
## Material de Estudio
|
|
|
|
*Generado el ${fecha}*
|
|
*Contenido extraído del curso online — Versión offline para estudio*
|
|
|
|
---
|
|
|
|
`;
|
|
|
|
for (const modulo of datos) {
|
|
md += `# ${modulo.titulo}\n\n`;
|
|
|
|
for (const seccion of modulo.secciones) {
|
|
md += `## ${seccion.titulo}\n\n`;
|
|
|
|
for (let t = 0; t < seccion.temas.length; t++) {
|
|
const tema = seccion.temas[t];
|
|
totalTemas++;
|
|
|
|
// Número de tema + título
|
|
md += `### ${t + 1}. ${tema.titulo}\n\n`;
|
|
|
|
// Nota de video
|
|
if (tema.vimeoID) {
|
|
md += `📹 *Video disponible — ID: ${tema.vimeoID}*\n\n`;
|
|
}
|
|
|
|
// Contenido de estudio
|
|
if (tema.contenidoHTML) {
|
|
md += htmlAMarkdown(tema.contenidoHTML);
|
|
md += "\n\n";
|
|
}
|
|
|
|
// Recurso descargable
|
|
if (tema.recursoURL) {
|
|
const tipoIcono = tema.recursoTexto === "Abrir Archivo" ? "📄" : "🔗";
|
|
md += `${tipoIcono} **${tema.recursoTexto}:** [${tema.titulo}](${tema.recursoURL})\n\n`;
|
|
}
|
|
|
|
// Separador entre temas
|
|
if (t < seccion.temas.length - 1) {
|
|
md += "---\n\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
md += `\n---\n*Fin del material de estudio. ${totalTemas} temas extraídos.*\n`;
|
|
|
|
return md;
|
|
}
|
|
|
|
// ============================================================
|
|
// GENERACIÓN DE HTML (.html)
|
|
// ============================================================
|
|
|
|
function generarHTML(datos) {
|
|
const ahora = new Date();
|
|
const fecha = ahora.toLocaleDateString("es-AR", {
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
});
|
|
|
|
let totalModulos = datos.length;
|
|
let totalSecciones = 0;
|
|
let totalTemas = 0;
|
|
let totalVideos = 0, videosDescargados = 0;
|
|
let totalRecursos = 0, recursosDescargados = 0;
|
|
let totalContenidos = 0, contenidosDescargados = 0;
|
|
|
|
// Leer mapa de videos descargados si existe
|
|
const mapaVideosPath = path.join(__dirname, ".mapa_videos.json");
|
|
let videosMap = {};
|
|
try {
|
|
if (fs.existsSync(mapaVideosPath)) {
|
|
videosMap = JSON.parse(fs.readFileSync(mapaVideosPath, "utf-8"));
|
|
}
|
|
} catch { /* sin mapa */ }
|
|
|
|
for (const m of datos) {
|
|
totalSecciones += m.secciones.length;
|
|
for (const s of m.secciones) {
|
|
totalTemas += s.temas.length;
|
|
for (const t of s.temas) {
|
|
if (t.vimeoID) {
|
|
totalVideos++;
|
|
if (videosMap[t.vimeoID]) videosDescargados++;
|
|
}
|
|
if (t.recursoURL) {
|
|
totalRecursos++;
|
|
if (t.recursoID) {
|
|
const secDir = path.join(__dirname, "descargas", "secciones", m.carpeta, s.carpeta);
|
|
let downloaded = false;
|
|
if (fs.existsSync(secDir)) {
|
|
const archivos = fs.readdirSync(secDir).filter(f => f.startsWith(`recurso_${t.recursoID}.`) || f.startsWith(`archivo_${t.recursoID}_`));
|
|
if (archivos.length > 0) downloaded = true;
|
|
}
|
|
if (downloaded) recursosDescargados++;
|
|
}
|
|
}
|
|
if (t.contenidoHTML) {
|
|
totalContenidos++;
|
|
contenidosDescargados++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const totalItems = totalVideos + totalRecursos + totalContenidos;
|
|
const itemsDescargados = videosDescargados + recursosDescargados + contenidosDescargados;
|
|
const globalPct = totalItems > 0 ? Math.round((itemsDescargados / totalItems) * 100) : 0;
|
|
|
|
const css = `
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
|
|
|
|
:root {
|
|
--sidebar-w: 280px;
|
|
--color-bg: #f5f3ef;
|
|
--color-surface: #ffffff;
|
|
--color-primary: #1a5276;
|
|
--color-primary-dark: #0d2b3e;
|
|
--color-accent: #2980b9;
|
|
--color-text: #2c2c2c;
|
|
--color-text-muted: #6b7280;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
|
|
background: var(--color-bg);
|
|
color: var(--color-text);
|
|
line-height: 1.8;
|
|
font-size: 16px;
|
|
}
|
|
|
|
/* ── LAYOUT ── */
|
|
.app-layout {
|
|
display: flex;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
/* ── SIDEBAR ── */
|
|
.sidebar {
|
|
width: var(--sidebar-w);
|
|
background: var(--color-primary-dark);
|
|
color: rgba(255,255,255,0.85);
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
bottom: 0;
|
|
overflow-y: auto;
|
|
z-index: 100;
|
|
display: flex;
|
|
flex-direction: column;
|
|
transition: transform 0.3s ease;
|
|
}
|
|
|
|
.sidebar-header {
|
|
padding: 1.5rem 1.2rem 1rem;
|
|
border-bottom: 1px solid rgba(255,255,255,0.08);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.sidebar-header .logo {
|
|
font-size: 1.8rem;
|
|
margin-bottom: 0.3rem;
|
|
}
|
|
|
|
.sidebar-header h1 {
|
|
font-size: 0.95rem;
|
|
font-weight: 700;
|
|
line-height: 1.3;
|
|
margin-bottom: 0.2rem;
|
|
}
|
|
|
|
.sidebar-header p {
|
|
font-size: 0.72rem;
|
|
opacity: 0.5;
|
|
font-weight: 400;
|
|
}
|
|
|
|
.sidebar-stats {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
padding: 0.8rem 1.2rem;
|
|
border-bottom: 1px solid rgba(255,255,255,0.08);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.sidebar-stats .stat {
|
|
background: rgba(255,255,255,0.08);
|
|
padding: 0.3rem 0.6rem;
|
|
border-radius: 6px;
|
|
font-size: 0.7rem;
|
|
font-weight: 500;
|
|
flex: 1;
|
|
text-align: center;
|
|
}
|
|
|
|
.sidebar-nav {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 0.8rem 0;
|
|
}
|
|
|
|
.sidebar-nav .nav-modulo {
|
|
padding: 0.6rem 1.2rem 0.3rem;
|
|
font-size: 0.68rem;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
color: rgba(255,255,255,0.4);
|
|
}
|
|
|
|
.sidebar-nav a {
|
|
display: block;
|
|
padding: 0.45rem 1.2rem 0.45rem 1.6rem;
|
|
color: rgba(255,255,255,0.7);
|
|
text-decoration: none;
|
|
font-size: 0.82rem;
|
|
font-weight: 400;
|
|
transition: all 0.2s;
|
|
border-left: 3px solid transparent;
|
|
}
|
|
|
|
.sidebar-nav a:hover {
|
|
background: rgba(255,255,255,0.06);
|
|
color: white;
|
|
border-left-color: var(--color-accent);
|
|
}
|
|
|
|
.sidebar-nav a.active {
|
|
background: rgba(41,128,185,0.15);
|
|
color: white;
|
|
border-left-color: var(--color-accent);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.sidebar-nav .nav-count {
|
|
font-size: 0.65rem;
|
|
opacity: 0.4;
|
|
margin-left: 0.3rem;
|
|
}
|
|
|
|
/* ── HAMBURGER ── */
|
|
.hamburger {
|
|
display: none;
|
|
position: fixed;
|
|
top: 1rem;
|
|
left: 1rem;
|
|
z-index: 200;
|
|
background: var(--color-primary-dark);
|
|
border: none;
|
|
color: white;
|
|
width: 44px;
|
|
height: 44px;
|
|
border-radius: 10px;
|
|
font-size: 1.4rem;
|
|
cursor: pointer;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
|
transition: transform 0.2s;
|
|
}
|
|
|
|
.hamburger:hover { transform: scale(1.05); }
|
|
|
|
.sidebar-overlay {
|
|
display: none;
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0,0,0,0.4);
|
|
z-index: 99;
|
|
}
|
|
|
|
/* ── MAIN CONTENT ── */
|
|
.main-content {
|
|
flex: 1;
|
|
margin-left: var(--sidebar-w);
|
|
min-width: 0;
|
|
}
|
|
|
|
/* ── PORTADA ── */
|
|
.portada {
|
|
background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 50%, var(--color-accent) 100%);
|
|
color: white;
|
|
padding: 4rem 2rem;
|
|
text-align: center;
|
|
min-height: 50vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
align-items: center;
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.portada::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: -50%; left: -50%;
|
|
width: 200%; height: 200%;
|
|
background: radial-gradient(circle at 30% 70%, rgba(255,255,255,0.05) 0%, transparent 50%);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.portada .icono-grande { font-size: 4rem; margin-bottom: 1rem; opacity: 0.3; }
|
|
.portada h1 { font-size: 2.4rem; margin-bottom: 0.5rem; font-weight: 800; letter-spacing: -1px; }
|
|
.portada h2 { font-size: 1.15rem; font-weight: 300; opacity: 0.8; margin-bottom: 1rem; }
|
|
.portada p { opacity: 0.6; font-size: 0.9rem; }
|
|
|
|
/* ── CONTENIDO ── */
|
|
.contenido {
|
|
max-width: 820px;
|
|
margin: 0 auto;
|
|
padding: 2.5rem;
|
|
background: var(--color-surface);
|
|
min-height: 60vh;
|
|
}
|
|
|
|
.contenido h1.modulo-titulo {
|
|
color: var(--color-primary-dark);
|
|
font-size: 1.8rem;
|
|
font-weight: 800;
|
|
border-bottom: 3px solid var(--color-accent);
|
|
padding-bottom: 0.5rem;
|
|
margin: 3rem 0 1.5rem;
|
|
letter-spacing: -0.5px;
|
|
}
|
|
|
|
.contenido h2.seccion-titulo {
|
|
color: var(--color-primary);
|
|
font-size: 1.35rem;
|
|
font-weight: 700;
|
|
margin: 2.5rem 0 1rem;
|
|
border-left: 4px solid var(--color-accent);
|
|
padding-left: 0.8rem;
|
|
scroll-margin-top: 1rem;
|
|
}
|
|
|
|
.contenido h3.tema-titulo {
|
|
color: #2c3e50;
|
|
font-size: 1.1rem;
|
|
margin: 1.8rem 0 0.8rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.contenido h4 {
|
|
color: #34495e;
|
|
font-size: 1rem;
|
|
margin: 1.3rem 0 0.6rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.contenido p { margin: 0.8rem 0; text-align: justify; }
|
|
.contenido ul, .contenido ol { margin: 0.8rem 0; padding-left: 1.8rem; }
|
|
.contenido li { margin: 0.4rem 0; }
|
|
.contenido strong { color: #1a3a4a; font-weight: 600; }
|
|
|
|
.contenido hr {
|
|
border: none;
|
|
border-top: 1px solid #e8e4df;
|
|
margin: 1.8rem 0;
|
|
}
|
|
|
|
.contenido table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin: 1.2rem 0;
|
|
font-size: 0.88rem;
|
|
overflow-x: auto;
|
|
display: block;
|
|
}
|
|
|
|
.contenido th, .contenido td {
|
|
border: 1px solid #ddd;
|
|
padding: 0.6rem 0.8rem;
|
|
text-align: left;
|
|
vertical-align: top;
|
|
}
|
|
|
|
.contenido th {
|
|
background: var(--color-primary-dark);
|
|
color: white;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.contenido tr:nth-child(even) { background: #f8f6f3; }
|
|
.contenido tr:hover { background: #efece7; }
|
|
|
|
.contenido blockquote {
|
|
border-left: 4px solid var(--color-accent);
|
|
margin: 1rem 0;
|
|
padding: 0.8rem 1.2rem;
|
|
background: #f0f5fa;
|
|
color: #2c3e50;
|
|
border-radius: 0 4px 4px 0;
|
|
}
|
|
|
|
/* ── VIDEO PLAYER ── */
|
|
.video-viewer-wrap {
|
|
margin: 1rem 0;
|
|
border: 1px solid #2c3e50;
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
background: #1a1a2e;
|
|
}
|
|
.video-viewer-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 0.7rem 1rem;
|
|
background: linear-gradient(135deg, #1a1a2e, #16213e);
|
|
color: #eee;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
font-size: 0.9rem;
|
|
transition: background 0.2s;
|
|
}
|
|
.video-viewer-header:hover {
|
|
background: linear-gradient(135deg, #16213e, #0f3460);
|
|
}
|
|
.video-toggle {
|
|
transition: transform 0.3s;
|
|
font-size: 0.8rem;
|
|
opacity: 0.6;
|
|
color: #aaa;
|
|
}
|
|
.video-viewer-wrap.collapsed .video-toggle {
|
|
transform: rotate(-90deg);
|
|
}
|
|
.video-viewer-wrap.collapsed .video-container,
|
|
.video-viewer-wrap.collapsed .video-placeholder {
|
|
display: none;
|
|
}
|
|
.video-container {
|
|
border-radius: 0;
|
|
overflow: hidden;
|
|
background: #000;
|
|
}
|
|
.video-container video {
|
|
width: 100%;
|
|
display: block;
|
|
}
|
|
|
|
/* ── NOTAS ESPECIALES ── */
|
|
.nota-video {
|
|
background: #fef9e7;
|
|
border: 1px solid #f9e79f;
|
|
border-left: 4px solid #f1c40f;
|
|
padding: 0.6rem 1rem;
|
|
margin: 0.8rem 0;
|
|
border-radius: 0 4px 4px 0;
|
|
font-size: 0.88rem;
|
|
color: #7d6608;
|
|
}
|
|
.video-placeholder {
|
|
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
|
border-radius: 8px;
|
|
padding: 2rem;
|
|
margin: 1rem 0;
|
|
text-align: center;
|
|
color: #e0e0e0;
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
.video-placeholder::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0; left: -100%; width: 200%; height: 100%;
|
|
background: linear-gradient(90deg, transparent 25%, rgba(255,255,255,0.03) 50%, transparent 75%);
|
|
animation: shimmer 3s infinite;
|
|
}
|
|
@keyframes shimmer {
|
|
0% { transform: translateX(-50%); }
|
|
100% { transform: translateX(50%); }
|
|
}
|
|
.video-placeholder .play-icon {
|
|
font-size: 2.5rem;
|
|
margin-bottom: 0.5rem;
|
|
opacity: 0.5;
|
|
}
|
|
.video-placeholder .placeholder-text {
|
|
font-size: 0.85rem;
|
|
opacity: 0.6;
|
|
}
|
|
.video-placeholder .placeholder-label {
|
|
font-size: 0.75rem;
|
|
opacity: 0.35;
|
|
margin-top: 0.4rem;
|
|
}
|
|
/* ── BARRA DE PROGRESO ── */
|
|
.progress-section {
|
|
padding: 0.8rem 1.2rem;
|
|
border-top: 1px solid rgba(255,255,255,0.08);
|
|
}
|
|
.progress-section .progress-label {
|
|
font-size: 0.7rem;
|
|
color: rgba(255,255,255,0.5);
|
|
margin-bottom: 0.4rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
}
|
|
.progress-bar-bg {
|
|
background: rgba(255,255,255,0.1);
|
|
border-radius: 6px;
|
|
height: 8px;
|
|
overflow: hidden;
|
|
}
|
|
.progress-bar-fill {
|
|
height: 100%;
|
|
border-radius: 6px;
|
|
background: linear-gradient(90deg, #2980b9, #27ae60);
|
|
transition: width 0.5s ease;
|
|
}
|
|
.progress-stats {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
font-size: 0.7rem;
|
|
color: rgba(255,255,255,0.4);
|
|
margin-top: 0.3rem;
|
|
}
|
|
.nota-recurso {
|
|
background: #eaf2f8;
|
|
border: 1px solid #aed6f1;
|
|
border-left: 4px solid var(--color-accent);
|
|
padding: 0.6rem 1rem;
|
|
margin: 0.8rem 0;
|
|
border-radius: 0 4px 4px 0;
|
|
font-size: 0.88rem;
|
|
}
|
|
.nota-recurso a {
|
|
color: var(--color-primary);
|
|
font-weight: 600;
|
|
}
|
|
.pdf-viewer-wrap {
|
|
margin: 1rem 0;
|
|
border: 1px solid #d5e8f0;
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
background: #f8fbfd;
|
|
}
|
|
.pdf-viewer-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 0.7rem 1rem;
|
|
background: linear-gradient(135deg, #eaf2f8, #d4e6f1);
|
|
cursor: pointer;
|
|
user-select: none;
|
|
font-size: 0.9rem;
|
|
transition: background 0.2s;
|
|
}
|
|
.pdf-viewer-header:hover {
|
|
background: linear-gradient(135deg, #d4e6f1, #aed6f1);
|
|
}
|
|
.pdf-toggle {
|
|
transition: transform 0.3s;
|
|
font-size: 0.8rem;
|
|
opacity: 0.6;
|
|
}
|
|
.pdf-viewer-wrap.collapsed .pdf-toggle {
|
|
transform: rotate(-90deg);
|
|
}
|
|
.pdf-viewer {
|
|
width: 100%;
|
|
height: 70vh;
|
|
border: none;
|
|
display: block;
|
|
}
|
|
.pdf-viewer-wrap.collapsed .pdf-viewer,
|
|
.pdf-viewer-wrap.collapsed .pdf-download-link {
|
|
display: none;
|
|
}
|
|
.pdf-download-link {
|
|
display: block;
|
|
text-align: center;
|
|
padding: 0.5rem;
|
|
font-size: 0.82rem;
|
|
color: var(--color-primary);
|
|
text-decoration: none;
|
|
background: #eaf2f8;
|
|
border-top: 1px solid #d5e8f0;
|
|
}
|
|
.pdf-download-link:hover {
|
|
background: #d4e6f1;
|
|
}
|
|
.nota-vacio {
|
|
color: var(--color-text-muted);
|
|
font-style: italic;
|
|
font-size: 0.88rem;
|
|
margin: 0.5rem 0;
|
|
}
|
|
.contenido .tema-separador {
|
|
margin: 2rem 0;
|
|
border-top: 1px dashed #ddd;
|
|
}
|
|
|
|
/* ── PIE DE PÁGINA ── */
|
|
.footer {
|
|
text-align: center;
|
|
padding: 2rem;
|
|
color: var(--color-text-muted);
|
|
font-size: 0.8rem;
|
|
max-width: 820px;
|
|
margin: 0 auto;
|
|
border-top: 1px solid #e8e4df;
|
|
background: var(--color-surface);
|
|
}
|
|
|
|
/* ── RESPONSIVE ── */
|
|
@media (max-width: 900px) {
|
|
.sidebar { transform: translateX(-100%); }
|
|
.sidebar.open { transform: translateX(0); }
|
|
.sidebar-overlay.open { display: block; }
|
|
.hamburger { display: block; }
|
|
.main-content { margin-left: 0; }
|
|
.portada { padding: 3rem 1rem 2rem; min-height: 40vh; }
|
|
.portada h1 { font-size: 1.6rem; }
|
|
.portada h2 { font-size: 0.95rem; }
|
|
.contenido { padding: 1.5rem 1rem; }
|
|
}
|
|
`;
|
|
|
|
// ─── SIDEBAR NAV ───
|
|
let sidebarNav = "";
|
|
for (const modulo of datos) {
|
|
sidebarNav += `<div class="nav-modulo">${modulo.titulo.replace(/Módulo \d+ — /i, "")}</div>\n`;
|
|
for (const seccion of modulo.secciones) {
|
|
const secID = `sec-${slugify(seccion.titulo)}`;
|
|
sidebarNav += `<a href="#${secID}" data-section="${secID}">${seccion.titulo}<span class="nav-count">${seccion.temas.length}</span></a>\n`;
|
|
}
|
|
}
|
|
|
|
// ─── CONTENIDO ───
|
|
let bodyHTML = "";
|
|
for (const modulo of datos) {
|
|
bodyHTML += `<h1 class="modulo-titulo">${modulo.titulo}</h1>\n`;
|
|
|
|
for (const seccion of modulo.secciones) {
|
|
const secID = `sec-${slugify(seccion.titulo)}`;
|
|
bodyHTML += `<h2 class="seccion-titulo" id="${secID}">${seccion.titulo}</h2>\n`;
|
|
|
|
for (let t = 0; t < seccion.temas.length; t++) {
|
|
const tema = seccion.temas[t];
|
|
const temaID = `tema-${slugify(tema.titulo)}-${t}`;
|
|
|
|
bodyHTML += `<h3 class="tema-titulo" id="${temaID}">${t + 1}. ${tema.titulo}</h3>\n`;
|
|
|
|
// Video — local player o referencia
|
|
if (tema.vimeoID) {
|
|
const videoFile = videosMap[tema.vimeoID];
|
|
if (videoFile) {
|
|
bodyHTML += `<div class="video-viewer-wrap collapsed">
|
|
<div class="video-viewer-header" onclick="this.parentElement.classList.toggle('collapsed')">
|
|
<span>🎬 <strong>${tema.titulo}</strong></span>
|
|
<span class="video-toggle">▼</span>
|
|
</div>
|
|
<div class="video-container"><video controls preload="metadata"><source src="videos_offline/${videoFile}" type="video/mp4">Tu navegador no soporta video HTML5.</video></div>
|
|
</div>\n`;
|
|
} else {
|
|
bodyHTML += `<div class="video-viewer-wrap collapsed">
|
|
<div class="video-viewer-header" onclick="this.parentElement.classList.toggle('collapsed')">
|
|
<span>🎬 <strong>${tema.titulo}</strong> <em style="opacity:0.5;font-size:0.8em">(descargando...)</em></span>
|
|
<span class="video-toggle">▼</span>
|
|
</div>
|
|
<div class="video-placeholder"><div class="play-icon">▶</div><div class="placeholder-text">Video en proceso de descarga</div></div>
|
|
</div>\n`;
|
|
}
|
|
}
|
|
|
|
// Contenido de estudio
|
|
if (tema.contenidoHTML) {
|
|
bodyHTML += contenidoEstudioAHTML(tema.contenidoHTML);
|
|
} else if (!tema.vimeoID && !tema.recursoURL) {
|
|
bodyHTML += `<p class="nota-vacio">Sin contenido de estudio adicional.</p>\n`;
|
|
}
|
|
|
|
// Recurso descargable o enlace
|
|
if (tema.recursoURL) {
|
|
// Buscar archivo local descargado
|
|
let recursoHref = tema.recursoURL;
|
|
let recursoLocal = null;
|
|
if (tema.recursoID) {
|
|
const secDir = path.join(__dirname, "descargas", "secciones", modulo.carpeta, seccion.carpeta);
|
|
const archivos = fs.existsSync(secDir) ? fs.readdirSync(secDir).filter(f => f.startsWith(`recurso_${tema.recursoID}.`)) : [];
|
|
if (archivos.length > 0) {
|
|
recursoLocal = archivos[0];
|
|
recursoHref = `secciones/${modulo.carpeta}/${seccion.carpeta}/${recursoLocal}`;
|
|
}
|
|
}
|
|
|
|
if (recursoLocal && recursoLocal.endsWith(".pdf")) {
|
|
// PDF inline con visor embebido
|
|
const pdfId = `pdf-${tema.id}-${tema.recursoID}`;
|
|
bodyHTML += `<div class="pdf-viewer-wrap collapsed">
|
|
<div class="pdf-viewer-header" onclick="this.parentElement.classList.toggle('collapsed')">
|
|
<span>📄 <strong>${tema.titulo}</strong></span>
|
|
<span class="pdf-toggle">▼</span>
|
|
</div>
|
|
<iframe class="pdf-viewer" src="${recursoHref}" id="${pdfId}"></iframe>
|
|
<a href="${recursoHref}" download class="pdf-download-link">⬇ Descargar PDF</a>
|
|
</div>\n`;
|
|
} else if (recursoLocal) {
|
|
// Otros archivos locales (ZIP, PPT, XLS, MP4, etc)
|
|
const isVideo = recursoLocal.endsWith(".mp4");
|
|
const icono = isVideo ? "🎬" : "📦";
|
|
const etiqueta = isVideo ? "Ver Video" : "Descargar";
|
|
bodyHTML += `<div class="nota-recurso">${icono} <strong>${etiqueta}:</strong> <a href="${recursoHref}" ${isVideo ? 'target="_blank"' : 'download'}>${tema.titulo}</a></div>\n`;
|
|
} else {
|
|
// Faltante / no descargado
|
|
bodyHTML += `<div class="nota-recurso missing-resource" style="opacity: 0.7; background: #fdf2e9; border-left-color: #e67e22;">
|
|
⏳ <strong>Recurso pendiente:</strong> <span style="text-decoration: line-through;">${tema.titulo}</span> <em style="font-size:0.85em">(en proceso de descarga...)</em>
|
|
</div>\n`;
|
|
}
|
|
}
|
|
|
|
// Separador entre temas
|
|
if (t < seccion.temas.length - 1) {
|
|
bodyHTML += `<div class="tema-separador"></div>\n`;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const jsCode = `
|
|
// Hamburger menu
|
|
const hamburger = document.getElementById('hamburger');
|
|
const sidebar = document.getElementById('sidebar');
|
|
const overlay = document.getElementById('sidebar-overlay');
|
|
|
|
hamburger.addEventListener('click', () => {
|
|
sidebar.classList.toggle('open');
|
|
overlay.classList.toggle('open');
|
|
});
|
|
|
|
overlay.addEventListener('click', () => {
|
|
sidebar.classList.remove('open');
|
|
overlay.classList.remove('open');
|
|
});
|
|
|
|
// Close sidebar on nav click (mobile)
|
|
sidebar.querySelectorAll('a').forEach(link => {
|
|
link.addEventListener('click', () => {
|
|
if (window.innerWidth <= 900) {
|
|
sidebar.classList.remove('open');
|
|
overlay.classList.remove('open');
|
|
}
|
|
});
|
|
});
|
|
|
|
// Highlight active section on scroll
|
|
const sections = document.querySelectorAll('.seccion-titulo');
|
|
const navLinks = document.querySelectorAll('.sidebar-nav a[data-section]');
|
|
|
|
const observer = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
navLinks.forEach(link => link.classList.remove('active'));
|
|
const id = entry.target.id;
|
|
const activeLink = document.querySelector('.sidebar-nav a[data-section="' + id + '"]');
|
|
if (activeLink) {
|
|
activeLink.classList.add('active');
|
|
activeLink.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
}
|
|
}
|
|
});
|
|
}, { rootMargin: '-10% 0px -80% 0px' });
|
|
|
|
sections.forEach(section => observer.observe(section));
|
|
`;
|
|
|
|
return `<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Curso de Vóley — Material de Estudio</title>
|
|
<meta name="description" content="Material de estudio offline del Curso de Entrenador Nacional de Vóley">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
|
|
<style>${css}</style>
|
|
</head>
|
|
<body>
|
|
|
|
<button class="hamburger" id="hamburger" aria-label="Menú">☰</button>
|
|
<div class="sidebar-overlay" id="sidebar-overlay"></div>
|
|
|
|
<div class="app-layout">
|
|
<nav class="sidebar" id="sidebar">
|
|
<div class="sidebar-header">
|
|
<div class="logo">🏐</div>
|
|
<h1>Entrenador Nacional de Vóley</h1>
|
|
<p>Material de Estudio</p>
|
|
</div>
|
|
|
|
<div class="sidebar-nav">
|
|
${sidebarNav}
|
|
</div>
|
|
<div class="progress-section">
|
|
<div class="progress-label">Progreso de Descargas (Videos, Textos y Recursos)</div>
|
|
<div class="progress-bar-bg"><div class="progress-bar-fill" style="width: ${globalPct}%"></div></div>
|
|
<div class="progress-stats"><span>${itemsDescargados} de ${totalItems} ítems</span><span>${globalPct}%</span></div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="main-content">
|
|
<div class="portada">
|
|
<div class="icono-grande">🏐</div>
|
|
<h1>Curso de Entrenador Nacional de Vóley</h1>
|
|
<h2>Material de Estudio — Versión Offline</h2>
|
|
<p>Contenido extraído del campus virtual</p>
|
|
<p style="margin-top: 1.5rem; opacity: 0.4; font-size: 0.75rem;">Generado el ${fecha}</p>
|
|
</div>
|
|
|
|
<div class="contenido">
|
|
${bodyHTML}
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>Online Education Center — Material de estudio offline</p>
|
|
<p style="margin-top: 0.3rem; font-size: 0.75rem;">Generado el ${fecha}</p>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<script>${jsCode}</script>
|
|
</body>
|
|
</html>`;
|
|
}
|
|
|
|
/**
|
|
* Convierte el HTML de contenido de estudio (redactor-usr-input) a HTML limpio
|
|
* manteniendo la estructura semántica (títulos, párrafos, listas, tablas, citas).
|
|
*/
|
|
function contenidoEstudioAHTML(html) {
|
|
if (!html) return "";
|
|
|
|
let out = html;
|
|
|
|
// Procesar títulos
|
|
out = out.replace(/<h1[^>]*>([\s\S]*?)<\/h1>/gi, "<h4>$1</h4>");
|
|
out = out.replace(/<h2[^>]*>([\s\S]*?)<\/h2>/gi, "<h4>$1</h4>");
|
|
out = out.replace(/<h3[^>]*>([\s\S]*?)<\/h3>/gi, "<h4>$1</h4>");
|
|
|
|
// Eliminar <br> que son solo espaciado estético (más de 2 seguidos)
|
|
out = out.replace(/(<br\s*\/?>\s*){3,}/gi, "<br><br>");
|
|
|
|
// Asegurar que las tablas tengan bordes visibles
|
|
out = out.replace(/<table/gi, '<table cellspacing="0"');
|
|
|
|
// Eliminar etiquetas vacías que no aportan contenido
|
|
out = out.replace(/<p>\s*<\/p>/gi, "");
|
|
out = out.replace(/<div>\s*<\/div>/gi, "");
|
|
|
|
return out;
|
|
}
|
|
|
|
/**
|
|
* Convierte un texto en un slug apto para usar como ID HTML.
|
|
*/
|
|
function slugify(texto) {
|
|
return texto
|
|
.toLowerCase()
|
|
.normalize("NFD")
|
|
.replace(/[\u0300-\u036f]/g, "") // eliminar tildes
|
|
.replace(/[^a-z0-9]+/gi, "-")
|
|
.replace(/-+/g, "-")
|
|
.replace(/^-|-$/g, "");
|
|
}
|
|
|
|
// ============================================================
|
|
// EJECUCIÓN PRINCIPAL
|
|
// ============================================================
|
|
|
|
console.log("🏐 Generando libro de estudio...");
|
|
console.log("");
|
|
|
|
const datos = generarContenido();
|
|
|
|
if (datos.length === 0) {
|
|
console.log(
|
|
"⚠ No se encontró contenido de estudio en las páginas descargadas.",
|
|
);
|
|
console.log(
|
|
" Asegurate de haber ejecutado primero: node download_course.mjs",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Resumen de lo extraído
|
|
for (const modulo of datos) {
|
|
console.log(` 📚 ${modulo.titulo}`);
|
|
for (const seccion of modulo.secciones) {
|
|
console.log(` 📂 ${seccion.titulo} (${seccion.temas.length} temas)`);
|
|
for (const tema of seccion.temas) {
|
|
const tieneContenido = tema.contenidoHTML ? "📝" : " ";
|
|
const tieneVideo = tema.vimeoID ? "📹" : " ";
|
|
const tieneRecurso = tema.recursoURL ? "📎" : " ";
|
|
console.log(
|
|
` ${tieneContenido}${tieneVideo}${tieneRecurso} ${tema.titulo}`,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
console.log("");
|
|
|
|
// Generar Markdown
|
|
console.log("📝 Generando LIBRO_DE_ESTUDIO.md...");
|
|
const md = generarMarkdown(datos);
|
|
const mdPath = path.join(DOWNLOADS_DIR, "LIBRO_DE_ESTUDIO.md");
|
|
fs.writeFileSync(mdPath, md, "utf-8");
|
|
console.log(` ✓ ${mdPath} (${(md.length / 1024).toFixed(0)} KB)`);
|
|
|
|
// Generar HTML
|
|
console.log("🎨 Generando LIBRO_DE_ESTUDIO.html...");
|
|
const html = generarHTML(datos);
|
|
const htmlPath = path.join(DOWNLOADS_DIR, "LIBRO_DE_ESTUDIO.html");
|
|
fs.writeFileSync(htmlPath, html, "utf-8");
|
|
console.log(` ✓ ${htmlPath} (${(html.length / 1024).toFixed(0)} KB)`);
|
|
|
|
// Estadísticas
|
|
let totalPalabras = 0;
|
|
let totalTemas = 0;
|
|
for (const m of datos) {
|
|
for (const s of m.secciones) {
|
|
for (const t of s.temas) {
|
|
if (t.contenidoHTML) {
|
|
totalPalabras += t.contenidoHTML
|
|
.replace(/<[^>]*>/g, "")
|
|
.split(/\s+/).length;
|
|
}
|
|
totalTemas++;
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log("");
|
|
console.log("📊 Estadísticas:");
|
|
console.log(` ${datos.length} módulos`);
|
|
console.log(` ${datos.reduce((s, m) => s + m.secciones.length, 0)} secciones`);
|
|
console.log(` ${totalTemas} temas de estudio`);
|
|
console.log(` ~${(totalPalabras / 1000).toFixed(1)}k palabras de contenido`);
|
|
console.log("");
|
|
console.log("📂 Archivos generados:");
|
|
console.log(` LIBRO_DE_ESTUDIO.md → Para leer en cualquier editor de texto`);
|
|
console.log(
|
|
` LIBRO_DE_ESTUDIO.html → Para leer en el navegador (recomendado)`,
|
|
);
|
|
console.log("");
|
|
console.log("✅ Listo. ¡A estudiar!");
|