<%
var obj = {
  image: post.cover
};
function div_default() {
  var el = '';
  el += '<article class="md-text">';

  // 封面：仅当显式 cover 为完整 URL 时渲染（Unsplash 自动封面接口已失效，不再生成）
  if (obj.image && obj.image.includes('/')) {
    el += '<div class="post-cover">';
    el += '<img src="' + escape_html(obj.image) + '"/>';
    el += '</div>';
  }

  // 标题
  el += '<h2 class="post-title">';
  el += post.title ? escape_html(post.title) : date(post.date, config.date_format);
  el += '</h2>';

  // 摘要
  el += '<div class="excerpt';
  if (theme.plugins.heti?.enable) {
    el += ' heti';
  }
  el += '">';
  el += '<p>';
  if (post.excerpt) {
    el += escape_html(strip_html(post.excerpt));
  } else if (post.description) {
    el += escape_html(post.description);
  } else if (post.content && theme.article.auto_excerpt > 0) {
    el += escape_html(truncate(strip_html(post.content), {length: theme.article.auto_excerpt}));
  }
  el += '</p>';
  el += '</div>';

  // meta
  el += '<div class="meta cap">';
  el += '<span class="cap" id="post-meta">';
  el += icon('default:calendar')
  // time
  el += `<time datetime="${date_xml(post.date)}">${date(post.date, config.date_format)}</time>`
  el += '</span>';
  // cat
  if (post.categories && post.categories.length > 0) {
    if (post.layout === 'post' && post.categories && post.categories.length > 0) {
      var cats = [];
      if (post.categories) {
        post.categories.forEach((cat, i) => {
          cats.push(cat.name);
        });
      }
      if (cats.length > 0) {
        let str = cats.join(' / ');
        let lastCat = cats.pop();
        el += '<span class="cap breadcrumb"' + category_color(lastCat) + '>';
        el += icon('default:category')
        el += `<span>${escape_html(str)}</span>`
        el += '</span>';
      }
    }
  }
  // 置顶文章由轮播（默认）或首页列表靠前展示（flat 平铺）承担，卡片内不显示 pin 图标。
  // 文章标签（最多 5 个，#580）
  if (theme.article.card_tags && post.tags && post.tags.length > 0) {
    el += '<span class="card-tags">';
    post.tags.forEach((tag, i) => {
      if (i >= 5) {
        return;
      }
      el += `<span class="cap tag-chip">${icon('default:hashtag')}${escape_html(tag.name)}</span>`;
    });
    el += '</span>';
  }
  el += '</div>';
  el += '</article>';
  return el;
}
function div_photo() {
  var el = '';
  // 小字取值统一由 subtitle() helper 提供：subtitle > description > excerpt 前 50 字
  var caption = subtitle(post);
  // hero 卡片文字区固定 bottom：标题 + 一行小字，不再有 top 布局
  el += '<div class="cover" position="bottom" style="--cover-url:url(\'' + escape_html(obj.image.replace(/'/g, '%27')) + '\')">';
  el += '<img src="' + escape_html(obj.image) + '"/>';
  el += '<div class="cover-info" position="bottom" data-text-adaptive="split">';
  el += '<div class="text headline">' + escape_html(post.title ? post.title : date(post.date, config.date_format)) + '</div>';
  if (caption.length > 0) {
    el += '<div class="text caption">' + escape_html(caption) + '</div>';
  }
  el += '</div>';
  el += '</div>';
  return el;
}
function div() {
  if (theme.article.card_style == 'hero' && obj.image && obj.image.length > 0) {
    return div_photo();
  }
  return div_default();
}
%>
<%- div() %>
