<%
function layoutDiv() {
  var el = '';
  // 置顶文章样式为平铺时不渲染轮播，置顶文章改由首页文章列表靠前展示
  if (stellar_config('article.listing.pinnedLayout') !== 'flat') {
    el += partial('_partial/main/pin_slider', {type: 'post'});
  }

  const listingNav = stellar_config('profiles.blogIndex.listingNav');
  if (!listingNav.enabled) {
    return el;
  }

  el += '<div class="listing-nav">';
  el += '<div class="listing-nav__surface">';
  el += '<div class="listing-nav__viewport">';
  el += '<nav class="post">';
  if (is_home()) {
    el += '<a class="active" href="' + pretty_url(config.index_generator.path) + '">' + __("btn.recent_publish") + '</a>';
  } else {
    el += '<a href="' + pretty_url(config.index_generator.path) + '">' + __("btn.recent_publish") + '</a>';
  }

  if (site.categories && site.categories.length > 0) {
    if (page.category) {
      el += '<a class="active" href="' + pretty_url(config.category_dir) + '">' + __("btn.category") + __("symbol.colon") + escape_html(page.category) + '</a>';
    } else if (page.layout == "categories") {
      el += '<a class="active" href="' + pretty_url(config.category_dir) + '">' + __("btn.categories") + '</a>';
    } else {
      el += '<a href="' + pretty_url(config.category_dir) + '">' + __("btn.categories") + '</a>';
    }
  }

  if (site.tags && site.tags.length > 0) {
    if (page.tag) {
      el += '<a class="active" href="' + pretty_url(config.tag_dir) + '">' + __("btn.tag") + __("symbol.colon") + escape_html(page.tag) + '</a>';
    } else if (page.layout == "tags") {
      el += '<a class="active" href="' + pretty_url(config.tag_dir) + '">' + __("btn.tags") + '</a>';
    } else {
      el += '<a href="' + pretty_url(config.tag_dir) + '">' + __("btn.tags") + '</a>';
    }
  }

  var topicItems = stellar_data('topicIndex.items');
  if (Array.isArray(topicItems) && topicItems.length > 0) {
    if (page.layout == 'index_topic') {
      el += '<a class="active" href="' + pretty_url(stellar_config('profiles.topic.path')) + '">' + __("btn.topic") + '</a>';
    } else {
      el += '<a href="' + pretty_url(stellar_config('profiles.topic.path')) + '">' + __("btn.topic") + '</a>';
    }
  }

  if (site.posts && site.posts.length > 0) {
    if (is_archive()) {
      el += '<a class="active" href="' + pretty_url(config.archive_dir) + '">' + __("btn.archives") + '</a>';
    } else {
      el += '<a href="' + pretty_url(config.archive_dir) + '">' + __("btn.archives") + '</a>';
    }
  }

  if (Array.isArray(listingNav.tabs)) {
    for (const item of listingNav.tabs) {
      if (full_url_for(page.path).startsWith(full_url_for(item.url))){
        el += '<a class="active" href="' + escape_html(url_for(item.url)) + '">' + escape_html(item.title) + '</a>';
      } else {
        el += '<a href="' + escape_html(url_for(item.url)) + '">' + escape_html(item.title) + '</a>';
      }
    }
  }

  el += '</nav>';
  el += '</div>';
  el += '</div>';
  el += '</div>';
  return el;
}
%>

<%- layoutDiv() %>
