$ is_link = ocaid and chapter.pagenum and chapter.pagenum.isdigit()
$ tag = 'a' if is_link else 'div'
<$tag
class="toc__main"
$:cond(is_link, 'href="//archive.org/details/%s/page/%s"' % (ocaid, chapter.pagenum))
$:cond(is_link, 'data-ol-link-track="BookPage|TOCClick"')
>
$ label = chapter.label
$if label and not label.endswith('.'):
$ label = label.strip() + '. '
$label $chapter.title
$if chapter.subtitle:
$chapter.subtitle
$if chapter.authors:
$:macros.BookByline(chapter.authors)
$if chapter.pagenum:
$_('Page %s', chapter.pagenum)
$tag>
$if chapter.description:
$chapter.description