<%
function layoutDiv() {
  var action = ''
  if (item.rss) {
    action += '<a class="' + ui_classes('cap-action') + '" id="rss" title="Subscribe" href="' + escape_html(item.rss) + '">'
    action += '<span class="ui-icon">' + icon('default:rss') + '</span>'
    action += '</a>'
  }
  var arr = []
  var notebookViewModel = typeof viewModel !== 'undefined' && viewModel?.collection?.profile === 'notebook'
    ? viewModel
    : null
  var notebookItems = notebookViewModel
    ? notebookViewModel.render.layout.recentItems
    : page.notebookIndex?.mode === 'collections'
      ? page.notebookIndex.recentItems
      : page.notebookIndex?.mode === 'notes'
        ? page.notebookIndex.collection.recentItems
        : null
  if (notebookItems) {
    arr = notebookItems.slice()
  } else if (content_config(page).activeMenu == 'wiki') {
    arr = stellar_data('wiki').all_pages.filter(function(p) {
      if (p.collectionId) {
        var proj = stellar_data('wiki').tree[p.collectionId]
        return proj?.index != false
      }
      return false
    })
    arr = arr.sort(function(p1, p2) {
      return p1.updated > p2.updated ? -1 : 1
    })
  } else {
    arr = site.posts.filter(function(p) {
      return p.title && p.title.length > 0
    }).sort('updated', -1)
  }
  arr = arr.filter(function(p) {
    return p.title?.length > 0
  })
  arr.length = item.limit
  var entries = []
  arr.forEach(function(post) {
    if (!post) {
      return
    }
    var prefix = ''
    var wikiId = notebookItems ? null : collection_id(post, 'wiki') || post.collectionId
    if (wikiId) {
      var proj = stellar_data('wiki').tree[wikiId]
      prefix = proj?.name || wikiId
    } else if (notebookItems && page.notebookIndex?.mode === 'collections') {
      prefix = post.collectionName || post.collectionId || ''
    }
    entries.push({
      href: pretty_url(notebookItems ? post.href : post.link || post.path),
      title: post.title,
      prefix: prefix,
      indicator: false
    })
  })
  var body = partial('_partial/components/collection', {options: {
    layout: 'list',
    variant: 'nav',
    density: 'compact',
    items: entries
  }})
  return partial('_partial/components/widget-frame', {
    className: 'recent-widget',
    title: __('meta.recent_update'),
    action: action,
    body: body
  })
}
%>
<%- layoutDiv() %>
