taiageweb/js/ver.js

38 lines
1.5 KiB
JavaScript

(function () {
const params = new URLSearchParams(window.location.search);
const f = params.get('f');
const tema = params.get('tema');
if (tema) {
document.getElementById('back-link').href = 'esquema.html?tema=' + tema;
}
if (!f) {
document.getElementById('loading').textContent = 'No se especificó ningún fichero.';
return;
}
fetch(f)
.then(function (r) {
if (!r.ok) throw new Error('HTTP ' + r.status);
return r.text();
})
.then(function (md) {
const nombre = f.split('/').pop().replace('.md', '');
document.getElementById('page-title').textContent = nombre;
document.title = nombre + ' · TAI';
const contenido = document.getElementById('contenido');
contenido.innerHTML = marked.parse(md);
})
.catch(function (err) {
document.getElementById('loading').innerHTML =
'<p style="color:#f85149;margin-bottom:12px">Error al cargar el fichero: ' + err.message + '</p>' +
'<p>Abre el visor desde un servidor local, no directamente con <code>file://</code>:</p>' +
'<pre style="margin-top:10px;background:#161b22;padding:12px 16px;border-radius:6px;border:1px solid #30363d">' +
'cd /home/tatvil/trabajo/oposiciones/taiage-apuntes\npython3 -m http.server 8000' +
'</pre>' +
'<p style="margin-top:10px">Luego abre: <a href="http://localhost:8000/esquema.html" style="color:#58a6ff">http://localhost:8000/esquema.html</a></p>';
});
}());