<%
function layoutDiv() {
  var action = ''
  if (item.rss) {
    action += '<a class="cap-action" id="rss" title="Subscribe" href="' + escape_html(item.rss) + '">'
    action += icon('default:rss')
    action += '</a>'
  }
  var arr = []
  if (page.menu_id == 'wiki') {
    arr = theme.wiki.all_pages.filter(function(p) {
      if (p.wiki) {
        var proj = theme.wiki.tree[p.wiki]
        return proj?.index != false
      }
      return false
    })
    arr = arr.sort(function(p1, p2) {
      return p1.updated > p2.updated ? -1 : 1
    })
  } else if (page.layout === 'notebooks') {
    arr = site.pages.filter(function(p) {
      return p.notebook
    }).sort('-updated')
  } else if (page.notebook) {
    arr = site.pages.filter(function(p) {
      return p.notebook === page.notebook
    }).sort('-updated')
  } 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 = ''
    if (post.wiki) {
      var proj = theme.wiki.tree[post.wiki]
      prefix = proj?.name || post.wiki || ''
    } else if (page.layout === 'notebooks') {
      var notebook = theme.notebooks.tree[post.notebook]
      prefix = notebook?.name || post.notebook || ''
    }
    entries.push({
      href: pretty_url(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() %>
