Arreglando el santo del dia
This commit is contained in:
parent
acf7b9e458
commit
e4c630f2fa
|
|
@ -42,6 +42,7 @@ function inicializarVariables() {
|
|||
fechaHoyElem = document.getElementById('fecha-hoy');
|
||||
nombreCicloElem = document.getElementById('nombre_ciclo');
|
||||
cicloParImparElem = document.getElementById('ciclo_par_impar');
|
||||
santoDelDiaElem = document.getElementById('santo-del-dia');
|
||||
descripcionSantoDelDiaElem = document.getElementById('descripcion-santo-del-dia');
|
||||
indicadorLiturgicoElem = document.getElementById('indicador-liturgico');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,20 +137,20 @@ async function difuntos() {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/* ================================
|
||||
6. SANTO DEL DÍA
|
||||
================================ */
|
||||
|
||||
async function santoDelDia() {
|
||||
const hoy = new Date();
|
||||
const offset = hoy.getTimezoneOffset() * 60000;
|
||||
const fechaHoy = new Date(hoy - offset).toISOString().split('T')[0];
|
||||
|
||||
try {
|
||||
const res = await apiCall('/santo/hoy');
|
||||
if (!res || !res.ok) {
|
||||
if (santoDelDiaElem) santoDelDiaElem.textContent = "";
|
||||
if (descripcionSantoDelDiaElem) descripcionSantoDelDiaElem.textContent = "";
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
const data = res && res.ok ? await res.json() : await cargarSantoLocal(fechaHoy);
|
||||
|
||||
if (!data) return;
|
||||
console.log("Actualizando santo:", data.santo, santoDelDiaElem, descripcionSantoDelDiaElem);
|
||||
if (santoDelDiaElem) santoDelDiaElem.textContent = data.santo || "";
|
||||
if (descripcionSantoDelDiaElem) descripcionSantoDelDiaElem.textContent = data.descripcion || "";
|
||||
|
|
@ -158,7 +158,21 @@ async function santoDelDia() {
|
|||
console.log("try: Actualizando santo:", data.santo, santoDelDiaElem);
|
||||
} catch (e) {
|
||||
console.error("Error obteniendo el santo del día desde la API:", e);
|
||||
console.log("catch: No se pudo actualizar el santo del día, manteniendo el texto actual:", santoDelDiaElem ? santoDelDiaElem.textContent : "Elemento no encontrado");
|
||||
const data = await cargarSantoLocal(fechaHoy);
|
||||
if (data && santoDelDiaElem) santoDelDiaElem.textContent = data.santo || "";
|
||||
if (data && descripcionSantoDelDiaElem) descripcionSantoDelDiaElem.textContent = data.descripcion || "";
|
||||
}
|
||||
}
|
||||
|
||||
async function cargarSantoLocal(fecha) {
|
||||
try {
|
||||
const res = await fetch('data/santos.json');
|
||||
if (!res.ok) throw new Error('No se pudo cargar el santoral local');
|
||||
const santos = await res.json();
|
||||
return santos.find(santo => santo.fecha === fecha) || null;
|
||||
} catch (e) {
|
||||
console.error("Error cargando el santoral local:", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue