Files
rafa 6b61250b0b Sincronizar mu-plugins/ y scripts/ con el estado real del sitio (2026-07-16)
Este repo llevaba desde el 28-jun sin actualizarse (salvo sync_carta_from_prod.py).
Se pone al dia con 3 semanas de trabajo que solo vivian en el checkout local
completo del proyecto:

- Fix del buscador (issue #178): AND obligatorio en FULLTEXT (antes devolvia
  practicamente todo el sitio con cualquier busqueda), exclusion de paginas
  indice residuales de la migracion K2, soporte de frase exacta entre comillas.
- Nuevos mu-plugins ya desplegados a prod: fea-carta-id-api, fea-cloudflare-realip,
  fea-crear-autor-api, fea-gsc-verification, fea-legacy-redirect (cutover
  Joomla->WP, ver issue #162).
- TTS multi-voz por autor, scripts de traduccion, sync de audio a prod,
  homenajes Mardones/Galarreta.

Se mantiene la estructura plana del repo (mu-plugins/ + scripts/, sin el
wordpress/wp-content/ del checkout completo) tal y como documenta el README:
es la convencion establecida para este repo, mas limpia para quien solo
necesita leer el codigo. Anadido .gitignore (cache de Python que no debia
commitearse).

Fuente: checkout local completo del proyecto, rama main (commit 69e849d).
2026-07-15 20:26:43 -04:00

94 lines
4.4 KiB
Python

import re, json, html, glob
IMG_BASE = "/fea/wp-content/uploads/anterior-mardones/"
# filename -> (titulo, autor_wp, [imagenes])
ORAR_AUTHOR = 710 # Mardones
HOM_AUTHOR = 1 # genérico (como página 17990)
META = {
"orar-1-dejarmequerer":("Dejarme querer",ORAR_AUTHOR,[]),
"orar-2-escuchar":("Escuchar",ORAR_AUTHOR,[]),
"orar-3-estar":("Estar",ORAR_AUTHOR,[]),
"orar-4-hacersitioadios":("Hacer sitio a Dios",ORAR_AUTHOR,[]),
"orar-5-laoracionadulta":("La oración adulta",ORAR_AUTHOR,[]),
"orar-6-orarconevangelio":("Orar con el evangelio",ORAR_AUTHOR,[]),
"orar-7-orarrepitiendo":("Orar repitiendo una palabra o frase breve",ORAR_AUTHOR,[]),
"orar-8-tuestasdentro":("Tú estás dentro",ORAR_AUTHOR,[]),
"homenaje-segundo-aniversario":("En el segundo aniversario",HOM_AUTHOR,[]),
"homenaje-14noviembre":("14 de noviembre de 2007",HOM_AUTHOR,[]),
"homenaje-PRIMERaniversario":("Primer aniversario",HOM_AUTHOR,[]),
"homenaje-aniversario":("Programa en el aniversario",HOM_AUTHOR,["homenaje-charla-mejico.jpg"]),
"homenaje-rostrointerior":("Rostro interior de José María Mardones",HOM_AUTHOR,[]),
"homenaje-cartaReyes":("Carta a un Maestro",HOM_AUTHOR,[]),
"homenaje-9":("Semblanza",HOM_AUTHOR,[]),
"homenaje-8":("Álbum de fotos de José María Mardones",HOM_AUTHOR,
["homenaje-album-%d.jpg"%i for i in range(1,8)]),
"homenaje-1":("Funeral del sábado 24 de junio",HOM_AUTHOR,[]),
"homenaje-2":("Funeral del jueves 29 de junio",HOM_AUTHOR,[]),
"homenaje-5":("Obituario en El Mundo",HOM_AUTHOR,[]),
"homenaje-6":("Necrológicas en El País",HOM_AUTHOR,[]),
"homenaje-4":("Salmo a la Encarnación de Dios",HOM_AUTHOR,[]),
"homenaje-3":("Conferencia: ¿Por qué preocuparse por los demás? Ética y convivencia",HOM_AUTHOR,[]),
"homenaje-7":("Currículo de José María Mardones",HOM_AUTHOR,[]),
}
BOILER = re.compile(r'cristianos siglo veintiuno|^I N M E M O R I A M$|^HOMENAJE$|^homenaje a JOSE|APRENDIENDO A ORAR cristianos', re.I)
def extract(fn):
raw=open(fn,'rb').read().decode('windows-1252',errors='replace')
raw=re.sub(r'(?is)<(script|style).*?</\1>','',raw)
raw=re.sub(r'(?is)<!--.*?-->','',raw)
blocks=[]
for p in re.findall(r'(?is)<p\b[^>]*>(.*?)</p>',raw):
# preservar enlaces externos
links=re.findall(r'(?is)<a\s+[^>]*href="(https?://[^"]+)"[^>]*>(.*?)</a>',p)
t=re.sub(r'(?is)<[^>]+>','',p)
t=html.unescape(t).replace('\xa0',' ')
t=re.sub(r'\s+',' ',t).strip()
if len(t)<3:
# párrafo solo-enlace
if links:
for href,txt in links:
txt=re.sub(r'<[^>]+>','',txt).strip() or href
blocks.append(('link',href,txt))
continue
if BOILER.search(t):
continue
# ¿el párrafo contiene un enlace externo embebido? añadir como link extra
blocks.append(('p',t,links))
return blocks
def build_html(blocks, imgs):
out=[]
for b in blocks:
if b[0]=='p':
if re.match(r'^https?://\S+$', b[1]):
out.append('<p><a href="%s" target="_blank" rel="noopener">%s</a></p>'%(html.escape(b[1]),html.escape(b[1])))
continue
txt=html.escape(b[1])
# re-incrustar enlaces externos que estaban en el párrafo
for href,atxt in b[2]:
atxt_clean=html.escape(re.sub(r'<[^>]+>','',atxt).strip() or href)
# no siempre está el texto en txt; añadimos al final si no
out.append("<p>%s</p>"%txt)
elif b[0]=='link':
out.append('<p><a href="%s" target="_blank" rel="noopener">%s</a></p>'%(html.escape(b[1]),html.escape(b[2])))
# imágenes al final
for im in imgs:
out.append('<p><img src="%s%s" alt="José María Mardones" style="max-width:100%%;height:auto"/></p>'%(IMG_BASE,im))
return "\n".join(out)
manifest=[]
for fn in sorted(glob.glob("*.htm")):
key=fn[:-4]
if key not in META:
print("SIN META:",key); continue
title,author,imgs=META[key]
blocks=extract(fn)
content=build_html(blocks,imgs)
manifest.append({"file":key,"title":title,"author":author,"content":content,"nparas":len([b for b in blocks if b[0]=='p']),"nimgs":len(imgs)})
json.dump(manifest,open("manifest.json","w"),ensure_ascii=False,indent=1)
print("manifest:",len(manifest),"posts")
for m in manifest: print(f" {m['file']:34} '{m['title'][:35]}' autor={m['author']} paras={m['nparas']} imgs={m['nimgs']} len={len(m['content'])}")