Corrigiendo texto del Hero segun lo que pasaron
This commit is contained in:
+38
-4
@@ -792,20 +792,54 @@ function renderMockArticles(articles, container) {
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function extractFirstImage(post) {
|
||||
// 1. Intentar obtener la imagen destacada oficial gracias al ?_embed
|
||||
if (post._embedded && post._embedded['wp:featuredmedia'] && post._embedded['wp:featuredmedia'][0]) {
|
||||
const featuredMedia = post._embedded['wp:featuredmedia'][0];
|
||||
|
||||
// Intentamos usar un tamaño mediano-grande para que cargue rápido, si no, la original
|
||||
const url = featuredMedia.media_details?.sizes?.medium_large?.source_url || featuredMedia.source_url;
|
||||
if (url) return url;
|
||||
}
|
||||
|
||||
// 2. Respaldo: Si el artículo no tiene imagen destacada, busca la primera <img> dentro del texto
|
||||
const contentHtml = post.content?.rendered || '';
|
||||
const match = contentHtml.match(/<img[^>]+src=["']([^"']+)["']/i);
|
||||
if (match && match[1]) {
|
||||
let url = match[1];
|
||||
if (url.startsWith('/')) {
|
||||
url = 'https://blog.ideconsultores.com.ar' + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
function renderWpPosts(posts, container) {
|
||||
container.innerHTML = posts.map(post => {
|
||||
const title = post.title?.rendered || 'Artículo';
|
||||
const excerpt = post.excerpt?.rendered?.replace(/<[^>]*>?/gm, '').substring(0, 140) + '...' || '';
|
||||
const link = post.link || 'https://blog.ideconsultores.com.ar';
|
||||
const date = new Date(post.date).toLocaleDateString('es-AR', { day: 'numeric', month: 'long', year: 'numeric' });
|
||||
const imageUrl = extractFirstImage(post);
|
||||
|
||||
const imageHtml = imageUrl
|
||||
? `<div style="aspect-ratio: 16/9; margin-bottom: 1.25rem; overflow: hidden; border-radius: 8px; background: #f3f4f6;">
|
||||
<img src="${imageUrl}" alt="${title}" loading="lazy"
|
||||
style="width: 100%; height: 100%; object-fit: cover; display: block;"
|
||||
onerror="this.style.display='none'; this.parentElement.innerHTML='<div class=\\'img-placeholder-icon\\' style=\\'text-align:center;padding-top:2.5rem;font-size:2rem;\\'>📰</div><div class=\\'img-placeholder-label\\' style=\\'text-align:center;\\'>Imagen no disponible</div>';">
|
||||
</div>`
|
||||
: `<div class="img-placeholder" style="aspect-ratio: 16/9; margin-bottom: 1.25rem; padding: 1.5rem;">
|
||||
<div class="img-placeholder-icon">📰</div>
|
||||
<div class="img-placeholder-label">Sin imagen destacada</div>
|
||||
</div>`;
|
||||
|
||||
return `
|
||||
<article class="card" style="display: flex; flex-direction: column; justify-content: space-between;">
|
||||
<div>
|
||||
<div class="img-placeholder" style="aspect-ratio: 16/9; margin-bottom: 1.25rem; padding: 1.5rem;">
|
||||
<div class="img-placeholder-icon">📰</div>
|
||||
<div class="img-placeholder-label">Imagen Destacada WP</div>
|
||||
</div>
|
||||
${imageHtml}
|
||||
<div style="font-size: 0.8rem; font-weight: 700; color: var(--ide-accent); margin-bottom: 0.4rem;">
|
||||
${date}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user